Jump to content

Edit History

andtrx

andtrx

19 hours ago, stifler97 said:

if by hook is not working you mean that function does not fire after the event of actionObjectProductAddAfter, then the problem is that this event has not taken place at all.

Check the ObjectModel class and search for Hook::exec

You will see which hooks are there and when they get fired.

AddAfter and UpdateAfter are different.

The last thing is that, you mentioned you want to run some code or process some thing or any thing of that sort, JUST AFTER a combination is added. Read this again, a combination, so that will obviously not fire the ProductAddAfter at all.

You need to find out the object models that are involved in the action of adding a product combination. Then put your code in that hook method. Thats it. Good luck

@stifler97 1 last question,

I fixed the code, and I am hooking into hookActionObjectCombinationAddAfter, 

Where I execute this code:

    public function hookActionObjectCombinationAddAfter($params) {

        $language = Tools::getValue('language', 'ro');
        $language = Language::getIdByIso( $language );

        $product = new Product( $params['object']->id_product, false, $language);
        $combinations = $product->getAttributeCombinations(2);

        $newArr = [];

        foreach($combinations as $combination) {
            $attributeValues = $product->getAttributeCombinationsById($combination['id_product_attribute'], 2);
            $newArr[$combination['id_product_attribute']][] = $attributeValues;
        }

        echo "<pre>";
        print_r($newArr);
        echo "</pre>";
        die("exit");

    }


I expected the newsest combination added (the one with an ID of [2846]) to return the same values as the combination with the id of [5], but for some reason [attribute_name] is empty.
Is there another hook that gets executed after the hook I am using,  and therfore the attribute_name is created after? I also tried hookActionObjectAttributeGroupAddAfter but it does not trigger.
 

    [5] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [id_product_attribute] => 5
                            [id_product] => 1219
                            [reference] => ART002279SED
                            [supplier_reference] => 
                            [location] => 
                            [ean13] => 
                            [upc] => 
                            [wholesale_price] => 0.000000
                            [price] => 0.000000
                            [price_euro] => 0.000000
                            [ecotax] => 0.000000
                            [quantity] => 99998
                            [weight] => 0.000000
                            [unit_price_impact] => 0.00
                            [default_on] => 1
                            [minimal_quantity] => 1
                            [available_date] => 0000-00-00
                            [sedona_custom_status] => 0
                            [sedona_stock_ro] => In stoc la depozit
                            [sedona_stock_en] => Warehouse stock
                            [sedona_delivery_ro] => Maximum 48 de ore
                            [sedona_delivery_en] => Maximum 48 hours
                            [id_shop] => 1
                            [id_attribute_group] => 2
                            [is_color_group] => 0
                            [group_name] => Brat flexibil
                            [attribute_name] => Elbow Arm
                            [id_attribute] => 5
                        )

                )

        )

    [2846] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [id_product_attribute] => 2846
                            [id_product] => 1219
                            [reference] => 1231
                            [supplier_reference] => 
                            [location] => 
                            [ean13] => 
                            [upc] => 
                            [wholesale_price] => 0.000000
                            [price] => 0.000000
                            [price_euro] => 0.000000
                            [ecotax] => 0.000000
                            [quantity] => 0
                            [weight] => 0.000000
                            [unit_price_impact] => 0.00
                            [default_on] => 0
                            [minimal_quantity] => 1
                            [available_date] => 0000-00-00
                            [sedona_custom_status] => 0
                            [sedona_stock_ro] => 
                            [sedona_stock_en] => 
                            [sedona_delivery_ro] => 
                            [sedona_delivery_en] => 
                            [id_shop] => 1
                            [id_attribute_group] => 
                            [is_color_group] => 
                            [group_name] => 
                            [attribute_name] => 
                            [id_attribute] => 
                        )

                )

        )

 

andtrx

andtrx

19 hours ago, stifler97 said:

if by hook is not working you mean that function does not fire after the event of actionObjectProductAddAfter, then the problem is that this event has not taken place at all.

Check the ObjectModel class and search for Hook::exec

You will see which hooks are there and when they get fired.

AddAfter and UpdateAfter are different.

The last thing is that, you mentioned you want to run some code or process some thing or any thing of that sort, JUST AFTER a combination is added. Read this again, a combination, so that will obviously not fire the ProductAddAfter at all.

You need to find out the object models that are involved in the action of adding a product combination. Then put your code in that hook method. Thats it. Good luck

@stifler97 1 last question,

I fixed the code, and I am hooking into hookActionObjectCombinationAddAfter, 

Where I execute this code:

    public function hookActionObjectCombinationAddAfter($params) {

        $language = Tools::getValue('language', 'ro');
        $language = Language::getIdByIso( $language );

        $product = new Product( $params['object']->id_product, false, $language);
        $combinations = $product->getAttributeCombinations(2);

        $newArr = [];

        foreach($combinations as $combination) {
            $attributeValues = $product->getAttributeCombinationsById($combination['id_product_attribute'], 2);
            $newArr[$combination['id_product_attribute']][] = $attributeValues;
        }

        echo "<pre>";
        print_r($newArr);
        echo "</pre>";
        die("exit");

    }


I expected the combination with an ID of [2846] to return the same values as the combination with the id of [5], but for some reason [attribute_name] is empty.
Is there another hook that gets executed after the hook I am using,  and therfore the attribute_name is created after? I also tried hookActionObjectAttributeGroupAddAfter but it does not trigger.
 

    [5] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [id_product_attribute] => 5
                            [id_product] => 1219
                            [reference] => ART002279SED
                            [supplier_reference] => 
                            [location] => 
                            [ean13] => 
                            [upc] => 
                            [wholesale_price] => 0.000000
                            [price] => 0.000000
                            [price_euro] => 0.000000
                            [ecotax] => 0.000000
                            [quantity] => 99998
                            [weight] => 0.000000
                            [unit_price_impact] => 0.00
                            [default_on] => 1
                            [minimal_quantity] => 1
                            [available_date] => 0000-00-00
                            [sedona_custom_status] => 0
                            [sedona_stock_ro] => In stoc la depozit
                            [sedona_stock_en] => Warehouse stock
                            [sedona_delivery_ro] => Maximum 48 de ore
                            [sedona_delivery_en] => Maximum 48 hours
                            [id_shop] => 1
                            [id_attribute_group] => 2
                            [is_color_group] => 0
                            [group_name] => Brat flexibil
                            [attribute_name] => Elbow Arm
                            [id_attribute] => 5
                        )

                )

        )

    [2846] => Array
        (
            [0] => Array
                (
                    [0] => Array
                        (
                            [id_product_attribute] => 2846
                            [id_product] => 1219
                            [reference] => 1231
                            [supplier_reference] => 
                            [location] => 
                            [ean13] => 
                            [upc] => 
                            [wholesale_price] => 0.000000
                            [price] => 0.000000
                            [price_euro] => 0.000000
                            [ecotax] => 0.000000
                            [quantity] => 0
                            [weight] => 0.000000
                            [unit_price_impact] => 0.00
                            [default_on] => 0
                            [minimal_quantity] => 1
                            [available_date] => 0000-00-00
                            [sedona_custom_status] => 0
                            [sedona_stock_ro] => 
                            [sedona_stock_en] => 
                            [sedona_delivery_ro] => 
                            [sedona_delivery_en] => 
                            [id_shop] => 1
                            [id_attribute_group] => 
                            [is_color_group] => 
                            [group_name] => 
                            [attribute_name] => 
                            [id_attribute] => 
                        )

                )

        )

 

×
×
  • Create New...