Favorite/wishlist products

Help for integrating the Laravel package
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!
User avatar
peter69
Posts: 95
Joined: 09 Jun 2022, 19:31

Favorite/wishlist products

Post by peter69 » 16 Nov 2022, 22:51

Hello, aimeos!

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,

User avatar
aimeos
Administrator
Posts: 7896
Joined: 01 Jan 1970, 00:00

Re: Favorite/wishlist products

Post by aimeos » 17 Nov 2022, 17:42

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 :-)
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply