Captain Harlock Posted February 28, 2017 Share Posted February 28, 2017 (edited) Greetings, I'd like to know how to get the products' manufacturer id in : - \themes\default-bootstrap\js\modules\ajax-cart.js Thank you ! Edited February 28, 2017 by Captain Harlock (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted March 1, 2017 Share Posted March 1, 2017 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 More sharing options...
Captain Harlock Posted March 1, 2017 Author Share Posted March 1, 2017 (edited) Thank you. I tried it, but then, when I tried to call "idManufacturer" or "product.idManufacturer", the value is still "undefinied". Actually, I try to call it in the updateLayer function (about line 730, in ajax-cart.js). Edited March 1, 2017 by Captain Harlock (see edit history) Link to comment Share on other sites More sharing options...
rocky Posted March 1, 2017 Share Posted March 1, 2017 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 More sharing options...
Captain Harlock Posted March 1, 2017 Author Share Posted March 1, 2017 Yes, it does work in the ajaxCart function, but not in the updateLayer function, which I need... unless I use a global variable, but I have been told that is not a good idea. Link to comment Share on other sites More sharing options...
rocky Posted March 2, 2017 Share Posted March 2, 2017 I can't see any easy solution to get the manufacturer in there. I guess you'll have to use a global variable, even though that's not a good idea. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now