dotmailer / dotmailer-magento2-extension

The official Dotdigital for Magento2 extension
https://dotdigital.com/integrations/magento
MIT License
48 stars 63 forks source link

Fix abandon cart quote merging issue with configurable products #603

Closed paco-shum closed 1 year ago

paco-shum commented 1 year ago

This is a clean state branch copy for https://github.com/dotmailer/dotmailer-magento2-extension/pull/601

Original Issue:

When an abandoned cart contains configurable items, the original method won't be able to add the parent due to missing selected options on $currentQuote->addProduct($item->getProduct()); See screenshot as example Screenshot 2023-02-09 at 18 59 06

Solution:

Using getAllVisibleItems() instead, and loop through visible items to check for simple products that are contained within a configurable product. This method is borrowed from the merge() function within Quote but slightly simplified to match the original implementation.

Replication steps

  1. on browser A, add a configurable product to cart
  2. then on browser B, add another configurable product to cart
  3. on browser B, access {siteURL}/connector/email/getbasket/quote_id/{the quote created on step 1}/

The assumption

paco-shum commented 1 year ago

Hi @pvpcookie @sta1r here's a clean state branch. Thak you and sorry for the inconvenience.

sta1r commented 1 year ago

Hey @paco-shum - conscious you may be busy. If we don't hear from you by close of play Friday, we'll merge your changes and add our own code per our review. Then we can ship it next week. 👍

paco-shum commented 1 year ago

Hmm, I have tried the following,

  1. on browser A, add a configurable product to cart
  2. then on browser B, in another store, add another configurable product to cart
  3. on browser B, access {siteURL}/connector/email/getbasket/quote_id/{the quote created on step 1}/ Note: both store have the same item available

on this line there is a Quote load function (also should this be loadActive?) https://github.com/dotmailer/dotmailer-magento2-extension/blob/83e74a4c96881c486b58e5f894144477127b5449/Controller/Email/Getbasket.php#L111

so by this line there won't be any quote ID available (null) assuming the quote is not available within the current website so it will just return to the base URL https://github.com/dotmailer/dotmailer-magento2-extension/blob/83e74a4c96881c486b58e5f894144477127b5449/Controller/Email/Getbasket.php#L114

if, still want a check I guess on line 114 can use this instead

if ((!$quoteModel->getId()) || ($quoteModel->getStoreId() !== (int) $websiteId))
sta1r commented 1 year ago

@paco-shum Thanks again for your contribution! Release goes out next week.

sta1r commented 1 year ago

@paco-shum FYI this has been released in v4.20.3: https://github.com/dotmailer/dotmailer-magento2-extension/releases/tag/v4.20.3