Favorite/wishlist products
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Favorite/wishlist products
Hello, aimeos!
In the list of products, I have added the form containing the button to add the product to the favorites/wishlist:
With CSS, the button is only displayed when the user hovers over the product. When the button is clicked, it correctly adds to the favorites/wishlist.
What I want to do now, is to add a different color to the button in case the product is already in the favorites/wishlist, and also when the user clicks on it, it removes it from the favorites/wishlist.
How can I check if the product has been added to favorites/wishlist to perform the toggle/switch CSS styles and action?
Best regards,
In the list of products, I have added the form containing the button to add the product to the favorites/wishlist:
Code: Select all
<form
class="actions-favorite mb-2"
method="POST"
action="<?= $enc->attr( $this->link( 'client/html/account/favorite/url' ) ) ?>"
>
<!-- catalog.detail.csrf -->
<?= $this->csrf()->formfield() ?>
<!-- catalog.detail.csrf -->
<input
type="hidden"
name="<?= $this->formparam( 'fav_action' ) ?>"
value="add"
/>
<input
type="hidden"
name="<?= $this->formparam( 'fav_id' ) ?>"
value="<?= $enc->attr( $productItem->getId() ) ?>"
/>
<input
type="hidden"
name="<?= $this->formparam( 'd_prodid' ) ?>"
value="<?= $enc->attr( $productItem->getId() ) ?>"
/>
<input
type="hidden"
name="<?= $this->formparam( 'd_name' ) ?>"
value="<?= $productItem->getName( 'url' ) ?>"
/>
<button
class="actions-button favorite-action"
title="<?= $enc->attr( $this->translate( 'client/code', 'favorite' ) ) ?>"
>
<i class="bi bi-heart"></i>
</button>
</form>
With CSS, the button is only displayed when the user hovers over the product. When the button is clicked, it correctly adds to the favorites/wishlist.
What I want to do now, is to add a different color to the button in case the product is already in the favorites/wishlist, and also when the user clicks on it, it removes it from the favorites/wishlist.
How can I check if the product has been added to favorites/wishlist to perform the toggle/switch CSS styles and action?
Best regards,
Re: Favorite/wishlist products
You can use the same method as Aimeos uses for pinned products:
- https://github.com/aimeos/ai-client-htm ... js#L24-L36
- https://github.com/aimeos/ai-client-htm ... #L121-L152
- https://github.com/aimeos/ai-client-htm ... ms.php#L26
- https://github.com/aimeos/ai-client-htm ... #L357-L361
Additionally, you have to load the customer favorite items here to make them available in the template:
https://github.com/aimeos/ai-client-htm ... andard.php
We would love if you can create a PR to get that feature into the Aimeos core
- https://github.com/aimeos/ai-client-htm ... js#L24-L36
- https://github.com/aimeos/ai-client-htm ... #L121-L152
- https://github.com/aimeos/ai-client-htm ... ms.php#L26
- https://github.com/aimeos/ai-client-htm ... #L357-L361
Additionally, you have to load the customer favorite items here to make them available in the template:
https://github.com/aimeos/ai-client-htm ... andard.php
We would love if you can create a PR to get that feature into the Aimeos core
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star