In mailchimp_ecommerce/modules/mailchimp_ecommerce_commerce/src/EventSubscriber/CartEventSubscriber.php, we have:
public function cartAdd(CartEntityAddEvent $event) {
/** @var \Drupal\commerce_order\Entity\Order $order */
$order = $event->getCart();
$customer['email_address'] = $order->getEmail();
if (empty($customer['email_address'])) {
// Cannot create or add an item to a cart with no customer email address.
return;
}
Which checks if there is a customer email before doing any cart / order handling. However, there is no check in cartItemUpdate() nor cartItemRemove(). This results in an error when an anonymous shopper views the cart and updates a quantity or removes an item.
Adding:
$customer['email_address'] = $order->getEmail();
if (empty($customer['email_address'])) {
// Cannot create or add an item to a cart with no customer email address.
return;
}
To each function after $order = $event->getCart(); eliminates the error. I'll see if I can create a quick patch.
Comments
Comment #2
scottsawyerquick patch, let's see how this does.
Comment #3
scottsawyerComment #4
dench0I having the same issue, but I'm thinking better to check if cart exist, then existence of the customer e-mail. Because theoretically possible situation when customer e-mail exist, but cart not exist at mailchimp. Attached new patch.
Comment #5
scottsawyer@dench0, seems reasonable to me.
Comment #6
samuel.mortensonThe solution in #4 will now make two API calls when updating or deleting cart items instead of one - are there performance considerations here?
Comment #7
dench0@samuel.mortenson yes, but otherwise it impossible to be sure that cart exist. Need to use #4, or #2 but inside try/catch block. Now it just WSOD on any cart updates, and theoretically for #2 also possible this situation.
Comment #8
travis-bradbury commentedFor performance, it may be better to try updating and handle the special case of the cart not existing only if necessary ("Easier to ask forgiveness than it is to get permission.").
Additionally - and this is probably out of scope of this particular issue - these things should happen after pages have been delivered to the end user so customers aren't waiting on API calls to Mailchimp. See https://glamanate.com/blog/flush-and-run-using-kernelterminate-improve-p..., and https://api.drupal.org/api/drupal/core!lib!Drupal!Core!DestructableInter..., which is what you should use instead of the Kernel::TERMINATE event. DestructableInterface is designed for this.I'll open a separate issue for this request.Comment #9
xenophyle commentedSeems fixed by #3188900: 404 resource not found (when updating amount in cart, WSOD). Reopen if that is not true.