Jump to content

Get id_product_attribute from hookActionUpdateQuantity $params


hakeryk2

Recommended Posts

Hello community, 

 

I am developing a small module and I don't know how to get id_product_attribute values from actionUpdateQuantity hook in module. 

 

I already registered a hook, I used this to look for what params contains

public function hookActionUpdateQuantity($params)
    {
        ddd($params);
    }

and I get this one (a short version), the first id_product_attribute is 0 which is not correct and the correct one is in cart object.

Array
(
    [id_product] => 8
    [id_product_attribute] => 0
    [quantity] => 9
    [cookie] => Cookie Object
        (
            [_content:protected] => Array
                (
                    [date_add] => 2017-01-17 13:05:25
                    [id_lang] => 1
                    [id_currency] => 1
                    [viewed] => 1,8
                    [last_visited_category] => 2
                    [id_guest] => 2
                    [id_connections] => 6
                    [id_customer] => 2
                    [customer_lastname] => as
                    [customer_firstname] => Eryk
                    [passwd] => aad50fdc8c879e217339c9849b56c554
                    [logged] => 1
                    [email] => [email protected]
                    [is_guest] => 
                    [check_cgv] => 1
                    [id_cart] => 38
                    [checksum] => 590965302
                )

            [_name:protected] => PrestaShop-fb5891367b64508a464a2fc66489e306
            [_expire:protected] => 1486460114
            [_domain:protected] => 
            [_path:protected] => /prestashop2/
            [_cipherTool:protected] => Rijndael Object
                (
                    [_key:protected] => csffUkNsZaw3SohpmBKqnGm8dsnGck8R
                    [_iv:protected] => گc!$/5
                )

            [_modified:protected] => 
            [_allow_writing:protected] => 1
            [_salt:protected] => z6KHVx6c
            [_standalone:protected] => 
            [_secure:protected] => 
        )

    [cart] => Cart Object
        (
            [id] => 38
            [id_shop_group] => 1
            [id_shop] => 1
            [id_address_delivery] => 5
            [id_address_invoice] => 5
            [id_currency] => 1
            [id_customer] => 2
            [id_guest] => 2
            [id_lang] => 1
            [recyclable] => 0
            [gift] => 0
            [gift_message] => 
            [mobile_theme] => 0
            [date_add] => 2017-01-18 10:34:49
            [secure_key] => 5f03791d31f98d419dbb0d275b303410
            [id_carrier] => 1
            [date_upd] => 2017-01-18 10:35:10
            [checkedTos] => 
            [pictures] => 
            [textFields] => 
            [delivery_option] => a:1:{i:5;s:2:"1,";}
            [allow_seperated_package] => 0
            [_products:protected] => Array
                (
                    [0] => Array
                        (
                            [id_product_attribute] => 46
                            [id_product] => 8
                            [cart_quantity] => 1
                            [id_shop] => 1
                            [name] => testowy
                            [is_virtual] => 0
                            [description_short] => <p>asda</p>
                            [available_now] => 
                            [available_later] => 
                            [id_category_default] => 2
                            [id_supplier] => 0
                            [id_manufacturer] => 0
                            [on_sale] => 0
                            [ecotax] => 0.000000
                            [additional_shipping_cost] => 0.00
                            [available_for_order] => 1
                            [price] => 100
                            [active] => 1
                            [unity] => 
                            [unit_price_ratio] => 0.000000
                            [quantity_available] => 10
                            [width] => 0.000000
                            [height] => 0.000000
                            [depth] => 0.000000
                            [out_of_stock] => 2
                            [weight] => 0
                            [date_add] => 2017-01-17 13:09:40
                            [date_upd] => 2017-01-17 13:20:53
                            [quantity] => 1
                            [link_rewrite] => testowy
                            [category] => glowna
                            [unique_id] => 000000000800000000465
                            [id_address_delivery] => 5
                            [advanced_stock_management] => 0
                            [supplier_reference] => 
                            [customization_quantity] => 
                            [id_customization] => 
                            [price_attribute] => 0.000000
                            [ecotax_attr] => 0.000000
                            [reference] => 
                            [weight_attribute] => 0.000000
                            [ean13] => 
                            [upc] => 
                            [minimal_quantity] => 1
                            [wholesale_price] => 0.000000
                            [id_image] => pl-default
                            [legend] => 
                            [reduction_type] => 0
                            [stock_quantity] => 10
                            [price_without_reduction] => 123
                            [price_with_reduction] => 123
                            [price_with_reduction_without_tax] => 100
                            [total] => 100
                            [total_wt] => 123
                            [price_wt] => 123
                            [reduction_applies] => 
                            [quantity_discount_applies] => 
                            [allow_oosp] => 1
                            [features] => Array
                                (
                                )

                            [attributes] => Size : 35
                            [attributes_small] => 35
                            [rate] => 23
                            [tax_name] => PTU PL 23%
                        )

                )

In cart object and in _products array there is this value that I want to retrieve but I am a little bit rookie and I dont know how should I get it into variable that I could use it later. And maybe how to use it to retrieve id_product_attribute if there will be more products in the cart.

 

I just want to use this value in function (probably in foreach when multiple values)

 

Any help will be appreciated. 

----------------------------------------------------------------

 

EDIT: Found it

$productAttributeIds = array();
        $cart = $params['cart'];
        $products = $cart->getProducts();

        foreach ($products as $ids) {
            $productAttributeIds[] =  $ids['id_product_attribute'];
        }
Edited by hakeryk2 (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...