jesper03 Posted July 23, 2016 Share Posted July 23, 2016 Hi everyone, I'm new in designing Prestashop e-commerce website and I have a request for you. I edited the product.tpl file in order to show some kind of product's combination in a table. I added all the informations and for each row I added a button to add the specific product combination to cart. this is the specific line I used for the link: <a class="ajax_add_to_cart_button_custom" href="{$link->getPageLink('cart', true, NULL, "qty=1&id_product={$product->id}&token={$static_token}&add")}" rel="ajax_id_product_{$product->id|intval}" name="ajax_attr_product_{$group_attribute.attribute_id}" title="{l s='Add to cart'}">Aggiungi</a> This seems to work but the only problem is that only the default combination is added to the cart. I added the "name" attribute and also this lines to the ajax-cart.js file: $('.ajax_add_to_cart_button_custom').unbind('click').click(function() { var idProduct = $(this).attr('rel').replace('nofollow', '').replace('ajax_id_product_', ''); var idAttribute = $(this).attr('name').replace('nofollow', '').replace('ajax_attr_product_', ''); if ($(this).attr('disabled') != 'disabled') ajaxCart.add(idProduct, idAttribute, false, this); return false; }); This, instead, is the line I added to the ProductController.php file: $groups[$row['id_attribute_group']]['name_price'][$row['id_attribute']] = array('name' => $row['attribute_name'],'price' => number_format($row['price'],2), 'attribute_id' => $row['id_attribute']); I tried to put some console.log print to understand if I'm editing the right file but nothing comes out. I tried to edit all the file for ajax-cart.js both in my theme folder and in the module folder. I don't know if this is the right way to accomplish this task but as I already said I'm still not very confident with Prestashop. Hope some of you out there can help me. Have a nice day. PS: I'm sorry for my bad english.. Link to comment Share on other sites More sharing options...
vekia Posted July 23, 2016 Share Posted July 23, 2016 put console.log(idAttribute) to your function $('.ajax_add_to_cart_button_custom').unbind('click').click(function() do you see console log output it if you click on the button? Link to comment Share on other sites More sharing options...
jesper03 Posted July 23, 2016 Author Share Posted July 23, 2016 I've already tried but unfortunately nothing came out so I guess I'm not working on the right file. Is there a way to know which is the path to the actual js file that is used? Link to comment Share on other sites More sharing options...
vekia Posted July 23, 2016 Share Posted July 23, 2016 if you use default theme - check your theme file: themes/default-bootstrap/js/modules/blockcart/ajax-cart.js if you use some other template case needs inspection directly in your shop (no one knows how the theme is coded) Link to comment Share on other sites More sharing options...
jesper03 Posted July 27, 2016 Author Share Posted July 27, 2016 (edited) Thanks for you help. Anyway I still can't get this working. No console log print came out. I also tried to add "ipa" or "id_product_attribute" to the link for the cart controller but in this case I get the message "You already have the maximum quantity available for this product". I'm using the default theme so I tried to edit also the themes/default-bootstrap/js/modules/blockcart/ajax-cart.js but still no console output, even for the click event on the default add to cart button of product page. EDIT: if I try to reference the ajaxCart var declared in the ajax-cart.js, I get the error "ajaxCart is not defined" so the javascript file is not called inside the tpl file. Edited July 27, 2016 by jesper03 (see edit history) 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