Post by dyulo » Fri Mar 22, 2019 10:49 am

Hi all,

I'd like to change the style of the add to wishlist button when the product is already in the wishlist, perhaps change the color of the heart icon into red.
How can I check if the product is already in the wishlist regardless if the user is logged-in or not.

Hoping for the best and detailed answers.

Opencart 2.3.0.2

Newbie

Posts

Joined
Wed Feb 27, 2019 7:30 pm

Post by straightlight » Sun Mar 24, 2019 6:21 am

This can be changed via your stylesheet.css file of your custom theme.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by dyulo » Sun Mar 24, 2019 7:50 am

Hi straightlight,

I was talking about the status of the wishlist button on products. If the product is already in the wishlist, then set the button or the icon of the button to a red heart. If the product is not on the wishlist, then display the default button with the gray heart. Can this be really done only in stylesheet? Why is this not an opencart default function anyway?

Here is the default code that I want to change. See the wishlist part of the code:

Code: Select all

<div class="button-group">
	<button type="button" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><span class="hidden-xs hidden-sm hidden-md"><?php echo $button_cart; ?></span> <i class="fa fa-shopping-cart"></i></button>
	<button type="button" data-toggle="tooltip" title="<?php echo $button_wishlist; ?>" onclick="wishlist.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-heart"></i></button>
	<button type="button" data-toggle="tooltip" title="<?php echo $button_compare; ?>" onclick="compare.add('<?php echo $product['product_id']; ?>');"><i class="fa fa-exchange"></i></button>
</div>
I've found these 2 similar forum posts:
viewtopic.php?t=153316
viewtopic.php?t=96874

But the solutions provided doesn't seem to work on my case. Maybe I didn't perform the solutions correctly as I only have a few knowledge on this.

Any help for a Newbie like me is very much appreciated :)

Newbie

Posts

Joined
Wed Feb 27, 2019 7:30 pm

Post by dyulo » Mon Mar 25, 2019 11:13 am

Anyone?

Newbie

Posts

Joined
Wed Feb 27, 2019 7:30 pm

Post by wee » Mon Jun 03, 2019 9:02 pm

Hi,

I am also keen to change the color of the heart icon into red when clicking the item into wishlist. May I know if anyone can guide me to achieve this objective?

Thank you.

wee
Newbie

Posts

Joined
Fri Feb 24, 2017 11:53 pm

Post by grgr » Tue Jun 04, 2019 11:54 am

Code: Select all

if (isset($this->session->data['wishlist'])) {
 $data['wishlist_test'] = in_array($product_id, $this->session->data['wishlist']);
} 
Sets $data['wishlist_test'] to TRUE or FALSE.

This needs to go in the ../controller/product/product.php file above (around line 160):

Code: Select all

$product_info = $this->model_catalog_product->getProduct($product_id);
You can then use $wishlist_test in an if statement in the product template file.

-
Image Image Image Image
VIEW ALL EXTENSIONS * EXTENSION SUPPORT * WEBSITE * CUSTOM REQUESTS


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK

Post by straightlight » Tue Jun 04, 2019 7:19 pm

Since it is about defining a true or false statement, and that the array hasn't been defined before the IF statement or without validating the IF statement from the TWIG file, the validation may fail.

Code: Select all

if (isset($this->session->data['wishlist'])) {
 $data['wishlist_test'] = in_array($product_id, $this->session->data['wishlist']);
}
should be replaced with:

Code: Select all

$data['wishlist_test'] = false;

if (isset($this->session->data['wishlist'])) {
	$data['wishlist_test'] = in_array($product_id, $this->session->data['wishlist']);
}
or from the related TWIG file:

Code: Select all

{% if wishlist_text %}
	... your true returned result code here ...
{% else %}
	... your false returned result code here ...
{% endif %}

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by wee » Fri Jun 07, 2019 10:08 am

Hi,

May I know where is the heart icon of the wish list located, and how to change its color from grey to red?

Thanks.

wee
Newbie

Posts

Joined
Fri Feb 24, 2017 11:53 pm

Post by DigitCart » Tue Sep 03, 2019 9:12 pm

Hi
I have a commercial extension that can do that:
Add to Wishlist Button Switcher
https://www.opencart.com/index.php?rout ... n_id=37140

My Extensions


User avatar
Active Member

Posts

Joined
Thu Jun 22, 2017 5:32 pm


Post by thekrotek » Sat Oct 10, 2020 3:21 am

And here's a free solution: Better Wishlist Button.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am

Who is online

Users browsing this forum: No registered users and 50 guests