Skip to content

Commit 38fb38d

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

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Catalog\Model\ResourceModel\Product\Compare\CompareList as ResourceCompareList;
1313
use Magento\Catalog\Model\ResourceModel\Product\Compare\Item\CollectionFactory as CompareItemsCollectionFactory;
1414
use Magento\CompareListGraphQl\Model\Service\AddToCompareList;
15+
use Magento\Framework\Exception\LocalizedException;
1516
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
1617

1718
/**
@@ -64,18 +65,33 @@ public function __construct(
6465
* @param int $customerListId
6566
* @param ContextInterface $context
6667
* @return CompareList
68+
* @throws LocalizedException
6769
* @throws \Exception
6870
*/
6971
public function execute(int $guestListId, int $customerListId, ContextInterface $context): CompareList
7072
{
71-
$items = $this->itemCollectionFactory->create();
72-
$products = $items->getProductsByListId($guestListId);
73+
if ($guestListId === $customerListId) {
74+
throw new LocalizedException(__('Cannot merge a list with itself.'));
75+
}
7376

74-
$this->addProductToCompareList->execute($customerListId, $products, $context);
77+
$connection = $this->resourceCompareList->getConnection();
78+
$connection->beginTransaction();
7579

76-
$guestList = $this->compareListFactory->create();
77-
$this->resourceCompareList->load($guestList, $guestListId, 'list_id');
78-
$this->resourceCompareList->delete($guestList);
80+
try {
81+
$items = $this->itemCollectionFactory->create();
82+
$products = $items->getProductsByListId($guestListId);
83+
84+
$this->addProductToCompareList->execute($customerListId, $products, $context);
85+
86+
$guestList = $this->compareListFactory->create();
87+
$this->resourceCompareList->load($guestList, $guestListId, 'list_id');
88+
$this->resourceCompareList->delete($guestList);
89+
90+
$connection->commit();
91+
} catch (\Exception $e) {
92+
$connection->rollBack();
93+
throw $e;
94+
}
7995

8096
$customerList = $this->compareListFactory->create();
8197
$this->resourceCompareList->load($customerList, $customerListId, 'list_id');

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

0 commit comments

Comments
 (0)