-
Posts
5 -
Joined
-
Last visited
Profile Information
-
Location
Chandigarh India
-
Activity
Developer
Recent Profile Visitors
122 profile views
Aditya Kaushik's Achievements
Newbie (1/14)
3
Reputation
-
Compare button on every product page
Aditya Kaushik replied to grega33's topic in OUT - 1.6.0.11 [7 Jan 2015]
If it still not works Add this code as it is in the product.js- ---------------------------------------------------------------------------- function addToCompare() { product_id = $('#product_page_product_id').val(); var totalValueNow = parseInt($('.bt_compare').next('.compare_product_count').val()); var totalVal; if (totalValueNow < 3) { $.ajax({ url: 'index.php?controller=products-comparison&ajax=1&action=add&id_product=' + product_id, async: true, cache: false, type: 'Post', dataType: 'html' }); compareButtonsStatusRefresh(); totalVal = totalValueNow + 1, $('.bt_compare').next('.compare_product_count').val(totalVal), totalValue(totalVal); $('.bt_compare').attr("disabled", false); $('.bt_compare').css("background-color", "#E8490C"); $('.bt_compare').css("color", "#fff"); } else { var $div8 = $(".comapare_max_limit"); if ($div8.is(":visible")) { return; } $div8.show(); setTimeout(function() { $div8.hide(); }, 4000); var $div9 = $(".product-added_overlay"); if ($div9.is(":visible")) { return; } $div9.show(); setTimeout(function() { $div9.hide(); }, 4000); } } function totalValue(value) { $('.bt_compare').find('.total-compare-val').html(value); } function compareButtonsStatusRefresh() { $('.add_to_compare').each(function() { if ($.inArray(parseInt($(this).data('id-product')), comparedProductsIds) !== -1) $(this).addClass('checked'); else $(this).removeClass('checked'); }); } -------------------------------------------------------------------------------------- After this add the code below in product.tpl- ---------------------------------------------------------------------------- <div class="full_width compare-product"> {if isset($comparator_max_item) && $comparator_max_item} <a onclick="addToCompare()" href="#" data-id-product="{$product->id|intval}"><span class="tn btn-default button button-medium"><i class="fa fa-plus"></i> Add to Compare</span></a> <div class="comapare_max_limit">You cannot add more than 3 product(s) to the product comparison</div> {*<a href="index.php?controller=products-comparison&ajax=1&action=add&id_product={$product->id|intval}" data-id-product="{$product->id|intval}"><span>Add to Compare</span></a>*} {/if} {include file="./product-compare.tpl"} </div> ---------------------------------------------------------------------------- This should solve the problems B)- 20 replies
-
- 2
-
- comparison
- product compare
-
(and 1 more)
Tagged with:
-
Compare button on every product page
Aditya Kaushik replied to grega33's topic in OUT - 1.6.0.11 [7 Jan 2015]
Hi friends As mentioned if you are geeting some url on the hover that means that the anchor tag for "Add to Compare" is having href value as the url , but as shown in the code submitted above it must be "#"- <a onclick="addToCompare()" href="#" data-id-product="{$product->id|intval}"><span class="product_btn_comparison">Add to Compare</span></a> The "#" you are getting in url has nothing to do with the add to comparison function and is not an error, it is coded so. The actual work of adding the product to the comparison list is being done by ajax function mentioned in the javascript block of the above code- $.ajax({ url: 'index.php?controller=products-comparison&ajax=1&action=add&id_product=' + {$product->id|intval}, async: true, cache: false, type: 'Post', dataType: 'html' }); Possible errors that might have been done if this code is not working are- 1. The href value of "Add to compare" anchor<a> tag pointing to some page// --It must be "#" only. <a onclick="addToCompare()" href="#" data-id-product="{$product->id|intval}"><span class="product_btn_comparison">Add to Compare</span></a> 2.In the ajax function in the javascript section the url must have a product id which in my case was-{$product->id|intval}, this variable name can be different too-- url: 'index.php?controller=products-comparison&ajax=1&action=add&id_product=' + {$product->id|intval}, I would advice to use the code pasted initially by me "as it is" to avoid any confusion of code. The code works and is to be pasted in product.tpl only Hope this will help Thanks- 20 replies
-
- comparison
- product compare
-
(and 1 more)
Tagged with:
-
Add this code in "product.tpl" where you want to place the "Add to Compare button", code is working fine with Prestshop 1.6 version too --and consists of javascript code /ajax function to add a product to comapre. Use this code and Enjoy B) :D <!--Add to Compare----> <script type=\"text/javascript\"> function addToCompare() { var totalValueNow = parseInt($('.bt_compare').next('.compare_product_count').val()); var totalVal; if(totalValueNow<3){ $.ajax({ url: 'index.php?controller=products-comparison&ajax=1&action=add&id_product=' + {$product->id|intval}, async: true, cache: false, type: 'Post', dataType: 'html' }); compareButtonsStatusRefresh(); totalVal = totalValueNow +1, $('.bt_compare').next('.compare_product_count').val(totalVal), totalValue(totalVal); $('.bt_compare').attr("disabled",false); $('.bt_compare').css("background-color","#E8490C"); $('.bt_compare').css("color","#fff"); } else{ var $div8 = $(".comapare_max_limit"); if ($div8.is(":visible")) { return; } $div8.show(); setTimeout(function() { $div8.hide(); }, 4000); var $div9 = $(".product-added_overlay"); if ($div9.is(":visible")) { return; } $div9.show(); setTimeout(function() { $div9.hide(); }, 4000); } } function totalValue(value) { $('.bt_compare').find('.total-compare-val').html(value); } function compareButtonsStatusRefresh() { $('.add_to_compare').each(function() { if ($.inArray(parseInt($(this).data('id-product')), comparedProductsIds) !== -1) $(this).addClass('checked'); else $(this).removeClass('checked'); }); } </script> {if isset($comparator_max_item) && $comparator_max_item} <a onclick="addToCompare()" href="#" data-id-product="{$product->id|intval}"><span class="product_btn_comparison">Add to Compare</span></a> <div class="comapare_max_limit">You cannot add more than 3 product(s) to the product comparison</div> {/if} {include file="./product-compare.tpl"} <!------>
-
Add this code in "product.tpl" where you want to place the "Add to Compare button", code is working fine with Prestshop 1.6 version too --and consists of javascript code /ajax function to add a product to comapre. Use this code and Enjoy B) :D <!--Add to Compare----> <script type=\"text/javascript\"> function addToCompare() { var totalValueNow = parseInt($('.bt_compare').next('.compare_product_count').val()); var totalVal; if(totalValueNow<3){ $.ajax({ url: 'index.php?controller=products-comparison&ajax=1&action=add&id_product=' + {$product->id|intval}, async: true, cache: false, type: 'Post', dataType: 'html' }); compareButtonsStatusRefresh(); totalVal = totalValueNow +1, $('.bt_compare').next('.compare_product_count').val(totalVal), totalValue(totalVal); $('.bt_compare').attr("disabled",false); $('.bt_compare').css("background-color","#E8490C"); $('.bt_compare').css("color","#fff"); } else{ var $div8 = $(".comapare_max_limit"); if ($div8.is(":visible")) { return; } $div8.show(); setTimeout(function() { $div8.hide(); }, 4000); var $div9 = $(".product-added_overlay"); if ($div9.is(":visible")) { return; } $div9.show(); setTimeout(function() { $div9.hide(); }, 4000); } } function totalValue(value) { $('.bt_compare').find('.total-compare-val').html(value); } function compareButtonsStatusRefresh() { $('.add_to_compare').each(function() { if ($.inArray(parseInt($(this).data('id-product')), comparedProductsIds) !== -1) $(this).addClass('checked'); else $(this).removeClass('checked'); }); } </script> {if isset($comparator_max_item) && $comparator_max_item} <a onclick="addToCompare()" href="#" data-id-product="{$product->id|intval}"><span class="product_btn_comparison">Add to Compare</span></a> <div class="comapare_max_limit">You cannot add more than 3 product(s) to the product comparison</div> {/if} {include file="./product-compare.tpl"} <!------>
-
Compare button on every product page
Aditya Kaushik replied to grega33's topic in OUT - 1.6.0.11 [7 Jan 2015]
Add this code in "product.tpl" where you want to place the "Add to Compare button", code is working fine with Prestshop 1.6 version too --and consists of javascript code /ajax function to add a product to comapre. Use this code and Enjoy B) :D <!--Add to Compare----> <script type=\"text/javascript\"> function addToCompare() { var totalValueNow = parseInt($('.bt_compare').next('.compare_product_count').val()); var totalVal; if(totalValueNow<3){ $.ajax({ url: 'index.php?controller=products-comparison&ajax=1&action=add&id_product=' + {$product->id|intval}, async: true, cache: false, type: 'Post', dataType: 'html' }); compareButtonsStatusRefresh(); totalVal = totalValueNow +1, $('.bt_compare').next('.compare_product_count').val(totalVal), totalValue(totalVal); $('.bt_compare').attr("disabled",false); $('.bt_compare').css("background-color","#E8490C"); $('.bt_compare').css("color","#fff"); } else{ var $div8 = $(".comapare_max_limit"); if ($div8.is(":visible")) { return; } $div8.show(); setTimeout(function() { $div8.hide(); }, 4000); var $div9 = $(".product-added_overlay"); if ($div9.is(":visible")) { return; } $div9.show(); setTimeout(function() { $div9.hide(); }, 4000); } } function totalValue(value) { $('.bt_compare').find('.total-compare-val').html(value); } function compareButtonsStatusRefresh() { $('.add_to_compare').each(function() { if ($.inArray(parseInt($(this).data('id-product')), comparedProductsIds) !== -1) $(this).addClass('checked'); else $(this).removeClass('checked'); }); } </script> {if isset($comparator_max_item) && $comparator_max_item} <a onclick="addToCompare()" href="#" data-id-product="{$product->id|intval}"><span class="product_btn_comparison">Add to Compare</span></a> <div class="comapare_max_limit">You cannot add more than 3 product(s) to the product comparison</div> {/if} {include file="./product-compare.tpl"} <!------>- 20 replies
-
- 1
-
- comparison
- product compare
-
(and 1 more)
Tagged with: