duncanmcclean / simple-commerce

A simple, yet powerful e-commerce addon for Statamic.
https://statamic.com/addons/duncanmcclean/simple-commerce
Other
143 stars 36 forks source link

Multisite Single Cart - Line Items always in one site. #940

Closed mathamel closed 9 months ago

mathamel commented 9 months ago

Description

Enabling multisite and following the steps for the single cart across all site, we find one issue for the line items and translation.

Inside the cart.antlers.html, in the sc:cart tag, the site variable is not accessible  {site:url, site:handle, site:name}

Steps to reproduce

  1. create a new site
  2. enable multisite with at least 2 sites
  3. create product in 2 sites
  4. in frontend add a product to the cart, not in the default website
  5. go to the cart
  6. the item in the cart will have the wrong site handle/url and the button 'checkout' will go to 404 page without the site handle.

Environment

Environment Application Name: Statamic Laravel Version: 10.22.0 PHP Version: 8.2.12 Composer Version: 2.6.5 Environment: local Debug Mode: ENABLED URL: lapara-commerce.test Maintenance Mode: OFF

Cache Config: NOT CACHED Events: NOT CACHED Routes: NOT CACHED Views: NOT CACHED

Drivers Broadcasting: log Cache: statamic Database: mysql Logs: stack / single Mail: smtp Queue: sync Session: file

Simple Commerce Currencies: CAD, CAD, CAD Gateways: Dummy Repository: Customer: DoubleThreeDigital\SimpleCommerce\Customers\EntryCustomerRepository Repository: Order: DoubleThreeDigital\SimpleCommerce\Orders\EntryOrderRepository Repository: Product: DoubleThreeDigital\SimpleCommerce\Products\EntryProductRepository Shipping Methods: Free Shipping Tax Engine: DoubleThreeDigital\SimpleCommerce\Tax\BasicTaxEngine

Statamic Addons: 2 Antlers: runtime Stache Watcher: Enabled Static Caching: Disabled Version: 4.20.0 PRO

Statamic Addons doublethreedigital/simple-commerce: 5.3.7 manaweb/simple-commerce-plus: dev-simple-commerce-plus

duncanmcclean commented 9 months ago

Inside the cart.antlers.html, in the sc:cart tag, the site variable is not accessible {site:url, site:handle, site:name}

the link to the cart is not generated correctly {{ partial:components/button label="Continue to Checkout" url="{{site:url}}/checkout" }} return only /checkout

Technically, there is a site variable available, it's just a string and is the handle of the site the origin order is in.

You can workaround this though by using the Scope tag:

{{ scope:outside_the_cart }}
    {{ sc:cart }}
        Current site: {{ outside_the_cart:site:handle }}
    {{ /sc:cart }}
{{ /scope:outside_the_cart }}

the product line item and url are from one site, and does not change when changing site, not related to the current site.

This will be happening since the link to the product in the cart will be to the entry in the site you added the product to, not to the localised entry for the site you just changed to.

It would be a lot of work to change the entry that's displayed like you're expecting since there's lots of different places a product is displayed and some people would probably want different product prices to be reflected, etc. It's a lot of work. It would also introduce a breaking change for others who don't want it to work that way.

All that to say.... this probably isn't something I'll change in Simple Commerce, sorry! 😞

You might be able to get clever and do something with firing events / some sort of AJAX request to the backend when the user switches site, then loop through their line items and update each line item so it's using the localised version for that site.

I don't have enough time to code something out, as it'll also depend on your project and how you have things setup but that's what I'd look to do myself.

mathamel commented 9 months ago

Thank you Duncan, I understand your point, time is limited for all.

We will find a workaround. And if possible will share it so others can benefit.

Cheers.