Skip to content

Compare lists of other customers get transferred to current customer upon login-as-customer #40448

@bst-biwac

Description

@bst-biwac

Preconditions and environment

  • Magento version >= 2.4.6
  • 1 website
  • 2 store groups with 4 store views each

Preconditions

  • customer A added products to compare list and has logged out
  • customer B added products to compare list and has logged out
  • customer C added products to compare list and has not yet logged out
  • customer D exists with remote assistance enabled

Steps to reproduce

  1. admin > login-as-customer with customer D
  2. frontend > log out
  3. admin > login-as-customer with customer D

sometimes, step 1. alone suffices for the bug to appear.

Expected result

compare lists for customers A and B stay with customers A and B respectively

Actual result

compare lists of customer A and B get transferred to customer D

Additional information

DB Query debugging results:

  1. upon logout, visitor_id for compare items get set to 0.
  2. login-as-customer has no visitor ID upon login, so it assumes that all compare items with visitor ID 0 belongs to current customer and updates customer_id in compare item table accordingly

this patch seems to fix it

diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Compare/Item.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/C
index ff29a5a..f05f511 100644
--- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Compare/Item.php
+++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Compare/Item.php
@@ -152,7 +152,7 @@ class Item extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
      */
     public function updateCustomerFromVisitor($object)
     {
-        if (!$object->getCustomerId()) {
+        if (!$object->getCustomerId() || !$object->getVisitorId()) {
             return $this;
         }

additionally, sometimes login-as-customer won't work (customer section data error
{"message":"Item (Magento\\Catalog\\Model\\Product\\Interceptor) with the same ID "35910" already exists."}
)
see #40205
#40205

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Ready for Confirmation

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions