Jump to content

Retrieve id_manufacturer for the products in Ajax cart


Captain Harlock

Recommended Posts

Before you can access the product manufacturer inside ajax-cart.js, you'll need to add it as a data variable on the "Add to cart" button. For example, change line 157 of themes/default-bootstrap/product-list.tpl from:
<a class="button ajax_add_to_cart_button btn btn-default" href="{$link->getPageLink('cart', true, NULL, $smarty.capture.default, false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart'}" data-id-product-attribute="{$product.id_product_attribute|intval}" data-id-product="{$product.id_product|intval}" data-minimal_quantity="{if isset($product.product_attribute_minimal_quantity) && $product.product_attribute_minimal_quantity >= 1}{$product.product_attribute_minimal_quantity|intval}{else}{$product.minimal_quantity|intval}{/if}">

to:

<a class="button ajax_add_to_cart_button btn btn-default" href="{$link->getPageLink('cart', true, NULL, $smarty.capture.default, false)|escape:'html':'UTF-8'}" rel="nofollow" title="{l s='Add to cart'}" data-id-product-attribute="{$product.id_product_attribute|intval}" data-id-product="{$product.id_product|intval}" data-minimal_quantity="{if isset($product.product_attribute_minimal_quantity) && $product.product_attribute_minimal_quantity >= 1}{$product.product_attribute_minimal_quantity|intval}{else}{$product.minimal_quantity|intval}{/if}" data-id-product-manufacturer="{$product.id_manufacturer|intval}">

Notice the data-id-product-manufacturer="{$product.id_manufacturer|intval}" at the end of the line.

 

Then you can write code like the following in ajax-cart.js:

var idManufacturer = parseInt($(this).data('id-product-manufacturer'));

I hope this points you in the right direction.

Link to comment
Share on other sites

It works fine on my PrestaShop v1.6.1.11 test site. I adding the following at line 136 of themes/default-bootstrap/js/modules/blockcart/ajax-cart.js:

var idProductManufacturer = parseInt($(this).data('id-product-manufacturer'));
alert('idProductManufacturer is '+idProductManufacturer);

And when I click the "Add to cart" button on a product list, I see "idProductManufacturer is 1" appear in a popup.

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...