Jump to content

How To Get Id From $Params


wydydygibus

Recommended Posts

The hook is executed inside of the AdminProductsController.  As you can see from the code, the hook sends 2 parameters, the product ID and the product Object

Hook::exec('actionProductAdd', array('id_product' => (int)$this->object->id, 'product' => $this->object));

You can access either of them using

$id_product = $params['id_product'];
$product = $params['product'];

make sure your hook function defines the params parameter

public function hookActionProductAdd($params)

you can also dump the $params using print_r to see what is defined

print_r($params);
Link to comment
Share on other sites


Array ( [product] => Product Object ( [tax_name] => [tax_rate] => [id_manufacturer] => 1 [id_supplier] => 1 [id_category_default] => 3 [id_shop_default] => 1 [manufacturer_name] => [supplier_name] => [name] => Array ( [1] => iPod Nanod [2] => iPod Nano ) [description] => Array ( [1] =>

Curved ahead of the curve.

 

For those about to rock, we give you nine amazing colors. But that's only part of the story. Feel the curved, all-aluminum and glass design and you won't want to put iPod nano down.

 

Great looks. And brains, too.

 

The new Genius feature turns iPod nano into your own highly intelligent, personal DJ. It creates playlists by finding songs in your library that go great together.

 

Made to move with your moves.

 

The accelerometer comes to iPod nano. Give it a shake to shuffle your music. Turn it sideways to view Cover Flow. And play games designed with your moves in mind.

 

[2] =>

Curved ahead of the curve.

 

For those about to rock, we give you nine amazing colors. But that's only part of the story. Feel the curved, all-aluminum and glass design and you won't want to put iPod nano down.

 

Great looks. And brains, too.

 

The new Genius feature turns iPod nano into your own highly intelligent, personal DJ. It creates playlists by finding songs in your library that go great together.

 

Made to move with your moves.

 

The accelerometer comes to iPod nano. Give it a shake to shuffle your music. Turn it sideways to view Cover Flow. And play games designed with your moves in mind.

 

) [description_short] => Array ( [1] =>

New design. New features. Now in 8GB and 16GB. iPod nano rocks like never before.

 

[2] =>

New design. New features. Now in 8GB and 16GB. iPod nano rocks like never before.

 

) [quantity] => 160 [minimal_quantity] => 1 [available_now] => Array ( [1] => Dostępny [2] => In stock ) [available_later] => Array ( [1] => [2] => ) [price] => 124.581940 [additional_shipping_cost] => 0.00 [wholesale_price] => 70.00 [on_sale] => 0 [online_only] => 0 [unity] => [unit_price] => 0.00 [unit_price_ratio] => 0.000000 [ecotax] => 0 [reference] => demo_1d [supplier_reference] => [location] => [width] => 0.000000 [height] => 0.000000 [depth] => 0.000000 [weight] => 0.500000 [ean13] => 0 [upc] => [link_rewrite] => Array ( [1] => ipod-nano [2] => ipod-nano ) [meta_description] => Array ( [1] => [2] => ) [meta_keywords] => Array ( [1] => [2] => ) [meta_title] => Array ( [1] => [2] => ) [quantity_discount] => 0 [customizable] => 0 [new] => [uploadable_files] => 0 [text_fields] => 0 [active] => 1 [redirect_type] => 404 [id_product_redirected] => 0 [available_for_order] => 1 [available_date] => 0000-00-00 [condition] => new [show_price] => 1 [indexed] => 0 [visibility] => both [date_add] => 2016-01-11 12:12:36 [date_upd] => 2016-01-14 10:18:25 [tags] => [id_tax_rules_group] => 1 [id_color_default] => 0 [advanced_stock_management] => 0 [out_of_stock] => 2 [depends_on_stock] => [isFullyLoaded] => [cache_is_pack] => 0 [cache_has_attachments] => 0 [is_virtual] => 0 [cache_default_attribute] => 0 [category] => [webserviceParameters:protected] => Array ( [objectMethods] => Array ( [add] => addWs [update] => updateWs ) [objectNodeNames] => products [fields] => Array ( [id_manufacturer] => Array ( [xlink_resource] => manufacturers ) [id_supplier] => Array ( [xlink_resource] => suppliers ) [id_category_default] => Array ( [xlink_resource] => categories ) [new] => Array ( ) [cache_default_attribute] => Array ( ) [id_default_image] => Array ( [getter] => getCoverWs [setter] => setCoverWs [xlink_resource] => Array ( [resourceName] => images [subResourceName] => products ) ) [id_default_combination] => Array ( [getter] => getWsDefaultCombination [setter] => setWsDefaultCombination [xlink_resource] => Array ( [resourceName] => combinations ) ) [id_tax_rules_group] => Array ( [xlink_resource] => Array ( [resourceName] => tax_rule_groups ) ) [position_in_category] => Array ( [getter] => getWsPositionInCategory [setter] => ) [manufacturer_name] => Array ( [getter] => getWsManufacturerName [setter] => ) [quantity] => Array ( [getter] => [setter] => ) [type] => Array ( [getter] => getWsType [setter] => setWsType ) ) [associations] => Array ( [categories] => Array ( [resource] => category [fields] => Array ( [id] => Array ( [required] => 1 ) ) ) [images] => Array ( [resource] => image [fields] => Array ( [id] => Array ( ) ) ) [combinations] => Array ( [resource] => combinations [fields] => Array ( [id] => Array ( [required] => 1 ) ) ) [product_option_values] => Array ( [resource] => product_options_values [fields] => Array ( [id] => Array ( [required] => 1 ) ) ) [product_features] => Array ( [resource] => product_feature [fields] => Array ( [id] => Array ( [required] => 1 ) [custom] => Array ( [required] => ) [id_feature_value] => Array ( [required] => 1 [xlink_resource] => product_feature_values ) ) ) [tags] => Array ( [resource] => tag [fields] => Array ( [id] => Array ( [required] => 1 ) ) ) [stock_availables] => Array ( [resource] => stock_available [fields] => Array ( [id] => Array ( [required] => 1 ) [id_product_attribute] => Array ( [required] => 1 ) ) [setter] => ) [accessories] => Array ( [resource] => product [fields] => Array ( [id] => Array ( [required] => 1 [xlink_resource] => product ) ) ) [product_bundle] => Array ( [resource] => products [fields] => Array ( [id] => Array ( [required] => 1 ) [quantity] => Array ( ) ) ) ) ) [id] => 1 [id_lang:protected] => [id_shop:protected] => 1 [id_shop_list] => [get_shop_from_context:protected] => 1 [table:protected] => product [identifier:protected] => id_product [fieldsRequired:protected] => Array ( [0] => price ) [fieldsSize:protected] => Array ( [reference] => 32 [supplier_reference] => 32 [location] => 64 [ean13] => 13 [upc] => 12 ) [fieldsValidate:protected] => Array ( [id_shop_default] => isUnsignedId [id_manufacturer] => isUnsignedId [id_supplier] => isUnsignedId [reference] => isReference [supplier_reference] => isReference [location] => isReference [width] => isUnsignedFloat [height] => isUnsignedFloat [depth] => isUnsignedFloat [weight] => isUnsignedFloat [quantity_discount] => isBool [ean13] => isEan13 [upc] => isUpc [cache_is_pack] => isBool [cache_has_attachments] => isBool [is_virtual] => isBool [id_category_default] => isUnsignedId [id_tax_rules_group] => isUnsignedId [on_sale] => isBool [online_only] => isBool [ecotax] => isPrice [minimal_quantity] => isUnsignedInt [price] => isPrice [wholesale_price] => isPrice [unity] => isString [additional_shipping_cost] => isPrice [customizable] => isUnsignedInt [text_fields] => isUnsignedInt [uploadable_files] => isUnsignedInt [active] => isBool [redirect_type] => isString [id_product_redirected] => isUnsignedId [available_for_order] => isBool [available_date] => isDateFormat [condition] => isGenericName [show_price] => isBool [indexed] => isBool [visibility] => isProductVisibility [advanced_stock_management] => isBool [date_add] => isDateFormat [date_upd] => isDateFormat ) [fieldsRequiredLang:protected] => Array ( [0] => link_rewrite [1] => name ) [fieldsSizeLang:protected] => Array ( [meta_description] => 255 [meta_keywords] => 255 [meta_title] => 128 [link_rewrite] => 128 [name] => 128 [available_now] => 255 [available_later] => 255 ) [fieldsValidateLang:protected] => Array ( [meta_description] => isGenericName [meta_keywords] => isGenericName [meta_title] => isGenericName [link_rewrite] => isLinkRewrite [name] => isCatalogName [description] => isCleanHtml [description_short] => isCleanHtml [available_now] => isGenericName [available_later] => IsGenericName ) [tables:protected] => Array ( ) [image_dir:protected] => [image_format:protected] => jpg [def:protected] => Array ( [table] => product [primary] => id_product [multilang] => 1 [multilang_shop] => 1 [fields] => Array ( [id_shop_default] => Array ( [type] => 1 [validate] => isUnsignedId ) [id_manufacturer] => Array ( [type] => 1 [validate] => isUnsignedId ) [id_supplier] => Array ( [type] => 1 [validate] => isUnsignedId ) [reference] => Array ( [type] => 3 [validate] => isReference => 32 ) [supplier_reference] => Array ( [type] => 3 [validate] => isReference => 32 ) [location] => Array ( [type] => 3 [validate] => isReference => 64 ) [width] => Array ( [type] => 4 [validate] => isUnsignedFloat ) [height] => Array ( [type] => 4 [validate] => isUnsignedFloat ) [depth] => Array ( [type] => 4 [validate] => isUnsignedFloat ) [weight] => Array ( [type] => 4 [validate] => isUnsignedFloat ) [quantity_discount] => Array ( [type] => 2 [validate] => isBool ) [ean13] => Array ( [type] => 3 [validate] => isEan13 => 13 ) [upc] => Array ( [type] => 3 [validate] => isUpc => 12 ) [cache_is_pack] => Array ( [type] => 2 [validate] => isBool ) [cache_has_attachments] => Array ( [type] => 2 [validate] => isBool ) [is_virtual] => Array ( [type] => 2 [validate] => isBool ) [id_category_default] => Array ( [type] => 1 [shop] => 1 [validate] => isUnsignedId ) [id_tax_rules_group] => Array ( [type] => 1 [shop] => 1 [validate] => isUnsignedId ) [on_sale] => Array ( [type] => 2 [shop] => 1 [validate] => isBool ) [online_only] => Array ( [type] => 2 [shop] => 1 [validate] => isBool ) [ecotax] => Array ( [type] => 4 [shop] => 1 [validate] => isPrice ) [minimal_quantity] => Array ( [type] => 1 [shop] => 1 [validate] => isUnsignedInt ) [price] => Array ( [type] => 4 [shop] => 1 [validate] => isPrice [required] => 1 ) [wholesale_price] => Array ( [type] => 4 [shop] => 1 [validate] => isPrice ) [unity] => Array ( [type] => 3 [shop] => 1 [validate] => isString ) [unit_price_ratio] => Array ( [type] => 4 [shop] => 1 ) [additional_shipping_cost] => Array ( [type] => 4 [shop] => 1 [validate] => isPrice ) [customizable] => Array ( [type] => 1 [shop] => 1 [validate] => isUnsignedInt ) [text_fields] => Array ( [type] => 1 [shop] => 1 [validate] => isUnsignedInt ) [uploadable_files] => Array ( [type] => 1 [shop] => 1 [validate] => isUnsignedInt ) [active] => Array ( [type] => 2 [shop] => 1 [validate] => isBool ) [redirect_type] => Array ( [type] => 3 [shop] => 1 [validate] => isString ) [id_product_redirected] => Array ( [type] => 1 [shop] => 1 [validate] => isUnsignedId ) [available_for_order] => Array ( [type] => 2 [shop] => 1 [validate] => isBool ) [available_date] => Array ( [type] => 5 [shop] => 1 [validate] => isDateFormat ) [condition] => Array ( [type] => 3 [shop] => 1 [validate] => isGenericName [values] => Array ( [0] => new [1] => used [2] => refurbished ) [default] => new ) [show_price] => Array ( [type] => 2 [shop] => 1 [validate] => isBool ) [indexed] => Array ( [type] => 2 [shop] => 1 [validate] => isBool ) [visibility] => Array ( [type] => 3 [shop] => 1 [validate] => isProductVisibility [values] => Array ( [0] => both [1] => catalog [2] => search [3] => none ) [default] => both ) [cache_default_attribute] => Array ( [type] => 1 [shop] => 1 ) [advanced_stock_management] => Array ( [type] => 2 [shop] => 1 [validate] => isBool ) [date_add] => Array ( [type] => 5 [shop] => 1 [validate] => isDateFormat ) [date_upd] => Array ( [type] => 5 [shop] => 1 [validate] => isDateFormat ) [meta_description] => Array ( [type] => 3 [lang] => 1 [validate] => isGenericName => 255 ) [meta_keywords] => Array ( [type] => 3 [lang] => 1 [validate] => isGenericName => 255 ) [meta_title] => Array ( [type] => 3 [lang] => 1 [validate] => isGenericName => 128 ) [link_rewrite] => Array ( [type] => 3 [lang] => 1 [validate] => isLinkRewrite [required] => 1 => 128 ) [name] => Array ( [type] => 3 [lang] => 1 [validate] => isCatalogName [required] => 1 => 128 ) [description] => Array ( [type] => 6 [lang] => 1 [validate] => isCleanHtml ) [description_short] => Array ( [type] => 6 [lang] => 1 [validate] => isCleanHtml => 800 ) [available_now] => Array ( [type] => 3 [lang] => 1 [validate] => isGenericName => 255 ) [available_later] => Array ( [type] => 3 [lang] => 1 [validate] => IsGenericName => 255 ) ) [associations] => Array ( [manufacturer] => Array ( [type] => 1 ) [supplier] => Array ( [type] => 1 ) [default_category] => Array ( [type] => 1 [field] => id_category_default [object] => Category ) [tax_rules_group] => Array ( [type] => 1 ) [categories] => Array ( [type] => 2 [field] => id_category [object] => Category [association] => category_product ) [stock_availables] => Array ( [type] => 2 [field] => id_stock_available [object] => StockAvailable [association] => stock_availables ) [l] => Array ( [type] => 2 [field] => id_product [foreign_field] => id_product ) ) [classname] => Product ) [update_fields:protected] => ) [cookie] => Cookie Object ( [_content:protected] => Array ( [date_add] => 2016-01-11 12:13:32 [id_lang] => 1 [detect_language] => 1 [id_employee] => 1 => [email protected] [profile] => 1 [passwd] => 3eff2bb9a9750c27965bc2e7b02b1587 [remote_addr] => [shopContext] => s-1 [id_currency] => 1 [product_pagination] => 50 [cart_rule_pagination] => 50 [submitFiltercart_rule] => 0 [cartrulescart_ruleFilter_id_cart_rule] => [cartrulescart_ruleFilter_name] => [cartrulescart_ruleFilter_priority] => [cartrulescart_ruleFilter_code] => [cartrulescart_ruleFilter_quantity] => [cartrulescart_ruleFilter_date_to] => [cartrulescart_ruleFilter_active] => [checksum] => 839908799 ) [_name:protected] => 761e67b124cfb51e47e25b2f56688acd [_expire:protected] => 1454512704 [_domain:protected] => [_path:protected] => /presta15/abc/ [_cipherTool:protected] => Rijndael Object ( [_key:protected] => 8XpQSG6dye6wiBdd6I06Nbuht9uOsf6Y [_iv:protected] => Iw"= h9\? ) [_modified:protected] => [_allow_writing:protected] => 1 [_salt:protected] => 7P0pRkIO [_standalone:protected] => ) [cart] => [altern] => 5 )

Link to comment
Share on other sites

well, that shows that the entire Product object was passed into $params.  Since you didn't state which version of Prestashop you are using, I have to assume the latest.

 

So, instead of trying to get the id_product, get product from the array.  If you really need to product id, then do $product->id

public function hookActionProductUpdate($params) {
    $product = $params['product'];
    echo ($product->id);
}
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...