Sylius / ShopApiPlugin

Shop API for Sylius.
https://sylius.com
129 stars 89 forks source link

[FEATURE] Set Session CartContext via order token #704

Open franzwilding opened 3 years ago

franzwilding commented 3 years ago

Hey! I'm evaluating different approaches to include Sylius as a complete-headless or semi-headless e-commerce platform into our technology stack. The "semi-headless" approach would use some of the bigger Sylius SF/Twig frontend modules like the checkout, login, profile etc. while the integration into websites will be done via the API.

One of the user flows works like this:

  1. User creates a new cart and gets it's unique token value
  2. User adds items to this cart by using the token value
  3. User will be redirected to the Sylius checkout page

Is there an already existing way to pass a token value to a special route to set it as the default cart in the user session? I think it would be very easy to create such a controller and set the cart into the cart storage, however I was wondering if there already exists such a functionality and if others would like to have this.

mamazu commented 3 years ago

Hello, if you want to checkout with a predefined token in the ShopBundle, then there is no way in the standard Sylius. In general there is no way to migrate between the Shop UI and API. It is recommended to not use them together. So if you want to you should build some custom logic.

lchrusciel commented 3 years ago

Hey Frantz,

what you are describing is indeed possible with ShopAPI, but would require this custom controller. What you've described would be even easier for logged-in user, because of cart assignment. However I would recommend you to test out Unified API served together with the newest Sylius, as there are a few more things fixed already(like links in the emails that point out to twig-based website if it is enabled by default).

franzwilding commented 3 years ago

Hey @mamazu and @lchrusciel, thank you both for your answers! I will have a closer look into the new unified API.

@mamazu can you recommend a better approach to include a Sylius Cart and an add-to-cart-button into another website? I don't want to have a full headless shop frontend and I also don't want to include the CMS content into the Sylius frontend.