Skip to content

Commit 71fbb19

Browse files
committed
ACP2E-4244: Product not being removed from the compare list after the list is assigned to the customer
1 parent 38fb38d commit 71fbb19

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

app/code/Magento/CompareListGraphQl/Model/Service/Customer/SetCustomerToCompareList.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,26 @@ public function execute(int $listId, int $customerId, ContextInterface $context)
9797
$compareList = $this->compareListFactory->create();
9898
$customerListId = $this->getListIdByCustomerId->execute($customerId);
9999
$this->resourceCompareList->load($compareList, $listId, 'list_id');
100+
if (!$compareList->getListId()) {
101+
throw new GraphQlNoSuchEntityException(
102+
__('The compare list with ID "%list_id" does not exist.', ['list_id' => $listId])
103+
);
104+
}
100105
if ($customerListId) {
101106
return $this->mergeCompareLists->execute($listId, $customerListId, $context);
102107
}
103-
$compareList->setCustomerId($customerId);
104-
$this->resourceCompareList->save($compareList);
105-
$this->resourceCompareItem->updateCustomerIdForListItems($listId, $customerId);
108+
109+
$this->resourceCompareList->beginTransaction();
110+
try {
111+
$compareList->setCustomerId($customerId);
112+
$this->resourceCompareList->save($compareList);
113+
$this->resourceCompareItem->updateCustomerIdForListItems($listId, $customerId);
114+
$this->resourceCompareList->commit();
115+
} catch (\Exception $e) {
116+
$this->resourceCompareList->rollBack();
117+
throw $e;
118+
}
119+
106120
return $compareList;
107121
}
108122

0 commit comments

Comments
 (0)