craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
218 stars 170 forks source link

[3.x]: Post request required in product preview #3243

Closed bartdigitalpulse closed 2 months ago

bartdigitalpulse commented 1 year ago

What happened?

Description

When you preview a product and start navigating away from the current page it throws a "Post request required" error. I understand that a preview is mostly for visualizing the current page but a client had some issues with this.

He wanted to test what the effect of his adjustments are on the display of the variants. These work with colors and size combinations. Selecting one influences the display of other options. The selection uses a link to a different variant: https://mysite.be/nl-be/products/my-product?variant=142089 https://mysite.be/nl-be/products/my-product?variant=142088

So to get this working in preview would be really useful.

Link to code: https://github.com/craftcms/commerce/blob/3.4.22.1/src/controllers/ProductsPreviewController.php#L48

Steps to reproduce

  1. Preview a product
  2. Click any link in the preview that navigates away from the current page

Expected behavior

No required post request error

Actual behavior

Post request error

Craft CMS version

3.8.16

Craft Commerce version

3.4.22.1

PHP version

7.4.33

Operating system and version

Linux 5.15.90.1

Database type and version

MySQL 8.0.31

Image driver and version

No response

Installed plugins and versions

Back In Stock 1.4.4 Colour Swatches 1.7.0 Cookies 1.1.15 CP Field Inspect 1.4.4 Craft Commerce 3.4.22.1 Currency Field 1.0.3 Date Range Field 2.5.0 Default Dashboard 1.0.8 Eager Beaver 1.0.5 Element API 2.8.6.1 Elements Panel 1.1.1 Embedded Assets 2.11.4 Enupal Translate 2.3.2 Feed Me 4.7.0 Formulieren 3.13.32 Gift Voucher 2.7.3 Inventory 2.1.1 Knock Knock 1.2.18 Logs 3.0.5 Mailchimp Subscribe 3.1.1.1 Mailchimp Transactional 1.0.3 Maps 3.9.4 Minify 1.2.11 Mollie Payments 2.2.3 Mounteq 1.0.0 MultiSafepay for Craft Commerce 3.0.0 Preparse Field 1.4.1 Reasons 2.3.1 Recently Viewed 1.0.3 Redactor 2.10.12 Redirect Manager 1.1.1 Sentry SDK 1.1.2 SEO 3.4.59 Similar 1.1.5 Sprig 1.13.0 Starfield 1.0.1 Store Hours 2.2.0 Style Inliner 2.5.0 Super Table 2.7.5.1 Template Comments 1.2.0 Twig Profiler 1.0.1 Typed link field 2.0.0-rc.2 Typogrify 1.1.20 Units 1.0.6 Vite 1.0.31 Wishlist 1.4.18

lukeholder commented 2 months ago

As of Craft Commerce 5, previewing variant changes is now possible due to the enhanced product and variant editor UI. (The ProductPreviewController doesn't exist in Craft Commerce 5 now that it is using the core PreviewController)