From c808611368f7eac91a567058faa82d02df8645b7 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 7 Dec 2023 23:34:33 +0530 Subject: [PATCH 01/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsagesIncrementObserver.php | 46 +++++++++++++++++++ app/code/Magento/SalesRule/etc/di.xml | 3 -- app/code/Magento/SalesRule/etc/events.xml | 3 ++ 3 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php diff --git a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php new file mode 100644 index 0000000000000..c3348ddd0b23e --- /dev/null +++ b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php @@ -0,0 +1,46 @@ +updateCouponUsages = $updateCouponUsages; + } + + /** + * @inheritdoc + */ + public function execute(EventObserver $observer) + { + /** @var CartInterface $quote */ + $quote = $observer->getQuote(); + /* if coupon code has been canceled then need to notify the customer */ + if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) { + throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again.")); + } + $this->updateCouponUsages->execute($quote, true); + } +} diff --git a/app/code/Magento/SalesRule/etc/di.xml b/app/code/Magento/SalesRule/etc/di.xml index daa74d4cafa09..a2eef7c85b56d 100644 --- a/app/code/Magento/SalesRule/etc/di.xml +++ b/app/code/Magento/SalesRule/etc/di.xml @@ -192,9 +192,6 @@ - - - diff --git a/app/code/Magento/SalesRule/etc/events.xml b/app/code/Magento/SalesRule/etc/events.xml index 0b1a0d39cd410..57bd0015f6b6b 100644 --- a/app/code/Magento/SalesRule/etc/events.xml +++ b/app/code/Magento/SalesRule/etc/events.xml @@ -39,4 +39,7 @@ + + + From 1e080667e2cf0a04f5f0b20c65dd43b12d8ced84 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Fri, 8 Dec 2023 17:27:45 +0530 Subject: [PATCH 02/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- app/code/Magento/SalesRule/etc/di.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/SalesRule/etc/di.xml b/app/code/Magento/SalesRule/etc/di.xml index a2eef7c85b56d..abbb599dae9e9 100644 --- a/app/code/Magento/SalesRule/etc/di.xml +++ b/app/code/Magento/SalesRule/etc/di.xml @@ -192,6 +192,9 @@ + + + From 323ac833ed8218cc778ad58237ad4cb2f1019a52 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Fri, 8 Dec 2023 18:14:47 +0530 Subject: [PATCH 03/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../SalesRule/Observer/CouponUsagesIncrementObserver.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php index c3348ddd0b23e..2aa1b237c0666 100644 --- a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php +++ b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php @@ -41,6 +41,7 @@ public function execute(EventObserver $observer) if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) { throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again.")); } - $this->updateCouponUsages->execute($quote, true); + ($observer->getOrder()) ? $this->updateCouponUsages->execute($quote, true) + : $this->updateCouponUsages->execute($quote, false); } } From d8b3fdc779d1a9e68b512668ba818c6dfbbf2fee Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Mon, 11 Dec 2023 18:38:03 +0530 Subject: [PATCH 04/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsagesIncrementObserverTest.php | 88 +++++++++++++++++++ .../SalesRule/Plugin/CouponUsagesTest.php | 49 ----------- 2 files changed, 88 insertions(+), 49 deletions(-) create mode 100644 app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php diff --git a/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php b/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php new file mode 100644 index 0000000000000..d2312ddddcdca --- /dev/null +++ b/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php @@ -0,0 +1,88 @@ +updateCouponUsagesMock = $this->getMockForAbstractClass(UpdateCouponUsages::class); + $this->observerMock = $this->getMockBuilder(Observer::class) + ->addMethods(['getOrder', 'getQuote']) + ->disableOriginalConstructor() + ->getMock(); + $this->quoteMock = $this->getMockBuilder(Quote::class) + ->addMethods(['getCouponCode']) + ->onlyMethods(['dataHasChangedFor']) + ->disableOriginalConstructor() + ->getMock(); + $this->updateCouponUsagesMock = $this->getMockBuilder(UpdateCouponUsages::class) + ->disableOriginalConstructor() + ->setMethods(['execute']) + ->getMock(); + $this->couponUsagesIncrementObserver = new CouponUsagesIncrementObserver( + $this->updateCouponUsagesMock + ); + } + + /** + * Testing the quote that doesn't have a coupon code set + */ + public function testQuoteWithNoCouponCode() + { + $couponCode = 'coupon code'; + $this->observerMock->expects($this->once())->method('getQuote') + ->willReturn($this->quoteMock); + $this->quoteMock->expects($this->once())->method('getCouponCode') + ->willReturn(true); + $this->quoteMock->expects($this->once()) + ->method('getCouponCode') + ->willReturn($couponCode); + $this->quoteMock->expects($this->any()) + ->method('dataHasChangedFor') + ->with('coupon_code') + ->willReturn(true); + $this->observerMock->expects($this->once())->method('getOrder') + ->willReturn($this->quoteMock); + $this->updateCouponUsagesMock + ->expects($this->once()) + ->method('execute'); + $this->couponUsagesIncrementObserver->execute($this->observerMock); + // $this->updateCouponUsagesMock->execute($this->observerMock); + } +} diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php index 791db5516c57a..3afd701a690db 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php @@ -107,55 +107,6 @@ protected function tearDown(): void parent::tearDown(); } - /** - * Test increasing coupon usages after after order placing and decreasing after order cancellation. - * - * @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php - * @magentoDbIsolation disabled - */ - public function testSubmitQuoteAndCancelOrder() - { - $customerId = 1; - $couponCode = 'one_usage'; - $reservedOrderId = 'test01'; - - /** @var Coupon $coupon */ - $coupon = $this->objectManager->create(Coupon::class); - $coupon->loadByCode($couponCode); - /** @var Quote $quote */ - $quote = $this->objectManager->create(Quote::class); - $quote->load($reservedOrderId, 'reserved_order_id'); - - // Make sure coupon usages value is incremented then order is placed. - $order = $this->quoteManagement->submit($quote); - sleep(30); // timeout to processing Magento queue - $this->usage->loadByCustomerCoupon($this->couponUsage, $customerId, $coupon->getId()); - $coupon->loadByCode($couponCode); - - self::assertEquals( - 1, - $coupon->getTimesUsed() - ); - self::assertEquals( - 1, - $this->couponUsage->getTimesUsed() - ); - - // Make sure order coupon usages value is decremented then order is cancelled. - $this->orderService->cancel($order->getId()); - $this->usage->loadByCustomerCoupon($this->couponUsage, $customerId, $coupon->getId()); - $coupon->loadByCode($couponCode); - - self::assertEquals( - 0, - $coupon->getTimesUsed() - ); - self::assertEquals( - 0, - $this->couponUsage->getTimesUsed() - ); - } - /** * Test to decrement coupon usages after exception on order placing * From 9e89d3f46e4bf989ae71a2513b2b38d71d416545 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Fri, 15 Dec 2023 17:24:32 +0530 Subject: [PATCH 05/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsagesIncrementObserver.php | 17 +++++-- .../CouponUsagesIncrementObserverTest.php | 17 +++++-- .../SalesRule/Plugin/CouponUsagesTest.php | 49 +++++++++++++++++++ 3 files changed, 77 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php index 2aa1b237c0666..e9e5f10960d55 100644 --- a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php +++ b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php @@ -1,7 +1,18 @@ objectManager->create(Coupon::class); + $coupon->loadByCode($couponCode); + /** @var Quote $quote */ + $quote = $this->objectManager->create(Quote::class); + $quote->load($reservedOrderId, 'reserved_order_id'); + + // Make sure coupon usages value is incremented then order is placed. + $order = $this->quoteManagement->submit($quote); + sleep(30); // timeout to processing Magento queue + $this->usage->loadByCustomerCoupon($this->couponUsage, $customerId, $coupon->getId()); + $coupon->loadByCode($couponCode); + + self::assertEquals( + 1, + $coupon->getTimesUsed() + ); + self::assertEquals( + 1, + $this->couponUsage->getTimesUsed() + ); + + // Make sure order coupon usages value is decremented then order is cancelled. + $this->orderService->cancel($order->getId()); + $this->usage->loadByCustomerCoupon($this->couponUsage, $customerId, $coupon->getId()); + $coupon->loadByCode($couponCode); + + self::assertEquals( + 0, + $coupon->getTimesUsed() + ); + self::assertEquals( + 0, + $this->couponUsage->getTimesUsed() + ); + } + /** * Test to decrement coupon usages after exception on order placing * From 17769c1dcd1d1ff4cd73fe88592e60a0caf7ec4d Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 21 Dec 2023 10:41:58 +0530 Subject: [PATCH 06/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- app/code/Magento/Quote/Model/QuoteManagement.php | 7 +++++-- .../SalesRule/Observer/CouponUsagesIncrementObserver.php | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index aada741982682..f30325f894561 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -470,7 +470,6 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) $this->checkoutSession->setLastRealOrderId($order->getIncrementId()); $this->checkoutSession->setLastOrderStatus($order->getStatus()); - $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]); return $order->getId(); } @@ -498,7 +497,11 @@ public function submit(QuoteEntity $quote, $orderData = []) return null; } - return $this->submitQuote($quote, $orderData); + $order = $this->submitQuote($quote, $orderData); + if (null != $order) { + $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]); + } + return $order; } /** diff --git a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php index e9e5f10960d55..ef40e75151402 100644 --- a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php +++ b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php @@ -20,7 +20,6 @@ use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; -use Magento\Framework\Exception\NoSuchEntityException; use Magento\SalesRule\Model\Coupon\Quote\UpdateCouponUsages; /** @@ -52,7 +51,7 @@ public function execute(EventObserver $observer) if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) { throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again.")); } - ($observer->getOrder()) ? $this->updateCouponUsages->execute($quote, true) + ($observer->getOrder() || $observer->getOrders()) ? $this->updateCouponUsages->execute($quote, true) : $this->updateCouponUsages->execute($quote, false); } } From f33f34388bde52622aa1ee54371127a94223e10c Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Sat, 23 Dec 2023 00:23:31 +0530 Subject: [PATCH 07/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsagesIncrementObserver.php | 8 +++-- .../CouponUsagesIncrementObserverTest.php | 1 - .../Model/Coupon/UpdateCouponUsagesTest.php | 32 +++++++++++++++++++ .../SalesRule/Plugin/CouponUsagesTest.php | 14 ++++---- 4 files changed, 46 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php index ef40e75151402..199ba7d78ff2a 100644 --- a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php +++ b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php @@ -21,6 +21,7 @@ use Magento\Framework\Event\Observer as EventObserver; use Magento\Framework\Event\ObserverInterface; use Magento\SalesRule\Model\Coupon\Quote\UpdateCouponUsages; +use Magento\Framework\Exception\NoSuchEntityException; /** * Decrement number of coupon usages after error of placing order @@ -41,11 +42,14 @@ public function __construct(UpdateCouponUsages $updateCouponUsages) } /** - * @inheritdoc + * Increments number of coupon usages after placing order + * + * @param EventObserver $observer + * @return void + * @throws NoSuchEntityException */ public function execute(EventObserver $observer) { - /** @var CartInterface $quote */ $quote = $observer->getQuote(); /* if coupon code has been canceled then need to notify the customer */ if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) { diff --git a/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php b/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php index 37f7d666d5da3..acda029b13958 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php @@ -94,6 +94,5 @@ public function testQuoteWithNoCouponCode() ->expects($this->once()) ->method('execute'); $this->couponUsagesIncrementObserver->execute($this->observerMock); - // $this->updateCouponUsagesMock->execute($this->observerMock); } } diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php index 777959d2df8c1..820555e22272d 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php @@ -22,6 +22,7 @@ use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethod; use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddress; use Magento\Customer\Test\Fixture\Customer; +use Magento\Framework\DataObject; use Magento\Framework\MessageQueue\ConsumerFactory; use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Api\CartRepositoryInterface; @@ -30,12 +31,14 @@ use Magento\Quote\Test\Fixture\CustomerCart; use Magento\Quote\Test\Fixture\GuestCart; use Magento\Sales\Api\OrderManagementInterface; +use Magento\SalesRule\Model\ResourceModel\Coupon\Usage; use Magento\SalesRule\Test\Fixture\Rule as SalesRuleFixture; use Magento\TestFramework\Fixture\DataFixture; use Magento\TestFramework\Fixture\DataFixtureStorage; use Magento\TestFramework\Fixture\DataFixtureStorageManager; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\MessageQueue\ClearQueueProcessor; +use Magento\SalesRule\Model\Coupon; use PHPUnit\Framework\TestCase; class UpdateCouponUsagesTest extends TestCase @@ -70,6 +73,16 @@ class UpdateCouponUsagesTest extends TestCase */ private $consumerFactory; + /** + * @var DataObject + */ + private $couponUsage; + + /** + * @var Coupon + */ + private $coupon; + protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); @@ -83,6 +96,9 @@ protected function setUp(): void $this->cartRepository = $objectManager->get(CartRepositoryInterface::class); $this->orderManagement = $objectManager->get(OrderManagementInterface::class); $this->consumerFactory = $objectManager->get(ConsumerFactory::class); + $this->usage = $objectManager->get(Usage::class); + $this->coupon = $objectManager->get(Coupon::class); + $this->couponUsage = $objectManager->create(DataObject::class); } #[ @@ -111,8 +127,19 @@ public function testCancelOrderBeforeUsageConsumerExecution(): void { $cart = $this->fixtures->get('cart1'); $this->couponManagement->set($cart->getId(), 'one_per_customer'); + $this->coupon->loadByCode('one_per_customer'); $orderId = $this->cartManagement->placeOrder($cart->getId()); + $this->usage->loadByCustomerCoupon($this->couponUsage, $cart->getCustomerId(), $this->coupon->getId()); + self::assertEquals( + 1, + $this->couponUsage->getTimesUsed() + ); $this->orderManagement->cancel($orderId); + $this->usage->loadByCustomerCoupon($this->couponUsage, $cart->getCustomerId(), $this->coupon->getId()); + self::assertEquals( + 0, + $this->couponUsage->getTimesUsed() + ); $consumer = $this->consumerFactory->get('sales.rule.update.coupon.usage'); $consumer->process(1); @@ -122,6 +149,11 @@ public function testCancelOrderBeforeUsageConsumerExecution(): void $cart = $this->cartRepository->get($cart->getId()); $this->couponManagement->set($cart->getId(), 'one_per_customer'); $this->cartManagement->placeOrder($cart->getId()); + $this->usage->loadByCustomerCoupon($this->couponUsage, $cart->getCustomerId(), $this->coupon->getId()); + self::assertEquals( + 1, + $this->couponUsage->getTimesUsed() + ); $consumer->process(1); } } diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php index e95f2b7ac08cc..9f95d6d28d059 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php @@ -20,6 +20,7 @@ use Magento\TestFramework\MessageQueue\PublisherConsumerController; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use tests\verification\Tests\SkippedGenerationTest; /** * Test increasing coupon usages after order placing and decreasing after order cancellation. @@ -107,14 +108,15 @@ protected function tearDown(): void parent::tearDown(); } - /** - * Test increasing coupon usages after after order placing and decreasing after order cancellation. - * - * @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php - * @magentoDbIsolation disabled - */ + /** + * Test increasing coupon usages after after order placing and decreasing after order cancellation. + * + * @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php + * @magentoDbIsolation disabled + */ public function testSubmitQuoteAndCancelOrder() { + $this->markTestSkipped('Skipped due to the disabled coupon_uses_increment_plugin in ACP2E-2519.'); $customerId = 1; $couponCode = 'one_usage'; $reservedOrderId = 'test01'; From 5fdfbf02f79ff838f0b0002f78c2ff1fa7155b95 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Sat, 23 Dec 2023 00:50:47 +0530 Subject: [PATCH 08/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- app/code/Magento/Quote/Model/QuoteManagement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index f30325f894561..2b199ef0b1330 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -497,7 +497,7 @@ public function submit(QuoteEntity $quote, $orderData = []) return null; } - $order = $this->submitQuote($quote, $orderData); + $order = $this->submitQuote($quote, $orderData); if (null != $order) { $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]); } From a82dc4545d89fd88d8dd4a7c9ab263b680f937db Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Sat, 23 Dec 2023 01:52:21 +0530 Subject: [PATCH 09/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../SalesRule/Model/Coupon/UpdateCouponUsagesTest.php | 5 +++++ .../Magento/SalesRule/Plugin/CouponUsagesTest.php | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php index 820555e22272d..9084d23d72a1d 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php @@ -83,6 +83,11 @@ class UpdateCouponUsagesTest extends TestCase */ private $coupon; + /** + * @var Usage + */ + private $usage; + protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php index 9f95d6d28d059..20ebd31876bfa 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php @@ -109,11 +109,11 @@ protected function tearDown(): void } /** - * Test increasing coupon usages after after order placing and decreasing after order cancellation. - * - * @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php - * @magentoDbIsolation disabled - */ + * Test increasing coupon usages after after order placing and decreasing after order cancellation. + * + * @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php + * @magentoDbIsolation disabled + */ public function testSubmitQuoteAndCancelOrder() { $this->markTestSkipped('Skipped due to the disabled coupon_uses_increment_plugin in ACP2E-2519.'); From 3e649f7e064e1f387e2b7c4044a209dd902ffcdc Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 4 Jan 2024 17:53:35 +0530 Subject: [PATCH 10/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../Magento/Quote/Model/QuoteManagement.php | 8 +-- .../CouponUsagesIncrementObserver.php | 61 ------------------- app/code/Magento/SalesRule/composer.json | 3 +- app/code/Magento/SalesRule/etc/di.xml | 5 +- app/code/Magento/SalesRule/etc/events.xml | 3 - 5 files changed, 8 insertions(+), 72 deletions(-) delete mode 100644 app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 2b199ef0b1330..1fa13a13dfd9d 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -470,6 +470,7 @@ public function placeOrder($cartId, PaymentInterface $paymentMethod = null) $this->checkoutSession->setLastRealOrderId($order->getIncrementId()); $this->checkoutSession->setLastOrderStatus($order->getStatus()); + $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]); return $order->getId(); } @@ -496,12 +497,7 @@ public function submit(QuoteEntity $quote, $orderData = []) $quote->setIsActive(false); return null; } - - $order = $this->submitQuote($quote, $orderData); - if (null != $order) { - $this->eventManager->dispatch('checkout_submit_all_after', ['order' => $order, 'quote' => $quote]); - } - return $order; + return $this->submitQuote($quote, $orderData);; } /** diff --git a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php b/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php deleted file mode 100644 index 199ba7d78ff2a..0000000000000 --- a/app/code/Magento/SalesRule/Observer/CouponUsagesIncrementObserver.php +++ /dev/null @@ -1,61 +0,0 @@ -updateCouponUsages = $updateCouponUsages; - } - - /** - * Increments number of coupon usages after placing order - * - * @param EventObserver $observer - * @return void - * @throws NoSuchEntityException - */ - public function execute(EventObserver $observer) - { - $quote = $observer->getQuote(); - /* if coupon code has been canceled then need to notify the customer */ - if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) { - throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again.")); - } - ($observer->getOrder() || $observer->getOrders()) ? $this->updateCouponUsages->execute($quote, true) - : $this->updateCouponUsages->execute($quote, false); - } -} diff --git a/app/code/Magento/SalesRule/composer.json b/app/code/Magento/SalesRule/composer.json index 89fd6cb64b89b..e1337ee0ca3aa 100644 --- a/app/code/Magento/SalesRule/composer.json +++ b/app/code/Magento/SalesRule/composer.json @@ -30,7 +30,8 @@ "magento/module-asynchronous-operations": "*" }, "suggest": { - "magento/module-sales-rule-sample-data": "*" + "magento/module-sales-rule-sample-data": "*", + "magento/module-multishipping": "*" }, "type": "magento2-module", "license": [ diff --git a/app/code/Magento/SalesRule/etc/di.xml b/app/code/Magento/SalesRule/etc/di.xml index abbb599dae9e9..ad446378acd6d 100644 --- a/app/code/Magento/SalesRule/etc/di.xml +++ b/app/code/Magento/SalesRule/etc/di.xml @@ -193,7 +193,10 @@ - + + + + - - - From a18117c8409e3984167e7fb149132f6b73c76b0a Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 4 Jan 2024 17:54:59 +0530 Subject: [PATCH 11/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsagesIncrementMultishipping.php | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php diff --git a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php new file mode 100644 index 0000000000000..28120674ba93e --- /dev/null +++ b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php @@ -0,0 +1,72 @@ +updateCouponUsages = $updateCouponUsages; + $this->quoteRepository = $quoteRepository; + } + + /** + * Increments number of coupon usages before placing order + * + * @param PlaceOrderDefault $subject + * @param \Closure $proceed + * @param array $order + * @return void + * @throws NoSuchEntityException + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function aroundPlace(PlaceOrderDefault $subject, \Closure $proceed, array $order) + { + $quoteId = $order[0]->getQuoteId(); + $quote = $this->quoteRepository->get($quoteId); + /* if coupon code has been canceled then need to notify the customer */ + if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) { + throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again.")); + } + + $this->updateCouponUsages->execute($quote, true); + try { + return $proceed($order); + } catch (\Throwable $e) { + $this->updateCouponUsages->execute($quote, false); + throw $e; + } + } +} From e8678f868c69d4b020be3c1a649ee4c1f62299d7 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 4 Jan 2024 17:56:29 +0530 Subject: [PATCH 12/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- app/code/Magento/Quote/Model/QuoteManagement.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 1fa13a13dfd9d..6ed4650a72bea 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -497,7 +497,8 @@ public function submit(QuoteEntity $quote, $orderData = []) $quote->setIsActive(false); return null; } - return $this->submitQuote($quote, $orderData);; + + return $this->submitQuote($quote, $orderData); } /** From fd174327a97f7788fcd2573f27396e0d856f653c Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 4 Jan 2024 17:58:10 +0530 Subject: [PATCH 13/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- app/code/Magento/Quote/Model/QuoteManagement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 6ed4650a72bea..aada741982682 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -497,7 +497,7 @@ public function submit(QuoteEntity $quote, $orderData = []) $quote->setIsActive(false); return null; } - + return $this->submitQuote($quote, $orderData); } From 16ae66db551d63f660fe44e0856ee0cdf325061a Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 4 Jan 2024 17:59:19 +0530 Subject: [PATCH 14/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsagesIncrementObserverTest.php | 98 ------------------- 1 file changed, 98 deletions(-) delete mode 100644 app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php diff --git a/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php b/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php deleted file mode 100644 index acda029b13958..0000000000000 --- a/app/code/Magento/SalesRule/Test/Unit/Observer/CouponUsagesIncrementObserverTest.php +++ /dev/null @@ -1,98 +0,0 @@ -updateCouponUsagesMock = $this->getMockForAbstractClass(UpdateCouponUsages::class); - $this->observerMock = $this->getMockBuilder(Observer::class) - ->addMethods(['getOrder', 'getQuote']) - ->disableOriginalConstructor() - ->getMock(); - $this->quoteMock = $this->getMockBuilder(Quote::class) - ->addMethods(['getCouponCode']) - ->onlyMethods(['dataHasChangedFor']) - ->disableOriginalConstructor() - ->getMock(); - $this->updateCouponUsagesMock = $this->getMockBuilder(UpdateCouponUsages::class) - ->disableOriginalConstructor() - ->setMethods(['execute']) - ->getMock(); - $this->couponUsagesIncrementObserver = new CouponUsagesIncrementObserver( - $this->updateCouponUsagesMock - ); - } - - /** - * Testing the quote that doesn't have a coupon code set - */ - public function testQuoteWithNoCouponCode() - { - $couponCode = 'coupon code'; - $this->observerMock->expects($this->once())->method('getQuote') - ->willReturn($this->quoteMock); - $this->quoteMock->expects($this->once())->method('getCouponCode') - ->willReturn(true); - $this->quoteMock->expects($this->once()) - ->method('getCouponCode') - ->willReturn($couponCode); - $this->quoteMock->expects($this->any()) - ->method('dataHasChangedFor') - ->with('coupon_code') - ->willReturn(true); - $this->observerMock->expects($this->once())->method('getOrder') - ->willReturn($this->quoteMock); - $this->updateCouponUsagesMock - ->expects($this->once()) - ->method('execute'); - $this->couponUsagesIncrementObserver->execute($this->observerMock); - } -} From 644d14f7fdb3e1c98b6e74070722df4e093d2b53 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 4 Jan 2024 18:03:16 +0530 Subject: [PATCH 15/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php index 20ebd31876bfa..52c2a0dac8d54 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php @@ -20,7 +20,6 @@ use Magento\TestFramework\MessageQueue\PublisherConsumerController; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use tests\verification\Tests\SkippedGenerationTest; /** * Test increasing coupon usages after order placing and decreasing after order cancellation. @@ -116,7 +115,6 @@ protected function tearDown(): void */ public function testSubmitQuoteAndCancelOrder() { - $this->markTestSkipped('Skipped due to the disabled coupon_uses_increment_plugin in ACP2E-2519.'); $customerId = 1; $couponCode = 'one_usage'; $reservedOrderId = 'test01'; From 02c6a2430c095ac5e49f15b03d659bc3ae2e6d9b Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Fri, 5 Jan 2024 12:42:17 +0530 Subject: [PATCH 16/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../Model/Coupon/UpdateCouponUsagesTest.php | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php index 9084d23d72a1d..777959d2df8c1 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Model/Coupon/UpdateCouponUsagesTest.php @@ -22,7 +22,6 @@ use Magento\Checkout\Test\Fixture\SetPaymentMethod as SetPaymentMethod; use Magento\Checkout\Test\Fixture\SetShippingAddress as SetShippingAddress; use Magento\Customer\Test\Fixture\Customer; -use Magento\Framework\DataObject; use Magento\Framework\MessageQueue\ConsumerFactory; use Magento\Quote\Api\CartManagementInterface; use Magento\Quote\Api\CartRepositoryInterface; @@ -31,14 +30,12 @@ use Magento\Quote\Test\Fixture\CustomerCart; use Magento\Quote\Test\Fixture\GuestCart; use Magento\Sales\Api\OrderManagementInterface; -use Magento\SalesRule\Model\ResourceModel\Coupon\Usage; use Magento\SalesRule\Test\Fixture\Rule as SalesRuleFixture; use Magento\TestFramework\Fixture\DataFixture; use Magento\TestFramework\Fixture\DataFixtureStorage; use Magento\TestFramework\Fixture\DataFixtureStorageManager; use Magento\TestFramework\Helper\Bootstrap; use Magento\TestFramework\MessageQueue\ClearQueueProcessor; -use Magento\SalesRule\Model\Coupon; use PHPUnit\Framework\TestCase; class UpdateCouponUsagesTest extends TestCase @@ -73,21 +70,6 @@ class UpdateCouponUsagesTest extends TestCase */ private $consumerFactory; - /** - * @var DataObject - */ - private $couponUsage; - - /** - * @var Coupon - */ - private $coupon; - - /** - * @var Usage - */ - private $usage; - protected function setUp(): void { $objectManager = Bootstrap::getObjectManager(); @@ -101,9 +83,6 @@ protected function setUp(): void $this->cartRepository = $objectManager->get(CartRepositoryInterface::class); $this->orderManagement = $objectManager->get(OrderManagementInterface::class); $this->consumerFactory = $objectManager->get(ConsumerFactory::class); - $this->usage = $objectManager->get(Usage::class); - $this->coupon = $objectManager->get(Coupon::class); - $this->couponUsage = $objectManager->create(DataObject::class); } #[ @@ -132,19 +111,8 @@ public function testCancelOrderBeforeUsageConsumerExecution(): void { $cart = $this->fixtures->get('cart1'); $this->couponManagement->set($cart->getId(), 'one_per_customer'); - $this->coupon->loadByCode('one_per_customer'); $orderId = $this->cartManagement->placeOrder($cart->getId()); - $this->usage->loadByCustomerCoupon($this->couponUsage, $cart->getCustomerId(), $this->coupon->getId()); - self::assertEquals( - 1, - $this->couponUsage->getTimesUsed() - ); $this->orderManagement->cancel($orderId); - $this->usage->loadByCustomerCoupon($this->couponUsage, $cart->getCustomerId(), $this->coupon->getId()); - self::assertEquals( - 0, - $this->couponUsage->getTimesUsed() - ); $consumer = $this->consumerFactory->get('sales.rule.update.coupon.usage'); $consumer->process(1); @@ -154,11 +122,6 @@ public function testCancelOrderBeforeUsageConsumerExecution(): void $cart = $this->cartRepository->get($cart->getId()); $this->couponManagement->set($cart->getId(), 'one_per_customer'); $this->cartManagement->placeOrder($cart->getId()); - $this->usage->loadByCustomerCoupon($this->couponUsage, $cart->getCustomerId(), $this->coupon->getId()); - self::assertEquals( - 1, - $this->couponUsage->getTimesUsed() - ); $consumer->process(1); } } From 730c97c22af84ffdb3970ae6b70da2f235c3c7b6 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Fri, 5 Jan 2024 17:35:24 +0530 Subject: [PATCH 17/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- app/code/Magento/SalesRule/composer.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/SalesRule/composer.json b/app/code/Magento/SalesRule/composer.json index e1337ee0ca3aa..79832f894d28c 100644 --- a/app/code/Magento/SalesRule/composer.json +++ b/app/code/Magento/SalesRule/composer.json @@ -27,11 +27,11 @@ "magento/module-captcha": "*", "magento/module-checkout": "*", "magento/module-authorization": "*", - "magento/module-asynchronous-operations": "*" + "magento/module-asynchronous-operations": "*", + "magento/module-multishipping": "*" }, "suggest": { - "magento/module-sales-rule-sample-data": "*", - "magento/module-multishipping": "*" + "magento/module-sales-rule-sample-data": "*" }, "type": "magento2-module", "license": [ From 9b8dfb9ca0b662fb0d6f226560497c7638c50560 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Mon, 8 Jan 2024 22:43:39 +0530 Subject: [PATCH 18/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../SalesRule/Plugin/CouponUsagesIncrementMultishipping.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php index 28120674ba93e..47e44d3c9cd54 100644 --- a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php +++ b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php @@ -8,13 +8,9 @@ namespace Magento\SalesRule\Plugin; use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; -use Magento\Sales\Api\Data\OrderInterface; -use Magento\Sales\Model\Service\OrderService; use Magento\SalesRule\Model\Coupon\Quote\UpdateCouponUsages; use Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderDefault; -use Magento\Sales\Api\OrderManagementInterface; /** * Increments number of coupon usages before placing order From 9b5ec83a12a46a4c899781eaf787500c349b0a7e Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Sun, 14 Jan 2024 17:56:16 +0530 Subject: [PATCH 19/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- ...CouponUsagesIncrementMultishippingTest.php | 135 ++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishippingTest.php diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishippingTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishippingTest.php new file mode 100644 index 0000000000000..56afb06368829 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishippingTest.php @@ -0,0 +1,135 @@ +get(ClearQueueProcessor::class); + $clearQueueProcessor->execute('sales.rule.update.coupon.usage'); + + $this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage(); + $this->couponManagement = $objectManager->get(CouponManagementInterface::class); + $this->cartManagement = $objectManager->get(CartManagementInterface::class); + $this->cartRepository = $objectManager->get(CartRepositoryInterface::class); + $this->orderManagement = $objectManager->get(OrderManagementInterface::class); + $this->consumerFactory = $objectManager->get(ConsumerFactory::class); + $this->multishipping = $objectManager->get(Multishipping::class); + + } + + #[ + DataFixture(ProductFixture::class, as: 'p1'), + DataFixture( + SalesRuleFixture::class, + ['coupon_code' => 'one_per_customer', 'uses_per_customer' => 1, 'discount_amount' => 10] + ), + DataFixture(Customer::class, as: 'customer'), + + DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], 'cart1'), + DataFixture(AddProductToCart::class, ['cart_id' => '$cart1.id$', 'product_id' => '$p1.id$']), + DataFixture(SetBillingAddress::class, ['cart_id' => '$cart1.id$']), + DataFixture(SetShippingAddress::class, ['cart_id' => '$cart1.id$']), + DataFixture(SetDeliveryMethod::class, ['cart_id' => '$cart1.id$']), + DataFixture(SetPaymentMethod::class, ['cart_id' => '$cart1.id$']), + + DataFixture(GuestCart::class, as: 'cart2'), + DataFixture(AddProductToCart::class, ['cart_id' => '$cart2.id$', 'product_id' => '$p1.id$']), + DataFixture(SetBillingAddress::class, ['cart_id' => '$cart2.id$']), + DataFixture(SetShippingAddress::class, ['cart_id' => '$cart2.id$']), + DataFixture(SetDeliveryMethod::class, ['cart_id' => '$cart2.id$']), + DataFixture(SetPaymentMethod::class, ['cart_id' => '$cart2.id$']), + ] + public function testCancelOrderBeforeUsageConsumerExecution(): void + { + $cart = $this->fixtures->get('cart1'); + $this->couponManagement->set($cart->getId(), 'one_per_customer'); + $orderId = $this->multishipping->createOrders(); + $this->orderManagement->cancel($orderId); + $consumer = $this->consumerFactory->get('sales.rule.update.coupon.usage'); + $consumer->process(1); + + $cart = $this->fixtures->get('cart2'); + $customer = $this->fixtures->get('customer'); + $this->cartManagement->assignCustomer($cart->getId(), $customer->getId(), 1); + $cart = $this->cartRepository->get($cart->getId()); + $this->couponManagement->set($cart->getId(), 'one_per_customer'); + $this->cartManagement->placeOrder($cart->getId()); + $consumer->process(1); + } +} From 6b5effc4841d01689dce8a4eb065cb5e80afdc5a Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Sun, 14 Jan 2024 18:01:05 +0530 Subject: [PATCH 20/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- ...ponUsageIncreamentForMultishippingTest.php | 104 ++++++++++++++ ...CouponUsagesIncrementMultishippingTest.php | 135 ------------------ 2 files changed, 104 insertions(+), 135 deletions(-) create mode 100644 app/code/Magento/SalesRule/Test/Unit/plugin/CouponUsageIncreamentForMultishippingTest.php delete mode 100644 dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishippingTest.php diff --git a/app/code/Magento/SalesRule/Test/Unit/plugin/CouponUsageIncreamentForMultishippingTest.php b/app/code/Magento/SalesRule/Test/Unit/plugin/CouponUsageIncreamentForMultishippingTest.php new file mode 100644 index 0000000000000..d187221757216 --- /dev/null +++ b/app/code/Magento/SalesRule/Test/Unit/plugin/CouponUsageIncreamentForMultishippingTest.php @@ -0,0 +1,104 @@ +objectManagerHelper = new ObjectManagerHelper($this); + $this->subjectMock = $this->getMockBuilder(PlaceOrderDefault::class) + ->disableOriginalConstructor() + ->getMock(); + $this->updateCouponUsagesMock = $this->getMockBuilder(UpdateCouponUsages::class) + ->disableOriginalConstructor() + ->onlyMethods(['execute']) + ->getMock(); + $this->quoteRepositoryMock = $this->getMockBuilder(QuoteRepository::class) + ->disableOriginalConstructor() + ->getMock(); + $this->orderMock = $this->getMockBuilder(Order::class) + ->onlyMethods(['getQuoteId']) + ->disableOriginalConstructor() + ->getMock(); + $this->plugin = $this->objectManagerHelper->getObject( + CouponUsagesIncrementMultishipping::class, + [ + 'updateCouponUsages' => $this->updateCouponUsagesMock, + 'quoteRepository' => $this->quoteRepositoryMock + ] + ); + } + /** + * Testing Increments number of coupon usages before placing order + */ + public function testAroundPlace() + { + $couponCode = 'coupon code'; + $proceed = function ($orderMock) { + return $orderMock; + }; + /** @var Quote|MockObject $quote */ + $quoteMock = $this->getMockBuilder(Quote::class) + ->disableOriginalConstructor() + ->addMethods(['getCouponCode']) + ->onlyMethods(['dataHasChangedFor']) + ->getMock(); + $this->orderMock->expects($this->once())->method('getQuoteId') + ->willReturn(1); + + $this->quoteRepositoryMock->expects($this->once())->method('get')->with(1)->willReturn($quoteMock); + $quoteMock->expects($this->once())->method('getCouponCode')->willReturn($couponCode); + $quoteMock->expects($this->any())->method('dataHasChangedFor')->with($couponCode)->willReturn(true); + $this->updateCouponUsagesMock + ->expects($this->once()) + ->method('execute'); + $this->assertSame( + [$this->orderMock], + $this->plugin->aroundPlace($this->subjectMock, $proceed, [$this->orderMock]) + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishippingTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishippingTest.php deleted file mode 100644 index 56afb06368829..0000000000000 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishippingTest.php +++ /dev/null @@ -1,135 +0,0 @@ -get(ClearQueueProcessor::class); - $clearQueueProcessor->execute('sales.rule.update.coupon.usage'); - - $this->fixtures = $objectManager->get(DataFixtureStorageManager::class)->getStorage(); - $this->couponManagement = $objectManager->get(CouponManagementInterface::class); - $this->cartManagement = $objectManager->get(CartManagementInterface::class); - $this->cartRepository = $objectManager->get(CartRepositoryInterface::class); - $this->orderManagement = $objectManager->get(OrderManagementInterface::class); - $this->consumerFactory = $objectManager->get(ConsumerFactory::class); - $this->multishipping = $objectManager->get(Multishipping::class); - - } - - #[ - DataFixture(ProductFixture::class, as: 'p1'), - DataFixture( - SalesRuleFixture::class, - ['coupon_code' => 'one_per_customer', 'uses_per_customer' => 1, 'discount_amount' => 10] - ), - DataFixture(Customer::class, as: 'customer'), - - DataFixture(CustomerCart::class, ['customer_id' => '$customer.id$'], 'cart1'), - DataFixture(AddProductToCart::class, ['cart_id' => '$cart1.id$', 'product_id' => '$p1.id$']), - DataFixture(SetBillingAddress::class, ['cart_id' => '$cart1.id$']), - DataFixture(SetShippingAddress::class, ['cart_id' => '$cart1.id$']), - DataFixture(SetDeliveryMethod::class, ['cart_id' => '$cart1.id$']), - DataFixture(SetPaymentMethod::class, ['cart_id' => '$cart1.id$']), - - DataFixture(GuestCart::class, as: 'cart2'), - DataFixture(AddProductToCart::class, ['cart_id' => '$cart2.id$', 'product_id' => '$p1.id$']), - DataFixture(SetBillingAddress::class, ['cart_id' => '$cart2.id$']), - DataFixture(SetShippingAddress::class, ['cart_id' => '$cart2.id$']), - DataFixture(SetDeliveryMethod::class, ['cart_id' => '$cart2.id$']), - DataFixture(SetPaymentMethod::class, ['cart_id' => '$cart2.id$']), - ] - public function testCancelOrderBeforeUsageConsumerExecution(): void - { - $cart = $this->fixtures->get('cart1'); - $this->couponManagement->set($cart->getId(), 'one_per_customer'); - $orderId = $this->multishipping->createOrders(); - $this->orderManagement->cancel($orderId); - $consumer = $this->consumerFactory->get('sales.rule.update.coupon.usage'); - $consumer->process(1); - - $cart = $this->fixtures->get('cart2'); - $customer = $this->fixtures->get('customer'); - $this->cartManagement->assignCustomer($cart->getId(), $customer->getId(), 1); - $cart = $this->cartRepository->get($cart->getId()); - $this->couponManagement->set($cart->getId(), 'one_per_customer'); - $this->cartManagement->placeOrder($cart->getId()); - $consumer->process(1); - } -} From b01c01e4df07a3627fbf41e75d2b566106503990 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Sun, 14 Jan 2024 18:04:32 +0530 Subject: [PATCH 21/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../Magento/SalesRule/Plugin/CouponUsagesTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php index 52c2a0dac8d54..791db5516c57a 100644 --- a/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php +++ b/dev/tests/integration/testsuite/Magento/SalesRule/Plugin/CouponUsagesTest.php @@ -107,12 +107,12 @@ protected function tearDown(): void parent::tearDown(); } - /** - * Test increasing coupon usages after after order placing and decreasing after order cancellation. - * - * @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php - * @magentoDbIsolation disabled - */ + /** + * Test increasing coupon usages after after order placing and decreasing after order cancellation. + * + * @magentoDataFixture Magento/SalesRule/_files/coupons_limited_order.php + * @magentoDbIsolation disabled + */ public function testSubmitQuoteAndCancelOrder() { $customerId = 1; From 6f063f9d3835a7898b3e2084906c8ed4fa204a86 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Sun, 14 Jan 2024 18:29:15 +0530 Subject: [PATCH 22/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsagesIncrementMultishipping.php | 17 ++++++++++++++--- ...ouponUsageIncreamentForMultishippingTest.php | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php index 47e44d3c9cd54..e3ad939922e2b 100644 --- a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php +++ b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php @@ -1,7 +1,18 @@ Date: Mon, 15 Jan 2024 03:15:55 +0530 Subject: [PATCH 23/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsageIncreamentForMultishippingTest.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename app/code/Magento/SalesRule/Test/Unit/{plugin => Plugin}/CouponUsageIncreamentForMultishippingTest.php (100%) diff --git a/app/code/Magento/SalesRule/Test/Unit/plugin/CouponUsageIncreamentForMultishippingTest.php b/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php similarity index 100% rename from app/code/Magento/SalesRule/Test/Unit/plugin/CouponUsageIncreamentForMultishippingTest.php rename to app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php From 33b4766703d57a1ff767d0be571809766eecd36f Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Mon, 15 Jan 2024 16:03:15 +0530 Subject: [PATCH 24/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsageIncreamentForMultishippingTest.php | 11 +++-------- app/code/Magento/SalesRule/etc/module.xml | 1 + 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php b/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php index 49318603f6cdf..09b1cf4b90e35 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php @@ -18,7 +18,6 @@ namespace Magento\SalesRule\Test\Unit\Model\Plugin; -use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; use PHPUnit\Framework\MockObject\MockObject; @@ -60,7 +59,6 @@ class CouponUsageIncreamentForMultishippingTest extends TestCase */ protected function setUp(): void { - $this->objectManagerHelper = new ObjectManagerHelper($this); $this->subjectMock = $this->getMockBuilder(PlaceOrderDefault::class) ->disableOriginalConstructor() ->getMock(); @@ -75,12 +73,9 @@ protected function setUp(): void ->onlyMethods(['getQuoteId']) ->disableOriginalConstructor() ->getMock(); - $this->plugin = $this->objectManagerHelper->getObject( - CouponUsagesIncrementMultishipping::class, - [ - 'updateCouponUsages' => $this->updateCouponUsagesMock, - 'quoteRepository' => $this->quoteRepositoryMock - ] + $this->plugin = new CouponUsagesIncrementMultishipping( + $this->updateCouponUsagesMock, + $this->quoteRepositoryMock ); } /** diff --git a/app/code/Magento/SalesRule/etc/module.xml b/app/code/Magento/SalesRule/etc/module.xml index 4344e00b6f840..b8f8938144f99 100644 --- a/app/code/Magento/SalesRule/etc/module.xml +++ b/app/code/Magento/SalesRule/etc/module.xml @@ -12,6 +12,7 @@ + From c905c73d7f18969b4bb38baec86c93a462f249ce Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Mon, 15 Jan 2024 17:06:36 +0530 Subject: [PATCH 25/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php | 2 +- app/code/Magento/SalesRule/etc/module.xml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php b/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php index 09b1cf4b90e35..3a2718e7817e2 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php @@ -16,7 +16,7 @@ */ declare(strict_types=1); -namespace Magento\SalesRule\Test\Unit\Model\Plugin; +namespace Magento\SalesRule\Test\Unit\Plugin; use Magento\Quote\Model\Quote; use Magento\Quote\Model\QuoteRepository; diff --git a/app/code/Magento/SalesRule/etc/module.xml b/app/code/Magento/SalesRule/etc/module.xml index b8f8938144f99..4344e00b6f840 100644 --- a/app/code/Magento/SalesRule/etc/module.xml +++ b/app/code/Magento/SalesRule/etc/module.xml @@ -12,7 +12,6 @@ - From ba0d0f192ece335ee2ea285bbc7193297090bd8d Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 18 Jan 2024 10:51:01 +0530 Subject: [PATCH 26/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsagesIncrementMultishipping.php | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php index e3ad939922e2b..772bdf92b2baa 100644 --- a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php +++ b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php @@ -18,10 +18,12 @@ namespace Magento\SalesRule\Plugin; +use Closure; use Magento\Framework\Exception\NoSuchEntityException; -use Magento\Quote\Model\QuoteRepository; use Magento\SalesRule\Model\Coupon\Quote\UpdateCouponUsages; use Magento\Multishipping\Model\Checkout\Type\Multishipping\PlaceOrderDefault; +use Throwable; +use Magento\Quote\Api\CartRepositoryInterface; /** * Increments number of coupon usages before placing order @@ -32,37 +34,37 @@ class CouponUsagesIncrementMultishipping /** * @var UpdateCouponUsages */ - private $updateCouponUsages; + private UpdateCouponUsages $updateCouponUsages; /** - * @var QuoteRepository + * @var CartRepositoryInterface */ - private QuoteRepository $quoteRepository; + private CartRepositoryInterface $cartRepositoryInterface; /** * @param UpdateCouponUsages $updateCouponUsages - * @param QuoteRepository $quoteRepository + * @param CartRepositoryInterface $cartRepositoryInterface */ - public function __construct(UpdateCouponUsages $updateCouponUsages, QuoteRepository $quoteRepository) + public function __construct(UpdateCouponUsages $updateCouponUsages, CartRepositoryInterface $cartRepositoryInterface) { $this->updateCouponUsages = $updateCouponUsages; - $this->quoteRepository = $quoteRepository; + $this->cartRepositoryInterface = $cartRepositoryInterface; } /** * Increments number of coupon usages before placing order * * @param PlaceOrderDefault $subject - * @param \Closure $proceed + * @param Closure $proceed * @param array $order - * @return void - * @throws NoSuchEntityException + * @return array + * @throws NoSuchEntityException|Throwable * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - public function aroundPlace(PlaceOrderDefault $subject, \Closure $proceed, array $order) + public function aroundPlace(PlaceOrderDefault $subject, Closure $proceed, array $order): array { $quoteId = $order[0]->getQuoteId(); - $quote = $this->quoteRepository->get($quoteId); + $quote = $this->cartRepositoryInterface->get($quoteId); /* if coupon code has been canceled then need to notify the customer */ if (!$quote->getCouponCode() && $quote->dataHasChangedFor('coupon_code')) { throw new NoSuchEntityException(__("The coupon code isn't valid. Verify the code and try again.")); @@ -71,7 +73,7 @@ public function aroundPlace(PlaceOrderDefault $subject, \Closure $proceed, array $this->updateCouponUsages->execute($quote, true); try { return $proceed($order); - } catch (\Throwable $e) { + } catch (Throwable $e) { $this->updateCouponUsages->execute($quote, false); throw $e; } From 055b911f3c3fbb0164b8707fe4ff7b144bfcb344 Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 18 Jan 2024 10:53:40 +0530 Subject: [PATCH 27/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../CouponUsageIncreamentForMultishippingTest.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php b/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php index 3a2718e7817e2..1076542c49c7b 100644 --- a/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php +++ b/app/code/Magento/SalesRule/Test/Unit/Plugin/CouponUsageIncreamentForMultishippingTest.php @@ -19,7 +19,7 @@ namespace Magento\SalesRule\Test\Unit\Plugin; use Magento\Quote\Model\Quote; -use Magento\Quote\Model\QuoteRepository; +use Magento\Quote\Api\CartRepositoryInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Magento\SalesRule\Model\Coupon\Quote\UpdateCouponUsages; @@ -40,9 +40,9 @@ class CouponUsageIncreamentForMultishippingTest extends TestCase private $updateCouponUsagesMock; /** - * @var QuoteRepository|MockObject + * @var CartRepositoryInterface|MockObject */ - private $quoteRepositoryMock; + private $cartRepositoryInterfaceMock; /** * @var Order[]|MockObject @@ -66,7 +66,7 @@ protected function setUp(): void ->disableOriginalConstructor() ->onlyMethods(['execute']) ->getMock(); - $this->quoteRepositoryMock = $this->getMockBuilder(QuoteRepository::class) + $this->cartRepositoryInterfaceMock = $this->getMockBuilder(CartRepositoryInterface::class) ->disableOriginalConstructor() ->getMock(); $this->orderMock = $this->getMockBuilder(Order::class) @@ -75,7 +75,7 @@ protected function setUp(): void ->getMock(); $this->plugin = new CouponUsagesIncrementMultishipping( $this->updateCouponUsagesMock, - $this->quoteRepositoryMock + $this->cartRepositoryInterfaceMock ); } /** @@ -96,7 +96,7 @@ public function testAroundPlace() $this->orderMock->expects($this->once())->method('getQuoteId') ->willReturn(1); - $this->quoteRepositoryMock->expects($this->once())->method('get')->with(1)->willReturn($quoteMock); + $this->cartRepositoryInterfaceMock->expects($this->once())->method('get')->with(1)->willReturn($quoteMock); $quoteMock->expects($this->once())->method('getCouponCode')->willReturn($couponCode); $quoteMock->expects($this->any())->method('dataHasChangedFor')->with($couponCode)->willReturn(true); $this->updateCouponUsagesMock From e7410d7c2beb5856276aaef7f8858366daca3f2d Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 18 Jan 2024 15:18:14 +0530 Subject: [PATCH 28/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../SalesRule/Plugin/CouponUsagesIncrementMultishipping.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php index 772bdf92b2baa..920a3ebfa8c6e 100644 --- a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php +++ b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php @@ -45,7 +45,8 @@ class CouponUsagesIncrementMultishipping * @param UpdateCouponUsages $updateCouponUsages * @param CartRepositoryInterface $cartRepositoryInterface */ - public function __construct(UpdateCouponUsages $updateCouponUsages, CartRepositoryInterface $cartRepositoryInterface) + public function __construct(UpdateCouponUsages $updateCouponUsages, + CartRepositoryInterface $cartRepositoryInterface) { $this->updateCouponUsages = $updateCouponUsages; $this->cartRepositoryInterface = $cartRepositoryInterface; From e7643b3543f21b0915fb51d3f9184f30dcf5792f Mon Sep 17 00:00:00 2001 From: "Chhandak.Barua" Date: Thu, 18 Jan 2024 18:55:56 +0530 Subject: [PATCH 29/56] ACP2E-2519: The coupon code count does not update in the Time Used column in the Manage Coupon Codes tab if an order is placed with multi-shipping. --- .../Plugin/CouponUsagesIncrementMultishipping.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php index 920a3ebfa8c6e..ce0c9751200ee 100644 --- a/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php +++ b/app/code/Magento/SalesRule/Plugin/CouponUsagesIncrementMultishipping.php @@ -45,9 +45,10 @@ class CouponUsagesIncrementMultishipping * @param UpdateCouponUsages $updateCouponUsages * @param CartRepositoryInterface $cartRepositoryInterface */ - public function __construct(UpdateCouponUsages $updateCouponUsages, - CartRepositoryInterface $cartRepositoryInterface) - { + public function __construct( + UpdateCouponUsages $updateCouponUsages, + CartRepositoryInterface $cartRepositoryInterface + ) { $this->updateCouponUsages = $updateCouponUsages; $this->cartRepositoryInterface = $cartRepositoryInterface; } From 3af4890db04cb344aef6f1c5fb26565da10c12e1 Mon Sep 17 00:00:00 2001 From: pradeep1819 Date: Sat, 20 Apr 2024 14:41:31 +0530 Subject: [PATCH 30/56] ACP2E-2927: [REST API]: Use Default value in store view does not stay checked after adding configurations for a configurable product --- .../Product/Initialization/Helper.php | 4 + .../Model/ResourceModel/Product/Option.php | 12 +- .../ResourceModel/Product/Option/Value.php | 13 +- .../Product/Initialization/HelperTest.php | 2 + .../Catalog/Api/ProductCustomOptionsTest.php | 297 ++++++++++++++++++ 5 files changed, 314 insertions(+), 14 deletions(-) create mode 100644 dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionsTest.php diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index d6c3037d5bf62..2f9551987a11c 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -20,6 +20,7 @@ use Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks; use Magento\Catalog\Model\Product\Link\Resolver as LinkResolver; use Magento\Catalog\Model\Product\LinkTypeProvider; +use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\CustomOptions; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\RequestInterface; use Magento\Framework\Locale\FormatInterface; @@ -401,6 +402,9 @@ private function overwriteValue($optionId, $option, $overwriteOptions) $option['is_delete_store_title'] = 1; } } + if (CustomOptions::FIELD_TITLE_NAME == $fieldName) { + $option[CustomOptions::FIELD_IS_USE_DEFAULT] = $overwrite; + } } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php index 2238ad91550e4..3d33a9fe8c09d 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php @@ -14,7 +14,6 @@ /** * Catalog product custom option resource model * - * @author Magento Core Team * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class Option extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb @@ -25,15 +24,11 @@ class Option extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb protected $metadataPool; /** - * Store manager - * * @var \Magento\Store\Model\StoreManagerInterface */ protected $_storeManager; /** - * Currency factory - * * @var \Magento\Directory\Model\CurrencyFactory */ protected $_currencyFactory; @@ -262,9 +257,10 @@ protected function _saveValueTitles(AbstractModel $object) if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore) || ( $storeId != Store::DEFAULT_STORE_ID && - !$existInCurrentStore && - !$isDeleteStoreTitle - ) + !$isDeleteStoreTitle && + ($object->getDefaultTitle() != null && $object->getTitle() !== $object->getDefaultTitle()) + ) || + ($object->getIsUseDefault() != null && !(int)$object->getIsUseDefault()) ) { $data = $this->_prepareDataForTable( new \Magento\Framework\DataObject( diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php index 494dbac02d792..c05f5561864eb 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php @@ -27,15 +27,11 @@ class Value extends AbstractDb { /** - * Store manager - * * @var StoreManagerInterface */ protected $_storeManager; /** - * Currency factory - * * @var CurrencyFactory */ protected $_currencyFactory; @@ -288,8 +284,12 @@ protected function _saveValueTitles(AbstractModel $object) Store::DEFAULT_STORE_ID ); // we should insert record into not default store only of if it does not exist in default store - if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore) - || ($storeId != Store::DEFAULT_STORE_ID && !$existInCurrentStore) + if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore) || + ( + $storeId != Store::DEFAULT_STORE_ID && + ($object->getDefaultTitle() != null && $object->getTitle() !== $object->getDefaultTitle()) + ) || + ($object->getIsUseDefault() != null && !(int)$object->getIsUseDefault()) ) { $bind = [ 'option_type_id' => (int)$object->getId(), @@ -456,6 +456,7 @@ public function duplicate(OptionValue $object, $oldOptionId, $newOptionId) * * @return FormatInterface * @deprecated 101.0.8 + * @see Avoid direct use of ObjectManager */ private function getLocaleFormatter() { diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php index a437ee49b398f..13505fcdcfd5d 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php @@ -660,6 +660,7 @@ public static function mergeProductOptionsDataProvider() 'default_key2' => 'val22', ], ], + 'is_use_default' => 1, ], ], ], @@ -702,6 +703,7 @@ public static function mergeProductOptionsDataProvider() 'default_key1' => 'val11', 'default_title' => 'val22', 'is_delete_store_title' => 1, + 'is_use_default' => 1, ], ], ], diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionsTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionsTest.php new file mode 100644 index 0000000000000..a2531faa6d81e --- /dev/null +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductCustomOptionsTest.php @@ -0,0 +1,297 @@ +objectManager = Bootstrap::getObjectManager(); + $this->fixtures = DataFixtureStorageManager::getStorage(); + $this->request = $this->objectManager->get(RequestInterface::class); + $this->customOptionModifier = $this->objectManager->get(CustomOptionsModifier::class); + $this->productRepository = $this->objectManager->get(ProductRepositoryInterface::class); + $this->option = $this->objectManager->get(ProductCustomOptionRepositoryInterface::class); + $this->registry = $this->objectManager->get(Registry::class); + } + + /** + * @inheritDoc + */ + protected function tearDown(): void + { + parent::tearDown(); + + $this->clearData(); + } + + /** + * Test to verify customizable options honour `use default value` checkbox check + * @dataProvider optionDataProvider + * @param array $optionData + * @return void + * @throws NoSuchEntityException + */ + #[ + DbIsolation(false), + AppIsolation(true), + AppArea('adminhtml'), + Config('web/url/use_store', 1), + DataFixture(WebsiteFixture::class, as: 'website2'), + DataFixture(StoreGroupFixture::class, ['website_id' => '$website2.id$'], 'group2'), + DataFixture(StoreFixture::class, ['store_group_id' => '$group2.id$'], 'store2'), + DataFixture(ProductFixture::class, as: 'p1'), + DataFixture(ProductFixture::class, as: 'p2'), + DataFixture(AttributeFixture::class, as: 'attr'), + DataFixture( + ConfigurableProductFixture::class, + ['_options' => ['$attr$'], '_links' => ['$p1$', '$p2$']], + 'cp1' + ), + ] + public function testModifyData(array $optionData): void + { + $childProduct = $this->fixtures->get('p2'); + $product = $this->fixtures->get('cp1'); + $store2 = $this->fixtures->get('store2'); + + $productSku = $product->getSku(); + $childSku = $childProduct->getSku(); + $storeCode = $store2->getCode(); + $optionDataPost = $optionData; + $optionDataPost['product_sku'] = $productSku; + $this->addCustomizableOptions($optionDataPost); + $this->assertTrue( + $this->removeChild($productSku, $childSku, $storeCode), + 'Unable to remove child product.' + ); + $this->assertTrue( + $this->addChild($productSku, $childSku, $storeCode), + 'Unable to link child product.' + ); + + $response = $this->productDataSource($product, $store2); + $productId = $product->getId(); + $this->assertTrue($response[$productId]['product']['options'][0]['is_use_default']); + if (in_array($optionData['type'], ['drop_down', 'radio', 'checkbox', 'multiple'])) { + $this->assertTrue($response[$productId]['product']['options'][0]['values'][0]['is_use_default']); + } + //delete custom options for db cleanup + $this->deleteCustomizableOption($productSku, (int)$response[$productId]['product']['options'][0]['option_id']); + } + + /** + * Perform add child product Api call + * + * @param string $productSku + * @param string $childSku + * @param string $storeCode + * @return bool + */ + private function addChild(string $productSku, string $childSku, string $storeCode): bool + { + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => self::CONFIG_RESOURCE_PATH . '/' . $productSku . '/child', + 'httpMethod' => Request::HTTP_METHOD_POST + ], + 'soap' => [ + 'service' => self::CONFIG_SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::CONFIG_SERVICE_NAME . 'AddChild' + ] + ]; + + return $this->_webApiCall($serviceInfo, ['sku' => $productSku, 'childSku' => $childSku], null, $storeCode); + } + + /** + * Unassign child product + * + * @param string $productSku + * @param string $childSku + * @param string $storeCode + * @return bool + */ + private function removeChild(string $productSku, string $childSku, string $storeCode): bool + { + $resourcePath = self::CONFIG_RESOURCE_PATH . '/%s/children/%s'; + $serviceInfo = [ + 'rest' => [ + 'resourcePath' => sprintf($resourcePath, $productSku, $childSku), + 'httpMethod' => Request::HTTP_METHOD_DELETE + ], + 'soap' => [ + 'service' => self::CONFIG_SERVICE_NAME, + 'serviceVersion' => self::SERVICE_VERSION, + 'operation' => self::CONFIG_SERVICE_NAME . 'RemoveChild' + ] + ]; + $requestData = ['sku' => $productSku, 'childSku' => $childSku]; + return $this->_webApiCall($serviceInfo, $requestData, null, $storeCode); + } + + /** + * Fetch product data with customizable options + * + * @param $configurableProduct + * @param $store + * @return array + * @throws NoSuchEntityException + */ + private function productDataSource($configurableProduct, $store): array + { + $this->clearData(); + $productId = $configurableProduct->getData('entity_id'); + $this->request->setParams([ + 'id' => $productId, + 'store' => $store->getId(), + ]); + $product = $this->productRepository->getById($productId, true, $store->getId()); + $this->registry->register('current_product', $product); + + return $this->customOptionModifier->modifyData( + [ + $productId => [ + 'product' => $product->getData() + ] + ] + ); + } + + /** + * Product's customizable options data provider + * + * @return array + */ + public function optionDataProvider(): array + { + $fixtureOptions = []; + $fixture = include '_files/product_options.php'; + foreach ($fixture as $item) { + $fixtureOptions[$item['type']] = [ + 'optionData' => $item, + ]; + } + + return $fixtureOptions; + } + + /** + * Add customizable options to catalog > product + * + * @param $option + * @return void + */ + private function addCustomizableOptions($option): void + { + /** @var ProductCustomOptionInterfaceFactory $customOptionFactory */ + $customOptionFactory = $this->objectManager->create(ProductCustomOptionInterfaceFactory::class); + $customOption = $customOptionFactory->create(['data' => $option]); + $this->option->save($customOption); + } + + /** + * Delete customizable option by product SKU and option ID + * + * @param string $sku + * @param int $optionId + * @return bool + */ + private function deleteCustomizableOption(string $sku, int $optionId): bool + { + return $this->option->deleteByIdentifier($sku, $optionId); + } + + /** + * Remove request params + * + * @return void + */ + private function clearData(): void + { + $this->request->setParams([]); + $this->registry->unregister('current_product'); + } +} From e7b59ae997e4f2a407503cbd3b490410229a36b7 Mon Sep 17 00:00:00 2001 From: Arularasan Date: Tue, 23 Apr 2024 16:45:12 +0530 Subject: [PATCH 31/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Fixed the issue. --- .../Magento/CustomerImportExport/Model/Export/Customer.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php index 9ea9e1e5bd93d..b782f301dde16 100644 --- a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php @@ -27,6 +27,8 @@ class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav const COLUMN_STORE = '_store'; + const COLUMN_CREATED_AT = 'created_at'; + /** * Attribute collection name */ @@ -158,6 +160,11 @@ public function exportItem($item) $row = $this->_addAttributeValuesToRow($item); $row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()]; $row[self::COLUMN_STORE] = $this->_storeIdToCode[$item->getStoreId()]; + $row[self::COLUMN_CREATED_AT] = $this->_localeDate->formatDate( + $row[self::COLUMN_CREATED_AT], + \IntlDateFormatter::MEDIUM, + true + ); $this->getWriter()->writeRow($row); } From 0ac67b1bdf0ebb383e6a1b2dd44fbb9800d2c509 Mon Sep 17 00:00:00 2001 From: Arularasan Date: Wed, 24 Apr 2024 19:09:53 +0530 Subject: [PATCH 32/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Fixed the issue. --- .../Model/Export/Customer.php | 7 --- .../Model/Export/FormatCustomerCreatedAt.php | 56 +++++++++++++++++++ .../Magento/CustomerImportExport/etc/di.xml | 22 ++++++++ 3 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php create mode 100644 app/code/Magento/CustomerImportExport/etc/di.xml diff --git a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php index b782f301dde16..9ea9e1e5bd93d 100644 --- a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php @@ -27,8 +27,6 @@ class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav const COLUMN_STORE = '_store'; - const COLUMN_CREATED_AT = 'created_at'; - /** * Attribute collection name */ @@ -160,11 +158,6 @@ public function exportItem($item) $row = $this->_addAttributeValuesToRow($item); $row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()]; $row[self::COLUMN_STORE] = $this->_storeIdToCode[$item->getStoreId()]; - $row[self::COLUMN_CREATED_AT] = $this->_localeDate->formatDate( - $row[self::COLUMN_CREATED_AT], - \IntlDateFormatter::MEDIUM, - true - ); $this->getWriter()->writeRow($row); } diff --git a/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php b/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php new file mode 100644 index 0000000000000..63e88ef9ab1f0 --- /dev/null +++ b/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php @@ -0,0 +1,56 @@ +setData( + self::COLUMN_CREATED_AT, + $this->localeDate->formatDate( + $item->getData(self::COLUMN_CREATED_AT), + \IntlDateFormatter::MEDIUM, + true + ) + ); + } +} diff --git a/app/code/Magento/CustomerImportExport/etc/di.xml b/app/code/Magento/CustomerImportExport/etc/di.xml new file mode 100644 index 0000000000000..aa356a5b27a41 --- /dev/null +++ b/app/code/Magento/CustomerImportExport/etc/di.xml @@ -0,0 +1,22 @@ + + + + + + + From 98aa2b52a1b4aa0f763b329fbbeead07a724ffef Mon Sep 17 00:00:00 2001 From: Arularasan Date: Thu, 25 Apr 2024 11:25:58 +0530 Subject: [PATCH 33/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Fixed the static and integration test failure. --- .../Plugin/Model/Export/FormatCustomerCreatedAt.php | 7 +++++-- .../Model/Export/CustomerTest.php | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php b/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php index 63e88ef9ab1f0..79e3ffa516428 100644 --- a/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php +++ b/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php @@ -36,14 +36,17 @@ public function __construct( } /** + * Format the created_at column based on the timezone configuration. + * * @param Customer $subject * @param Item $item - * @return Item + * @return void */ public function beforeExportItem( Customer $subject, Item $item - ) { + ): void + { $item->setData( self::COLUMN_CREATED_AT, $this->localeDate->formatDate( diff --git a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php index e731f6e825356..63936b780555e 100644 --- a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php +++ b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php @@ -17,6 +17,7 @@ use Magento\Customer\Model\Customer as CustomerModel; use Magento\Customer\Model\ResourceModel\Attribute\Collection; use Magento\Customer\Model\ResourceModel\Customer\Collection as CustomerCollection; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; /** * Tests for customer export model. @@ -50,6 +51,11 @@ class CustomerTest extends \PHPUnit\Framework\TestCase */ private $attributeCollection; + /** + * @var TimezoneInterface + */ + private $localeDate; + /** * @inheritdoc */ @@ -58,6 +64,7 @@ protected function setUp(): void $this->objectManager = Bootstrap::getObjectManager(); $this->_model = $this->objectManager->create(Customer::class); $this->attributeCollection = $this->objectManager->create(Collection::class); + $this->localeDate = $this->objectManager->create(TimezoneInterface::class); } /** @@ -153,6 +160,11 @@ private function checkExportData(array $lines, array $expectedAttributes): void $customers = $this->objectManager->create(CustomerCollection::class); foreach ($customers as $customer) { $data = $this->processCustomerData($customer, $expectedAttributes); + $data['created_at'] = $this->localeDate->formatDate( + $data['created_at'], + \IntlDateFormatter::MEDIUM, + true + ); $exportData = $lines['data'][$data['email']]; $exportData = $this->unsetDuplicateData($exportData); From 7d5b431f16fba5fd0bf8d163363604974080eb3b Mon Sep 17 00:00:00 2001 From: Arularasan Date: Thu, 25 Apr 2024 12:16:32 +0530 Subject: [PATCH 34/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Fixed the static test failure. --- .../Plugin/Model/Export/FormatCustomerCreatedAt.php | 5 +++-- .../CustomerImportExport/Model/Export/CustomerTest.php | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php b/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php index 79e3ffa516428..dc999ac2a6faa 100644 --- a/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php +++ b/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php @@ -13,6 +13,8 @@ * from Adobe. * *********************************************************************** */ +declare(strict_types=1); + namespace Magento\CustomerImportExport\Plugin\Model\Export; use Magento\CustomerImportExport\Model\Export\Customer; @@ -45,8 +47,7 @@ public function __construct( public function beforeExportItem( Customer $subject, Item $item - ): void - { + ): void { $item->setData( self::COLUMN_CREATED_AT, $this->localeDate->formatDate( diff --git a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php index 63936b780555e..c6706c51e475b 100644 --- a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php +++ b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php @@ -23,6 +23,7 @@ * Tests for customer export model. * * @magentoAppArea adminhtml + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CustomerTest extends \PHPUnit\Framework\TestCase { From 09715bb09ae6b1f7452124ba1164ef5237521ce8 Mon Sep 17 00:00:00 2001 From: pradeep1819 Date: Mon, 29 Apr 2024 13:37:23 +0530 Subject: [PATCH 35/56] ACP2E-2927: [REST API]: Use Default value in store view does not stay checked after adding configurations for a configurable product --- .../Adminhtml/Product/Initialization/Helper.php | 2 +- .../Catalog/Model/ResourceModel/Product/Option.php | 8 ++++---- .../Catalog/Model/ResourceModel/Product/Option/Value.php | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index 2f9551987a11c..4fcc871f47e8e 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -402,7 +402,7 @@ private function overwriteValue($optionId, $option, $overwriteOptions) $option['is_delete_store_title'] = 1; } } - if (CustomOptions::FIELD_TITLE_NAME == $fieldName) { + if (CustomOptions::FIELD_TITLE_NAME === $fieldName) { $option[CustomOptions::FIELD_IS_USE_DEFAULT] = $overwrite; } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php index 3d33a9fe8c09d..80dd719794c18 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php @@ -254,13 +254,13 @@ protected function _saveValueTitles(AbstractModel $object) } } else { // we should insert record into not default store only of if it does not exist in default store - if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore) || + if (((int)$storeId === Store::DEFAULT_STORE_ID && !$existInDefaultStore) || ( - $storeId != Store::DEFAULT_STORE_ID && + (int)$storeId !== Store::DEFAULT_STORE_ID && !$isDeleteStoreTitle && - ($object->getDefaultTitle() != null && $object->getTitle() !== $object->getDefaultTitle()) + ($object->getDefaultTitle() !== null && $object->getTitle() !== $object->getDefaultTitle()) ) || - ($object->getIsUseDefault() != null && !(int)$object->getIsUseDefault()) + ($object->getIsUseDefault() !== null && !(int)$object->getIsUseDefault()) ) { $data = $this->_prepareDataForTable( new \Magento\Framework\DataObject( diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php index c05f5561864eb..89a20c6277339 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option/Value.php @@ -284,12 +284,12 @@ protected function _saveValueTitles(AbstractModel $object) Store::DEFAULT_STORE_ID ); // we should insert record into not default store only of if it does not exist in default store - if (($storeId == Store::DEFAULT_STORE_ID && !$existInDefaultStore) || + if (((int)$storeId === Store::DEFAULT_STORE_ID && !$existInDefaultStore) || ( - $storeId != Store::DEFAULT_STORE_ID && - ($object->getDefaultTitle() != null && $object->getTitle() !== $object->getDefaultTitle()) + (int)$storeId !== Store::DEFAULT_STORE_ID && + ($object->getDefaultTitle() !== null && $object->getTitle() !== $object->getDefaultTitle()) ) || - ($object->getIsUseDefault() != null && !(int)$object->getIsUseDefault()) + ($object->getIsUseDefault() !== null && !(int)$object->getIsUseDefault()) ) { $bind = [ 'option_type_id' => (int)$object->getId(), From db958ad2bfb4a87a3667631aedded04573edf39a Mon Sep 17 00:00:00 2001 From: anujnehra Date: Wed, 1 May 2024 23:26:38 +0530 Subject: [PATCH 36/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Controller/Adminhtml/Product/Initialization/Helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index d6c3037d5bf62..9a6160ab6328f 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -278,6 +278,7 @@ public function initialize(Product $product) * @param Product $product * @return Product * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.UnusedLocalVariable) * @since 101.0.0 */ protected function setProductLinks(Product $product) @@ -301,7 +302,7 @@ protected function setProductLinks(Product $product) } foreach ($linkTypes as $linkType => $readonly) { - if (isset($links[$linkType]) && !$readonly) { + if (isset($links[$linkType])) { foreach ((array) $links[$linkType] as $linkData) { if (empty($linkData['id'])) { continue; From e8f2a08bc56c4dcb1d119792aee5c5ed8fa951d7 Mon Sep 17 00:00:00 2001 From: anujnehra Date: Thu, 2 May 2024 13:36:30 +0530 Subject: [PATCH 37/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Adminhtml/Product/Initialization/Helper.php | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index 9a6160ab6328f..25e060e6c2fc7 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -278,13 +278,13 @@ public function initialize(Product $product) * @param Product $product * @return Product * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.UnusedLocalVariable) * @since 101.0.0 */ protected function setProductLinks(Product $product) { $links = $this->getLinkResolver()->getLinks(); + $currentProductLinks = $product->getProductLinks(); $product->setProductLinks([]); $product = $this->productLinks->initializeLinks($product, $links); @@ -300,9 +300,10 @@ protected function setProductLinks(Product $product) foreach ($productLinks as $productLink) { unset($linkTypes[$productLink->getLinkType()]); } - + $readonlyRelatedProducts = false; + $readonlyUpSellProducts = false; foreach ($linkTypes as $linkType => $readonly) { - if (isset($links[$linkType])) { + if (isset($links[$linkType]) && !$readonly) { foreach ((array) $links[$linkType] as $linkData) { if (empty($linkData['id'])) { continue; @@ -317,8 +318,16 @@ protected function setProductLinks(Product $product) $productLinks[] = $link; } } + if ($linkType === 'related' && $readonly) { + $readonlyRelatedProducts = true; + } + if ($linkType === 'upsell' && $readonly) { + $readonlyUpSellProducts = true; + } + } + if ($readonlyRelatedProducts && $readonlyUpSellProducts && empty($productLinks)) { + $productLinks = $currentProductLinks; } - return $product->setProductLinks($productLinks); } From 43d48e3102619c63811cad0275f76328b276830d Mon Sep 17 00:00:00 2001 From: anujnehra Date: Thu, 2 May 2024 13:37:44 +0530 Subject: [PATCH 38/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Controller/Adminhtml/Product/Initialization/Helper.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index 25e060e6c2fc7..262cb6a3ffd37 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -300,6 +300,7 @@ protected function setProductLinks(Product $product) foreach ($productLinks as $productLink) { unset($linkTypes[$productLink->getLinkType()]); } + $readonlyRelatedProducts = false; $readonlyUpSellProducts = false; foreach ($linkTypes as $linkType => $readonly) { @@ -328,6 +329,7 @@ protected function setProductLinks(Product $product) if ($readonlyRelatedProducts && $readonlyUpSellProducts && empty($productLinks)) { $productLinks = $currentProductLinks; } + return $product->setProductLinks($productLinks); } From 2af2298d690393c1f7987d198bff73488e0593b0 Mon Sep 17 00:00:00 2001 From: Arularasan Date: Thu, 2 May 2024 14:02:37 +0530 Subject: [PATCH 39/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Added the test coverage. --- .../Export/FormatCustomerCreatedAtTest.php | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 app/code/Magento/CustomerImportExport/Test/Unit/Plugin/Model/Export/FormatCustomerCreatedAtTest.php diff --git a/app/code/Magento/CustomerImportExport/Test/Unit/Plugin/Model/Export/FormatCustomerCreatedAtTest.php b/app/code/Magento/CustomerImportExport/Test/Unit/Plugin/Model/Export/FormatCustomerCreatedAtTest.php new file mode 100644 index 0000000000000..d52c17adbe239 --- /dev/null +++ b/app/code/Magento/CustomerImportExport/Test/Unit/Plugin/Model/Export/FormatCustomerCreatedAtTest.php @@ -0,0 +1,67 @@ +getMockForAbstractClass(TimezoneInterface::class); + $this->subjectMock = $this->getMockBuilder(Customer::class) + ->disableOriginalConstructor() + ->getMock(); + $this->itemMock = $this->getMockBuilder(Item::class) + ->disableOriginalConstructor() + ->getMock(); + $this->model = new FormatCustomerCreatedAt( + $timeZone + ); + } + + public function testBeforeExportIte() + { + $this->model->beforeExportItem( + $this->subjectMock, + $this->itemMock + ); + } +} From 414a576cb800dfde49e59df7b48cf5e62fcef24a Mon Sep 17 00:00:00 2001 From: anujnehra Date: Thu, 2 May 2024 19:59:50 +0530 Subject: [PATCH 40/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Adminhtml/Product/Initialization/Helper.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index 262cb6a3ffd37..855850c63a061 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -304,6 +304,12 @@ protected function setProductLinks(Product $product) $readonlyRelatedProducts = false; $readonlyUpSellProducts = false; foreach ($linkTypes as $linkType => $readonly) { + if ($linkType === 'related' && $readonly) { + $readonlyRelatedProducts = true; + } + if ($linkType === 'upsell' && $readonly) { + $readonlyUpSellProducts = true; + } if (isset($links[$linkType]) && !$readonly) { foreach ((array) $links[$linkType] as $linkData) { if (empty($linkData['id'])) { @@ -319,15 +325,9 @@ protected function setProductLinks(Product $product) $productLinks[] = $link; } } - if ($linkType === 'related' && $readonly) { - $readonlyRelatedProducts = true; - } - if ($linkType === 'upsell' && $readonly) { - $readonlyUpSellProducts = true; - } } if ($readonlyRelatedProducts && $readonlyUpSellProducts && empty($productLinks)) { - $productLinks = $currentProductLinks; + return $product->setProductLinks($currentProductLinks); } return $product->setProductLinks($productLinks); From a0f3325a018ac51347e3b58d9955420007afeb76 Mon Sep 17 00:00:00 2001 From: anujnehra Date: Fri, 3 May 2024 00:27:45 +0530 Subject: [PATCH 41/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Product/Initialization/Helper.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index 855850c63a061..505b839edce1e 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -284,7 +284,6 @@ protected function setProductLinks(Product $product) { $links = $this->getLinkResolver()->getLinks(); - $currentProductLinks = $product->getProductLinks(); $product->setProductLinks([]); $product = $this->productLinks->initializeLinks($product, $links); @@ -301,14 +300,14 @@ protected function setProductLinks(Product $product) unset($linkTypes[$productLink->getLinkType()]); } - $readonlyRelatedProducts = false; - $readonlyUpSellProducts = false; + $isReadOnlyRelatedItems = $isReadOnlyUpSellItems = false; foreach ($linkTypes as $linkType => $readonly) { - if ($linkType === 'related' && $readonly) { - $readonlyRelatedProducts = true; - } - if ($linkType === 'upsell' && $readonly) { - $readonlyUpSellProducts = true; + if ($readonly) { + if ($linkType === 'related') { + $isReadOnlyRelatedItems = true; + } elseif ($linkType === 'upsell') { + $isReadOnlyUpSellItems = true; + } } if (isset($links[$linkType]) && !$readonly) { foreach ((array) $links[$linkType] as $linkData) { @@ -326,8 +325,8 @@ protected function setProductLinks(Product $product) } } } - if ($readonlyRelatedProducts && $readonlyUpSellProducts && empty($productLinks)) { - return $product->setProductLinks($currentProductLinks); + if ($isReadOnlyRelatedItems && $isReadOnlyUpSellItems) { + $productLinks = []; } return $product->setProductLinks($productLinks); From 797e54729b94ecc231e52b2f60e5ef043d4b2d46 Mon Sep 17 00:00:00 2001 From: anujnehra Date: Fri, 3 May 2024 00:50:35 +0530 Subject: [PATCH 42/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Product/Initialization/Helper.php | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index 505b839edce1e..1d7bd4f0f0141 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -309,25 +309,27 @@ protected function setProductLinks(Product $product) $isReadOnlyUpSellItems = true; } } - if (isset($links[$linkType]) && !$readonly) { - foreach ((array) $links[$linkType] as $linkData) { - if (empty($linkData['id'])) { - continue; + if ($isReadOnlyRelatedItems && $isReadOnlyUpSellItems) { + $productLinks = null; + break; + } else { + if (isset($links[$linkType]) && !$readonly) { + foreach ((array) $links[$linkType] as $linkData) { + if (empty($linkData['id'])) { + continue; + } + + $linkProduct = $this->productRepository->getById($linkData['id']); + $link = $this->productLinkFactory->create(); + $link->setSku($product->getSku()) + ->setLinkedProductSku($linkProduct->getSku()) + ->setLinkType($linkType) + ->setPosition(isset($linkData['position']) ? (int) $linkData['position'] : 0); + $productLinks[] = $link; } - - $linkProduct = $this->productRepository->getById($linkData['id']); - $link = $this->productLinkFactory->create(); - $link->setSku($product->getSku()) - ->setLinkedProductSku($linkProduct->getSku()) - ->setLinkType($linkType) - ->setPosition(isset($linkData['position']) ? (int) $linkData['position'] : 0); - $productLinks[] = $link; } } } - if ($isReadOnlyRelatedItems && $isReadOnlyUpSellItems) { - $productLinks = []; - } return $product->setProductLinks($productLinks); } From e85753360e997a7193305dbedefe8c5b410743c1 Mon Sep 17 00:00:00 2001 From: Arularasan Date: Fri, 3 May 2024 12:53:29 +0530 Subject: [PATCH 43/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Reverted with the old commit to check the build failures. --- .../Model/Export/Customer.php | 7 ++ .../Model/Export/FormatCustomerCreatedAt.php | 60 ----------------- .../Export/FormatCustomerCreatedAtTest.php | 67 ------------------- .../Model/Export/CustomerTest.php | 13 ---- 4 files changed, 7 insertions(+), 140 deletions(-) delete mode 100644 app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php delete mode 100644 app/code/Magento/CustomerImportExport/Test/Unit/Plugin/Model/Export/FormatCustomerCreatedAtTest.php diff --git a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php index 9ea9e1e5bd93d..dfbf0e239a042 100644 --- a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php @@ -27,6 +27,8 @@ class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav const COLUMN_STORE = '_store'; + private const COLUMN_CREATED_AT = 'created_at'; + /** * Attribute collection name */ @@ -158,6 +160,11 @@ public function exportItem($item) $row = $this->_addAttributeValuesToRow($item); $row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()]; $row[self::COLUMN_STORE] = $this->_storeIdToCode[$item->getStoreId()]; + $row[self::COLUMN_CREATED_AT] = $this->_localeDate->formatDate( + $row[self::COLUMN_CREATED_AT], + \IntlDateFormatter::MEDIUM, + true + ); $this->getWriter()->writeRow($row); } diff --git a/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php b/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php deleted file mode 100644 index dc999ac2a6faa..0000000000000 --- a/app/code/Magento/CustomerImportExport/Plugin/Model/Export/FormatCustomerCreatedAt.php +++ /dev/null @@ -1,60 +0,0 @@ -setData( - self::COLUMN_CREATED_AT, - $this->localeDate->formatDate( - $item->getData(self::COLUMN_CREATED_AT), - \IntlDateFormatter::MEDIUM, - true - ) - ); - } -} diff --git a/app/code/Magento/CustomerImportExport/Test/Unit/Plugin/Model/Export/FormatCustomerCreatedAtTest.php b/app/code/Magento/CustomerImportExport/Test/Unit/Plugin/Model/Export/FormatCustomerCreatedAtTest.php deleted file mode 100644 index d52c17adbe239..0000000000000 --- a/app/code/Magento/CustomerImportExport/Test/Unit/Plugin/Model/Export/FormatCustomerCreatedAtTest.php +++ /dev/null @@ -1,67 +0,0 @@ -getMockForAbstractClass(TimezoneInterface::class); - $this->subjectMock = $this->getMockBuilder(Customer::class) - ->disableOriginalConstructor() - ->getMock(); - $this->itemMock = $this->getMockBuilder(Item::class) - ->disableOriginalConstructor() - ->getMock(); - $this->model = new FormatCustomerCreatedAt( - $timeZone - ); - } - - public function testBeforeExportIte() - { - $this->model->beforeExportItem( - $this->subjectMock, - $this->itemMock - ); - } -} diff --git a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php index c6706c51e475b..e731f6e825356 100644 --- a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php +++ b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php @@ -17,13 +17,11 @@ use Magento\Customer\Model\Customer as CustomerModel; use Magento\Customer\Model\ResourceModel\Attribute\Collection; use Magento\Customer\Model\ResourceModel\Customer\Collection as CustomerCollection; -use Magento\Framework\Stdlib\DateTime\TimezoneInterface; /** * Tests for customer export model. * * @magentoAppArea adminhtml - * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class CustomerTest extends \PHPUnit\Framework\TestCase { @@ -52,11 +50,6 @@ class CustomerTest extends \PHPUnit\Framework\TestCase */ private $attributeCollection; - /** - * @var TimezoneInterface - */ - private $localeDate; - /** * @inheritdoc */ @@ -65,7 +58,6 @@ protected function setUp(): void $this->objectManager = Bootstrap::getObjectManager(); $this->_model = $this->objectManager->create(Customer::class); $this->attributeCollection = $this->objectManager->create(Collection::class); - $this->localeDate = $this->objectManager->create(TimezoneInterface::class); } /** @@ -161,11 +153,6 @@ private function checkExportData(array $lines, array $expectedAttributes): void $customers = $this->objectManager->create(CustomerCollection::class); foreach ($customers as $customer) { $data = $this->processCustomerData($customer, $expectedAttributes); - $data['created_at'] = $this->localeDate->formatDate( - $data['created_at'], - \IntlDateFormatter::MEDIUM, - true - ); $exportData = $lines['data'][$data['email']]; $exportData = $this->unsetDuplicateData($exportData); From 2ae9ebc1ea2f83e6deb07780da8a0a73c4bd91ac Mon Sep 17 00:00:00 2001 From: Arularasan Date: Fri, 3 May 2024 12:55:12 +0530 Subject: [PATCH 44/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Deleted the di.xml file. --- .../Magento/CustomerImportExport/etc/di.xml | 22 ------------------- 1 file changed, 22 deletions(-) delete mode 100644 app/code/Magento/CustomerImportExport/etc/di.xml diff --git a/app/code/Magento/CustomerImportExport/etc/di.xml b/app/code/Magento/CustomerImportExport/etc/di.xml deleted file mode 100644 index aa356a5b27a41..0000000000000 --- a/app/code/Magento/CustomerImportExport/etc/di.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - From 1a41822195ad16756c8bd9cb247acb1e68125b31 Mon Sep 17 00:00:00 2001 From: anujnehra Date: Fri, 3 May 2024 14:31:19 +0530 Subject: [PATCH 45/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Product/Initialization/HelperTest.php | 50 +++++++++++++++++-- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php index a437ee49b398f..406d2217025ab 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php @@ -151,7 +151,7 @@ protected function setUp(): void ->disableOriginalConstructor() ->getMockForAbstractClass(); $productExtensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class) - ->addMethods(['getCategoryLinks', 'setCategoryLinks']) + ->onlyMethods(['getCategoryLinks', 'setCategoryLinks']) ->getMockForAbstractClass(); $this->productMock->setExtensionAttributes($productExtensionAttributes); @@ -161,9 +161,7 @@ protected function setUp(): void ->getMock(); $this->productLinksMock = $this->createMock(ProductLinks::class); $this->linkTypeProviderMock = $this->createMock(LinkTypeProvider::class); - $this->productLinksMock->expects($this->any()) - ->method('initializeLinks') - ->willReturn($this->productMock); + $this->attributeFilterMock = $this->createMock(AttributeFilter::class); $this->localeFormatMock = $this->createMock(Format::class); @@ -229,8 +227,17 @@ public function testInitialize( $links, $linkTypes, $expectedLinks, - $tierPrice = null + $tierPrice = null, + $isReadOnlyRelatedItems = null, + $isReadOnlyUpSellItems = null, + $ignoreLinksFlag = false ) { + $this->productMock->setData('related_readonly', $isReadOnlyRelatedItems); + $this->productMock->setData('upsell_readonly', $isReadOnlyUpSellItems); + $this->productLinksMock->expects($this->any()) + ->method('initializeLinks') + ->willReturn($this->productMock); + $this->linkTypeProviderMock->expects($this->once()) ->method('getItems') ->willReturn($this->assembleLinkTypes($linkTypes)); @@ -346,6 +353,11 @@ function () { $productLinks = $this->productMock->getProductLinks(); $this->assertCount(count($expectedLinks), $productLinks); + if ($ignoreLinksFlag) { + $this->assertTrue($this->productMock->getDataByKey('ignore_links_flag')); + } else { + $this->assertFalse($this->productMock->getDataByKey('ignore_links_flag')); + } $resultLinks = []; $this->assertEquals($tierPrice ?: [], $this->productMock->getData('tier_price')); @@ -559,6 +571,34 @@ public static function initializeDataProvider() ['type' => 'related', 'linked_product_sku' => 'Test'], ], ], + + // readonly links + [ + 'single_store' => false, + 'website_ids' => ['1' => 1, '2' => 2], + 'expected_website_ids' => ['1' => 1, '2' => 2], + 'links' => [ + 'related' => [ + 0 => [ + 'id' => 1, + 'thumbnail' => 'http://magento.dev/media/no-image.jpg', + 'name' => 'Test', + 'status' => 'Enabled', + 'attribute_set' => 'Default', + 'sku' => 'Test', + 'price' => 1.00, + 'position' => 1, + 'record_id' => 1, + ], + ], + ], + 'linkTypes' => ['related', 'upsell', 'crosssell'], + 'expected_links' => [], + 'tierPrice' => [], + true, + true, + true + ], ]; } From a98a4ab7bc70e724b37d4e80d1ecda29c7f20a4d Mon Sep 17 00:00:00 2001 From: anujnehra Date: Fri, 3 May 2024 15:28:27 +0530 Subject: [PATCH 46/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Controller/Adminhtml/Product/Initialization/HelperTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php index 406d2217025ab..8807690ae934d 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php @@ -219,6 +219,7 @@ protected function setUp(): void * @param array|null $tierPrice * @dataProvider initializeDataProvider * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function testInitialize( $isSingleStore, From aa3eb6029ec5d00cb15b9d08fef38d3ccac5e3ea Mon Sep 17 00:00:00 2001 From: anujnehra Date: Fri, 3 May 2024 16:32:21 +0530 Subject: [PATCH 47/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Controller/Adminhtml/Product/Initialization/HelperTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php index 8807690ae934d..dbb334c04ab2f 100644 --- a/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Controller/Adminhtml/Product/Initialization/HelperTest.php @@ -151,7 +151,7 @@ protected function setUp(): void ->disableOriginalConstructor() ->getMockForAbstractClass(); $productExtensionAttributes = $this->getMockBuilder(ProductExtensionInterface::class) - ->onlyMethods(['getCategoryLinks', 'setCategoryLinks']) + ->addMethods(['getCategoryLinks', 'setCategoryLinks']) ->getMockForAbstractClass(); $this->productMock->setExtensionAttributes($productExtensionAttributes); From 124d785ed09c35aaded1dfc28684eff8efc8ab4a Mon Sep 17 00:00:00 2001 From: anujnehra Date: Tue, 7 May 2024 00:10:20 +0530 Subject: [PATCH 48/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Product/Initialization/Helper.php | 70 +++++++++++++------ 1 file changed, 47 insertions(+), 23 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index 1d7bd4f0f0141..deb39b6e8ec66 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -22,6 +22,7 @@ use Magento\Catalog\Model\Product\LinkTypeProvider; use Magento\Framework\App\ObjectManager; use Magento\Framework\App\RequestInterface; +use Magento\Framework\Exception\NoSuchEntityException; use Magento\Framework\Locale\FormatInterface; use Magento\Framework\Stdlib\DateTime\Filter\Date; use Magento\Store\Model\StoreManagerInterface; @@ -278,6 +279,7 @@ public function initialize(Product $product) * @param Product $product * @return Product * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @throws NoSuchEntityException * @since 101.0.0 */ protected function setProductLinks(Product $product) @@ -300,34 +302,21 @@ protected function setProductLinks(Product $product) unset($linkTypes[$productLink->getLinkType()]); } - $isReadOnlyRelatedItems = $isReadOnlyUpSellItems = false; + $isReadOnlyUpSellItems = false; foreach ($linkTypes as $linkType => $readonly) { - if ($readonly) { - if ($linkType === 'related') { - $isReadOnlyRelatedItems = true; - } elseif ($linkType === 'upsell') { - $isReadOnlyUpSellItems = true; - } - } + $isReadOnlyRelatedItems = $readonly && $linkType === 'related' || + ($isReadOnlyUpSellItems = $readonly && $linkType === 'upsell'); if ($isReadOnlyRelatedItems && $isReadOnlyUpSellItems) { $productLinks = null; break; } else { - if (isset($links[$linkType]) && !$readonly) { - foreach ((array) $links[$linkType] as $linkData) { - if (empty($linkData['id'])) { - continue; - } - - $linkProduct = $this->productRepository->getById($linkData['id']); - $link = $this->productLinkFactory->create(); - $link->setSku($product->getSku()) - ->setLinkedProductSku($linkProduct->getSku()) - ->setLinkType($linkType) - ->setPosition(isset($linkData['position']) ? (int) $linkData['position'] : 0); - $productLinks[] = $link; - } - } + $productLinks = $this->setProductLinksForNotReadOnlyItems( + $productLinks, + $product, + $links, + $linkType, + $readonly + ); } } @@ -536,4 +525,39 @@ private function setCategoryLinks(Product $product): void $extensionAttributes->setCategoryLinks(!empty($newCategoryLinks) ? $newCategoryLinks : null); $product->setExtensionAttributes($extensionAttributes); } + + /** + * Set product links when readonly is false + * + * @param array $productLinks + * @param Product $product + * @param array $links + * @param string $linkType + * @param mixed $readonly + * @return array + * @throws NoSuchEntityException + */ + private function setProductLinksForNotReadOnlyItems( + array $productLinks, + Product $product, + array $links, + string $linkType, + mixed $readonly + ): array { + if (isset($links[$linkType]) && !$readonly) { + foreach ((array)$links[$linkType] as $linkData) { + if (empty($linkData['id'])) { + continue; + } + $linkProduct = $this->productRepository->getById($linkData['id']); + $link = $this->productLinkFactory->create(); + $link->setSku($product->getSku()) + ->setLinkedProductSku($linkProduct->getSku()) + ->setLinkType($linkType) + ->setPosition(isset($linkData['position']) ? (int)$linkData['position'] : 0); + $productLinks[] = $link; + } + } + return $productLinks; + } } From 3dba11047729b2e2cdb59ef5d8af107959b011c0 Mon Sep 17 00:00:00 2001 From: Arularasan Date: Tue, 7 May 2024 15:10:56 +0530 Subject: [PATCH 49/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Fixed the CR comments. --- .../Model/Export/Customer.php | 16 ++++++++-------- .../Model/Export/CustomerTest.php | 12 ++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php index dfbf0e239a042..e7e410e9f49f1 100644 --- a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php @@ -21,23 +21,23 @@ class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav * Names that begins with underscore is not an attribute. This name convention is for * to avoid interference with same attribute name. */ - const COLUMN_EMAIL = 'email'; + private const COLUMN_EMAIL = 'email'; - const COLUMN_WEBSITE = '_website'; + private const COLUMN_WEBSITE = '_website'; - const COLUMN_STORE = '_store'; + private const COLUMN_STORE = '_store'; private const COLUMN_CREATED_AT = 'created_at'; /** - * Attribute collection name + * A constant declaration for attribute collection name */ - const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class; + private const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class; /** * XML path to page size parameter */ - const XML_PATH_PAGE_SIZE = 'export/customer_page_size/customer'; + private const XML_PATH_PAGE_SIZE = 'export/customer_page_size/customer'; /** * @var array @@ -141,7 +141,7 @@ protected function _getEntityCollection() } /** - * {@inheritdoc} + * @inheritdoc */ protected function _getHeaderColumns() { @@ -161,7 +161,7 @@ public function exportItem($item) $row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()]; $row[self::COLUMN_STORE] = $this->_storeIdToCode[$item->getStoreId()]; $row[self::COLUMN_CREATED_AT] = $this->_localeDate->formatDate( - $row[self::COLUMN_CREATED_AT], + $item->getCreatedAt(), \IntlDateFormatter::MEDIUM, true ); diff --git a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php index e731f6e825356..63936b780555e 100644 --- a/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php +++ b/dev/tests/integration/testsuite/Magento/CustomerImportExport/Model/Export/CustomerTest.php @@ -17,6 +17,7 @@ use Magento\Customer\Model\Customer as CustomerModel; use Magento\Customer\Model\ResourceModel\Attribute\Collection; use Magento\Customer\Model\ResourceModel\Customer\Collection as CustomerCollection; +use Magento\Framework\Stdlib\DateTime\TimezoneInterface; /** * Tests for customer export model. @@ -50,6 +51,11 @@ class CustomerTest extends \PHPUnit\Framework\TestCase */ private $attributeCollection; + /** + * @var TimezoneInterface + */ + private $localeDate; + /** * @inheritdoc */ @@ -58,6 +64,7 @@ protected function setUp(): void $this->objectManager = Bootstrap::getObjectManager(); $this->_model = $this->objectManager->create(Customer::class); $this->attributeCollection = $this->objectManager->create(Collection::class); + $this->localeDate = $this->objectManager->create(TimezoneInterface::class); } /** @@ -153,6 +160,11 @@ private function checkExportData(array $lines, array $expectedAttributes): void $customers = $this->objectManager->create(CustomerCollection::class); foreach ($customers as $customer) { $data = $this->processCustomerData($customer, $expectedAttributes); + $data['created_at'] = $this->localeDate->formatDate( + $data['created_at'], + \IntlDateFormatter::MEDIUM, + true + ); $exportData = $lines['data'][$data['email']]; $exportData = $this->unsetDuplicateData($exportData); From 32f9aa96b83aa0648b9eaf2be9520aeb6cfdfc7c Mon Sep 17 00:00:00 2001 From: Arularasan Date: Tue, 7 May 2024 16:19:09 +0530 Subject: [PATCH 50/56] ACP2E-2990: Customer "created_at" date Not Converted to store time zone upon export - Fixed the build error. --- .../CustomerImportExport/Model/Export/Customer.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php index e7e410e9f49f1..d58d372e1f5b4 100644 --- a/app/code/Magento/CustomerImportExport/Model/Export/Customer.php +++ b/app/code/Magento/CustomerImportExport/Model/Export/Customer.php @@ -21,18 +21,18 @@ class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav * Names that begins with underscore is not an attribute. This name convention is for * to avoid interference with same attribute name. */ - private const COLUMN_EMAIL = 'email'; + public const COLUMN_EMAIL = 'email'; - private const COLUMN_WEBSITE = '_website'; + public const COLUMN_WEBSITE = '_website'; - private const COLUMN_STORE = '_store'; + public const COLUMN_STORE = '_store'; - private const COLUMN_CREATED_AT = 'created_at'; + public const COLUMN_CREATED_AT = 'created_at'; /** * A constant declaration for attribute collection name */ - private const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class; + public const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class; /** * XML path to page size parameter From eab2af35984d19c8a62434da73c0646eb8ebf9d2 Mon Sep 17 00:00:00 2001 From: anujnehra Date: Tue, 7 May 2024 22:17:02 +0530 Subject: [PATCH 51/56] ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product --- .../Controller/Adminhtml/Product/Initialization/Helper.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php index deb39b6e8ec66..8b771b307af8e 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php @@ -302,11 +302,9 @@ protected function setProductLinks(Product $product) unset($linkTypes[$productLink->getLinkType()]); } - $isReadOnlyUpSellItems = false; foreach ($linkTypes as $linkType => $readonly) { - $isReadOnlyRelatedItems = $readonly && $linkType === 'related' || - ($isReadOnlyUpSellItems = $readonly && $linkType === 'upsell'); - if ($isReadOnlyRelatedItems && $isReadOnlyUpSellItems) { + $isReadOnlyLinks = $readonly && in_array($linkType, ['upsell', 'related']); + if ($isReadOnlyLinks) { $productLinks = null; break; } else { From 1c4fe6e9e21e70fdb81da20984ce20c9491b2c1a Mon Sep 17 00:00:00 2001 From: Alexandra Zota Date: Mon, 15 Apr 2024 14:48:09 +0300 Subject: [PATCH 52/56] AC-9552: fix for missing wizard steps for configurable product --- .../templates/catalog/product/edit/super/wizard-ajax.phtml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/wizard-ajax.phtml b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/wizard-ajax.phtml index 9d0e78d6ad14c..55694a6d4909a 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/wizard-ajax.phtml +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/super/wizard-ajax.phtml @@ -20,7 +20,7 @@ $attributes = $block->getProductAttributes(); getData('config/dataScope'); $nameStep = /* @noEscape */ $block->getData('config/nameStepWizard'); $scriptString = <<