Download the PHP package setono/sylius-wishlist-plugin without Composer
On this page you can find all versions of the php package setono/sylius-wishlist-plugin. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download setono/sylius-wishlist-plugin
More information about setono/sylius-wishlist-plugin
Files in setono/sylius-wishlist-plugin
Package sylius-wishlist-plugin
Short Description Setono example plugin for Sylius.
License MIT
Informations about the package sylius-wishlist-plugin
Wishlist Plugin for Sylius
Add a wishlist (a.k.a. favourites / save for later) to your Sylius store. Visitors can save products whether or not they're logged in, the wishlist follows them from anonymous browsing into their account, and they can move everything to the cart in one click.
Features
- 🛍️ Guest and customer wishlists – anonymous visitors get a wishlist tied to a cookie; logged-in customers get one tied to their account.
- 🔄 Automatic hand-off on login – when a guest with a wishlist logs in, their items are moved onto their customer wishlist, so nothing is lost.
- ❤️ Drop-in toggle button – a ready-made "heart" button that adds/removes a product (or a specific variant) over AJAX, plus a JS event you can hook into.
- 🛒 Add the whole wishlist to the cart in a single request.
- 📝 Per-item notes – shoppers can add a free-text note to each wishlist item (e.g. a size or colour preference), editable by the owner and visible to anyone they share the wishlist with.
- 🔗 Shareable wishlists – every wishlist has a UUID, so it can be viewed via a stable, shareable URL.
- 🧩 Extensible – all resources (models, repositories, factories) are overridable, and the "whose wishlist is this?" logic is a tagged service you can plug into.
Heads up: the data model already supports multiple wishlists per customer, but the UI/flow for choosing between them is still a work in progress (the
select-wishlistsendpoint currently returns Not implemented).
How it works
A few concepts are worth understanding before you integrate the plugin.
Wishlists and items
Wishlist is an abstract resource with two concrete subclasses:
| Class | Belongs to | Identified by |
|---|---|---|
GuestWishlist |
an anonymous visitor | a clientId (cookie, see below) |
UserWishlist |
a logged-in Sylius\…\User\Model\UserInterface |
the user |
Each wishlist holds WishlistItems. An item references either a product or a specific product variant
(plus a quantity and an optional free-text note), and every wishlist exposes a uuid (UUID v7) used in its
public, shareable URL.
Who owns the current wishlist?
Everything in the plugin asks one service – WishlistProviderInterface – for "the current visitor's
wishlists". It's a composite built from two tagged providers, consulted by priority, returning the first
non-empty result:
UserWishlistProvider– the wishlists of the logged-in customer (via Symfony Security).GuestWishlistProvider– the guest wishlist for the current cookie client id.
The result is memoized for the duration of the request by a caching decorator. To add another source (e.g. a
shared/team wishlist), implement WishlistProviderInterface and tag it – you never touch the composite itself.
Guest identity
Anonymous visitors are identified through setono/client-bundle, which assigns a stable
client id stored in a cookie. That id keys the guest wishlist. When the visitor authenticates, a login subscriber
(ConvertGuestWishlistToUserWishlistSubscriber) converts the guest wishlist into a user wishlist.
Templates & the toggle flow
The plugin exposes two Twig functions so your templates can react to wishlist state:
Adding/removing happens against small JSON endpoints. The bundled wishlist-action-handler.js listens for clicks
on button.ssw-toggle, calls the endpoint, flips the button state, and dispatches a ssw:product-toggled event
you can listen to (e.g. to update a header counter).
Requirements
| Package | Version |
|---|---|
| PHP | ^8.1 |
| Sylius | ^1.13 |
| Symfony | ^6.4 |
| Twig | ^3.8 |
Installation
1. Require the package
2. Register the plugin
Add the bundle to config/bundles.php before SyliusGridBundle, otherwise you'll get a
You have requested a non-existent parameter "setono_sylius_wishlist.model.wishlist.class" exception:
3. Import the routing
If your shop doesn't use locales in the URL, import routes_no_locale.yaml instead:
4. Update your database
The plugin ships Doctrine mappings; generate and run a migration for your app:
5. Install the assets
The toggle button's stylesheet and script are injected into the shop layout automatically (via sylius_ui
events), but the JS file still needs to be published:
Usage
Add a wishlist button to your product page
Include the bundled partial wherever you render a product (e.g. the product box or the product show page),
passing the product and – optionally – the selected productVariant:
It renders a heart button.ssw-toggle whose data-url points at the correct add/remove route and whose state
reflects setono_sylius_wishlist_on_wishlist(...). No extra wiring is needed – the CSS/JS are already on the
page.
React to toggles in JavaScript
Every toggle dispatches a bubbling ssw:product-toggled event:
You can override the handler's defaults by setting window.sswWishlist before the script loads (e.g. to change
the selector.toggle or provide your own callback.onToggle).
Link to the wishlist
The wishlist index and a single (shareable) wishlist are available at these routes:
| Route name | Method | Path |
|---|---|---|
setono_sylius_wishlist_shop_wishlist_index |
GET | /wishlists |
setono_sylius_wishlist_shop_wishlist_show |
GET, PATCH | /wishlists/{uuid} |
setono_sylius_wishlist_shop_wishlist_add_to_cart |
GET | /wishlists/{uuid}/add-to-cart |
setono_sylius_wishlist_shop_wishlist_item_remove |
GET | /wishlists/{uuid}/remove-item/{id} |
setono_sylius_wishlist_shop_wishlist_add_product |
GET | /wishlist/add-product/{id} |
setono_sylius_wishlist_shop_wishlist_remove_product |
GET | /wishlist/remove-product/{id} |
(The *_product_variant variants of the add/remove routes exist too.) Because a wishlist is addressed by its
uuid, the _show URL can be shared with anyone.
Customization
Override a resource
Models, repositories and factories follow the standard Sylius Resource configuration. To swap in your own model:
Provide your own wishlists
Implement Setono\SyliusWishlistPlugin\Provider\WishlistProviderInterface and tag it; the composite provider
picks it up automatically (higher priority is consulted first):
Edit authorization
Edit actions are guarded by WishlistVoter (the wishlist_edit attribute), which grants access only when the
subject wishlist belongs to the current visitor. Override the voter if you need different rules.
Development
The repository contains a full test Sylius application under tests/Application used for integration testing.
License
This plugin is released under the MIT License.
All versions of sylius-wishlist-plugin with dependencies
doctrine/collections Version ^1.6
doctrine/persistence Version ^2.0 || ^3.0
setono/client-bundle Version ^1.2
setono/composite-compiler-pass Version ^1.2
setono/doctrine-orm-trait Version ^1.1
sylius/core Version ^1.13
sylius/core-bundle Version ^1.13
sylius/order Version ^1.13
sylius/product-bundle Version ^1.13
sylius/resource-bundle Version ^1.11
sylius/user Version ^1.13
symfony/config Version ^6.4
symfony/dependency-injection Version ^6.4
symfony/event-dispatcher Version ^6.4
symfony/form Version ^6.4
symfony/http-foundation Version ^6.4
symfony/http-kernel Version ^6.4
symfony/options-resolver Version ^6.4
symfony/routing Version ^6.4
symfony/security-bundle Version ^6.4
symfony/security-core Version ^6.4
symfony/security-http Version ^6.4
symfony/translation-contracts Version ^2.0 || ^3.0
symfony/uid Version ^6.4
twig/twig Version ^3.8
webmozart/assert Version ^1.11