|
| 1 | +<?php |
| 2 | +/************************************************************************ |
| 3 | + * |
| 4 | + * ADOBE CONFIDENTIAL |
| 5 | + * ___________________ |
| 6 | + * |
| 7 | + * Copyright 2023 Adobe |
| 8 | + * All Rights Reserved. |
| 9 | + * |
| 10 | + * NOTICE: All information contained herein is, and remains |
| 11 | + * the property of Adobe and its suppliers, if any. The intellectual |
| 12 | + * and technical concepts contained herein are proprietary to Adobe |
| 13 | + * and its suppliers and are protected by all applicable intellectual |
| 14 | + * property laws, including trade secret and copyright laws. |
| 15 | + * Dissemination of this information or reproduction of this material |
| 16 | + * is strictly forbidden unless prior written permission is obtained |
| 17 | + * from Adobe. |
| 18 | + * ************************************************************************ |
| 19 | + */ |
| 20 | +declare(strict_types=1); |
| 21 | + |
| 22 | +namespace Magento\Sales\Controller\Order; |
| 23 | + |
| 24 | +use Magento\Checkout\Model\Session as CheckoutSession; |
| 25 | +use Magento\Customer\Model\Session; |
| 26 | +use Magento\Framework\Exception\LocalizedException; |
| 27 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 28 | +use Magento\Quote\Api\CartRepositoryInterface; |
| 29 | +use Magento\Quote\Api\Data\CartInterface; |
| 30 | +use Magento\Sales\Api\Data\OrderInterfaceFactory; |
| 31 | +use Magento\Store\Model\StoreManagerInterface; |
| 32 | +use Magento\TestFramework\Request; |
| 33 | +use Magento\TestFramework\TestCase\AbstractController; |
| 34 | + |
| 35 | +/** |
| 36 | + * Test for reorder with different store. |
| 37 | + * |
| 38 | + * @magentoAppArea frontend |
| 39 | + * @magentoDbIsolation enabled |
| 40 | + */ |
| 41 | +class ReorderWithDifferentStoreTest extends AbstractController |
| 42 | +{ |
| 43 | + /** @var CheckoutSession */ |
| 44 | + private $checkoutSession; |
| 45 | + |
| 46 | + /** @var OrderInterfaceFactory */ |
| 47 | + private $orderFactory; |
| 48 | + |
| 49 | + /** @var Session */ |
| 50 | + private $customerSession; |
| 51 | + |
| 52 | + /** @var CartRepositoryInterface */ |
| 53 | + private $quoteRepository; |
| 54 | + |
| 55 | + /** @var CartInterface */ |
| 56 | + private $quote; |
| 57 | + |
| 58 | + /** |
| 59 | + * @var StoreManagerInterface |
| 60 | + */ |
| 61 | + private $storeManager; |
| 62 | + |
| 63 | + /** |
| 64 | + * @var int |
| 65 | + */ |
| 66 | + private $currentStoreId; |
| 67 | + |
| 68 | + /** |
| 69 | + * @inheritdoc |
| 70 | + */ |
| 71 | + protected function setUp(): void |
| 72 | + { |
| 73 | + parent::setUp(); |
| 74 | + |
| 75 | + $this->checkoutSession = $this->_objectManager->get(CheckoutSession::class); |
| 76 | + $this->orderFactory = $this->_objectManager->get(OrderInterfaceFactory::class); |
| 77 | + $this->customerSession = $this->_objectManager->get(Session::class); |
| 78 | + $this->quoteRepository = $this->_objectManager->get(CartRepositoryInterface::class); |
| 79 | + $this->storeManager = $this->_objectManager->get(StoreManagerInterface::class); |
| 80 | + $this->currentStoreId = $this->storeManager->getStore()->getId(); |
| 81 | + } |
| 82 | + |
| 83 | + /** |
| 84 | + * @inheritdoc |
| 85 | + */ |
| 86 | + protected function tearDown(): void |
| 87 | + { |
| 88 | + if ($this->quote instanceof CartInterface) { |
| 89 | + $this->quoteRepository->delete($this->quote); |
| 90 | + } |
| 91 | + $this->customerSession->setCustomerId(null); |
| 92 | + $this->storeManager->setCurrentStore($this->currentStoreId); |
| 93 | + parent::tearDown(); |
| 94 | + } |
| 95 | + |
| 96 | + /** |
| 97 | + * Test when reorder from different store and global customer account |
| 98 | + * |
| 99 | + * @magentoConfßigFixture web/url/use_store 1 |
| 100 | + * @magentoConfigFixture customer/account_share/scope 0 |
| 101 | + * @magentoDataFixture Magento/Sales/_files/customer_order_with_simple_product.php |
| 102 | + * @magentoDataFixture Magento/Store/_files/second_store.php |
| 103 | + * |
| 104 | + * @return void |
| 105 | + * @throws LocalizedException |
| 106 | + * @throws NoSuchEntityException |
| 107 | + */ |
| 108 | + public function testReorderWithDifferentStoreAndGlobalCustomerAccount(): void |
| 109 | + { |
| 110 | + $this->checkoutSession->resetCheckout(); |
| 111 | + $this->storeManager->setCurrentStore('fixture_second_store'); |
| 112 | + $order = $this->orderFactory->create()->loadByIncrementId('55555555'); |
| 113 | + $orderNumber = (int) $order->getId(); |
| 114 | + $this->customerSession->setCustomerId($order->getCustomerId()); |
| 115 | + $this->getRequest()->setMethod(Request::METHOD_POST); |
| 116 | + $this->getRequest()->setParam('order_id', $orderNumber); |
| 117 | + $this->dispatch('sales/order/reorder/'); |
| 118 | + $this->assertRedirect($this->stringContains('checkout/cart')); |
| 119 | + $this->quote = $this->checkoutSession->getQuote(); |
| 120 | + $quoteItemsCollection = $this->quote->getAllItems(); |
| 121 | + $this->assertCount(0, $quoteItemsCollection); |
| 122 | + } |
| 123 | +} |
0 commit comments