NemoPS Posted August 12, 2013 Share Posted August 12, 2013 Hey everybody! I got curious after reading this user's post: http://www.prestashop.com/forums/topic/266574-how-to-add-compare-to-the-product-page-not-only-category/ I went deeper and came up with a tutorial on how to add the compare butto nto the single product page. Here it is! http://nemops.com/compare-button-to-product-page/ Cheers! 2 Link to comment Share on other sites More sharing options...
damian5000 Posted September 8, 2013 Share Posted September 8, 2013 (edited) The tutorial isn't very noob friendly. Step 1 is clear enough, but then step 2 and 3 aren't so clear. Is this added to the .php created in step 1? So, I have this in a file called productcontroller.php, is it correct? <?php class ProductController extends ProductControllerCore { } public function setMedia() { parent::setMedia(); if (Configuration::get('PS_COMPARATOR_MAX_ITEM')) $this->addJS(_THEME_JS_DIR_.'products-comparison.js'); } public function initContent() { $this->context->smarty->assign('comparator_max_item', Configuration::get('PS_COMPARATOR_MAX_ITEM')); if (isset($this->context->cookie->id_compare)) $this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare)); parent::initContent(); } ?> Edited September 8, 2013 by damian5000 (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted September 9, 2013 Author Share Posted September 9, 2013 Yes, that's correct, it's the same php file Link to comment Share on other sites More sharing options...
damian5000 Posted September 10, 2013 Share Posted September 10, 2013 (edited) Thanks... So it's perfect as shown? I mean, all the functions and closing signs are in the right place? Or should the 'public functions' go within 'class product controller....' BTW, thanks for the tutorial. It blows my mind this isn't default functionality. Edited September 10, 2013 by damian5000 (see edit history) Link to comment Share on other sites More sharing options...
frosticek Posted June 26, 2014 Share Posted June 26, 2014 Guys, Actually you do not need to modify core files, you can use only tpl files. Array {$compareProduct} can be replaced with simple: {CompareProduct::getCompareProducts((int)$cookie->id_compare)} Thats it, so easy Link to comment Share on other sites More sharing options...
NemoPS Posted June 27, 2014 Author Share Posted June 27, 2014 Yes. but it's always better to keep logic away from views as whenever possible Link to comment Share on other sites More sharing options...
frank_jarle Posted November 1, 2014 Share Posted November 1, 2014 (edited) Is it possible to not use the checkbox, just have a Add to Compare button? I would like to have a "Add to compare" above "Add to Wishlist" and i think it just looks neater without the [ ] checkbox. Thanks! Edited November 1, 2014 by frank_jarle (see edit history) Link to comment Share on other sites More sharing options...
NemoPS Posted November 1, 2014 Author Share Posted November 1, 2014 Well yes, but you have to create a javascript trigger for it, different than the compare.tpl one Link to comment Share on other sites More sharing options...
frank_jarle Posted November 8, 2014 Share Posted November 8, 2014 I am not sure if i understand. Does that means that it is not possible to add "Compare" to the product page without having the checkbox? In my mind "add to wishlist" looked so simple but to add "compare" without the checkbox seems to complicated :-) Or is it just complicated in my head? Frank Link to comment Share on other sites More sharing options...
NemoPS Posted November 8, 2014 Author Share Posted November 8, 2014 As I said, you can, but you need to add some javascript as well as html Link to comment Share on other sites More sharing options...
frank_jarle Posted November 23, 2014 Share Posted November 23, 2014 Sorry, i am not a developer, i am a spoon-feed-me admin :-) Link to comment Share on other sites More sharing options...
davidmr92 Posted January 29, 2015 Share Posted January 29, 2015 Dont works on PS 1.6+ Link to comment Share on other sites More sharing options...
NemoPS Posted January 30, 2015 Author Share Posted January 30, 2015 Well you need to adapt the template's code, of course, did you just copy/paste? Link to comment Share on other sites More sharing options...
davidmr92 Posted January 30, 2015 Share Posted January 30, 2015 Yes, I don't know to adapt this. Could you help me please? Link to comment Share on other sites More sharing options...
kosm12 Posted March 13, 2015 Share Posted March 13, 2015 You must create ProductController.php how write this, but in product.tpl you must insert {if isset($comparator_max_item) && $comparator_max_item} <div class="compare"><a class="add_to_compare" href="#" data-id-product="{$product->id|intval}">{l s='Add to Compare'}</a></div>{/if}{include file="./product-compare.tpl"} and I add this: {*Products compare *}{addJsDefL name=min_item}{l s='Please select at least one product' js=1}{/addJsDefL}{addJsDefL name=max_item}{l s='You cannot add more than %d product(s) to the product comparison' sprintf=$comparator_max_item js=1}{/addJsDefL}{addJsDef comparator_max_item=$comparator_max_item}{addJsDef comparedProductsIds=$compared_products} Link to comment Share on other sites More sharing options...
mmsh Posted June 15, 2015 Share Posted June 15, 2015 hello, PS 1.4 in addition to "$this->context" which you can't use on PS 1.4 which are the differences, please? How to let it work on PS 1.4? I tried something but with no success... thanks Link to comment Share on other sites More sharing options...
mmsh Posted June 15, 2015 Share Posted June 15, 2015 in PS 1.4 there is no CompareProduct.php class and no ps_compare table (for getCompareProducts () function ) I was able to put the select and compare buttons on the page, but is there a way to keep the products in the cookie in PS 1.4 when the user clicks on the selection box? thanks Link to comment Share on other sites More sharing options...
NemoPS Posted December 30, 2015 Author Share Posted December 30, 2015 You might have added it inside another <form> which causes your second one not to be loaded Link to comment Share on other sites More sharing options...
mrhandaka Posted June 6, 2017 Share Posted June 6, 2017 i have followed the tutorial, but i got 404 error after that. It shows 404 Error every I open the product details. I have deleted the productcontroller.php and undo the product.tpl like before but it still 404 Error. can i get some help? Link to comment Share on other sites More sharing options...
NemoPS Posted June 7, 2017 Author Share Posted June 7, 2017 Sounds strange, did you clear the class index after you removed the override? Link to comment Share on other sites More sharing options...
mrhandaka Posted June 8, 2017 Share Posted June 8, 2017 Sounds strange, did you clear the class index after you removed the override? I have solved it by myself. haha, i had removed the ProductController.php in public_html/controllers/front/ as accidentally. Link to comment Share on other sites More sharing options...
gabrielio Posted August 21, 2019 Share Posted August 21, 2019 (edited) Thanks for the solution, i solved it like this: 1. Create the override file ProductController.php (like @NemoPS mentioned in his tutorial link) containing the code shown below and upload the file to override/controllers/front <?php class ProductController extends ProductControllerCore { public function setMedia() { parent::setMedia(); if (Configuration::get('PS_COMPARATOR_MAX_ITEM')) $this->addJS(_THEME_JS_DIR_.'products-comparison.js'); } public function initContent() { $this->context->smarty->assign('comparator_max_item', Configuration::get('PS_COMPARATOR_MAX_ITEM')); if (isset($this->context->cookie->id_compare)) $this->context->smarty->assign('compareProducts', CompareProduct::getCompareProducts((int)$this->context->cookie->id_compare)); parent::initContent(); } } ?> 2. In product.tpl add the following code (like @kosm12 mentioned) where you want the "add to compare" button to appear. You can customise the check button using css before and after. <div class="compare_product_page"> {if isset($comparator_max_item) && $comparator_max_item} <div class="compare"> <a class="add_to_compare" href="#" data-id-product="{$product->id|intval}">{l s='Add to Compare'}</a> </div> {/if} {include file="./product-compare.tpl"} </div> {*Products compare *} {addJsDefL name=min_item}{l s='Please select at least one product' js=1}{/addJsDefL} {addJsDefL name=max_item}{l s='You cannot add more than %d product(s) to the product comparison' sprintf=$comparator_max_item js=1}{/addJsDefL} {addJsDef comparator_max_item=$comparator_max_item} {addJsDef comparedProductsIds=$compared_products} You can see the results live, here: https://laptop-hunter.com/notebook-hp-15-dw0012na-6pc36ea-silver-6098.html PS: I forgot to mention that i use Prestashop 1.6.1.18. Thank you! Edited August 21, 2019 by gabrielio (see edit history) Link to comment Share on other sites More sharing options...
ruisonika Posted March 31, 2021 Share Posted March 31, 2021 Is it possible to add in product-list.tpl? Link to comment Share on other sites More sharing options...
niekoarchimedes Posted April 23, 2021 Share Posted April 23, 2021 (edited) I would like to have a "Add to compare" above "Add to Wishlist" and water damage restoration i think it just looks neater without the [ ] checkbox. Thanks! Edited April 27, 2021 by niekoarchimedes (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