-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MAGETWO-91330: [B2B] The product total price value on the second webs…
…ite is as on the default website - reverted fix from community PR #11165 - issue #7582 is fixed via plugin on store view switching
- Loading branch information
Showing
5 changed files
with
265 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Quote\Plugin; | ||
|
||
use Magento\Checkout\Model\Session; | ||
use Magento\Quote\Model\QuoteRepository; | ||
use Magento\Store\Api\Data\StoreInterface; | ||
use Magento\Store\Api\StoreCookieManagerInterface; | ||
|
||
/** | ||
* Updates quote store id. | ||
*/ | ||
class UpdateQuoteStore | ||
{ | ||
/** | ||
* @var QuoteRepository | ||
*/ | ||
private $quoteRepository; | ||
|
||
/** | ||
* @var Session | ||
*/ | ||
private $checkoutSession; | ||
|
||
/** | ||
* @param QuoteRepository $quoteRepository | ||
* @param Session $checkoutSession | ||
*/ | ||
public function __construct( | ||
QuoteRepository $quoteRepository, | ||
Session $checkoutSession | ||
) { | ||
$this->quoteRepository = $quoteRepository; | ||
$this->checkoutSession = $checkoutSession; | ||
} | ||
|
||
/** | ||
* Update store id in active quote after store view switching. | ||
* | ||
* @param StoreCookieManagerInterface $subject | ||
* @param null $result | ||
* @param StoreInterface $store | ||
* @return void | ||
* @SuppressWarnings(PHPMD.UnusedFormalParameter) | ||
*/ | ||
public function afterSetStoreCookie( | ||
StoreCookieManagerInterface $subject, | ||
$result, | ||
StoreInterface $store | ||
) { | ||
$storeCodeFromCookie = $subject->getStoreCodeFromCookie(); | ||
if (null === $storeCodeFromCookie) { | ||
return; | ||
} | ||
|
||
$quote = $this->checkoutSession->getQuote(); | ||
if ($quote->getIsActive() && $store->getCode() != $storeCodeFromCookie) { | ||
$quote->setStoreId( | ||
$store->getId() | ||
); | ||
$this->quoteRepository->save($quote); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> | ||
<type name="Magento\Quote\Plugin\UpdateQuoteStore"> | ||
<arguments> | ||
<argument name="quoteRepository" xsi:type="object">Magento\Quote\Model\QuoteRepository\Proxy</argument> | ||
<argument name="checkoutSession" xsi:type="object">Magento\Checkout\Model\Session\Proxy</argument> | ||
</arguments> | ||
</type> | ||
<type name="Magento\Store\Api\StoreCookieManagerInterface"> | ||
<plugin name="update_quote_store_after_switch_store_view" type="Magento\Quote\Plugin\UpdateQuoteStore"/> | ||
</type> | ||
</config> |
130 changes: 130 additions & 0 deletions
130
dev/tests/integration/testsuite/Magento/Quote/Model/Plugin/UpdateQuoteStoreTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\Quote\Model\Plugin; | ||
|
||
use Magento\Checkout\Model\Session; | ||
use Magento\Framework\Api\SearchCriteriaBuilder; | ||
use Magento\FunctionalTestingFramework\ObjectManagerInterface; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Model\Quote; | ||
use Magento\Store\Api\Data\StoreInterface; | ||
use Magento\Store\Api\StoreCookieManagerInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\Store\Model\StoreRepository; | ||
use Magento\TestFramework\Helper\Bootstrap as BootstrapHelper; | ||
|
||
/** | ||
* @magentoAppArea frontend | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class UpdateQuoteStoreTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var CartRepositoryInterface | ||
*/ | ||
private $quoteRepository; | ||
|
||
protected function setUp() | ||
{ | ||
$this->objectManager = BootstrapHelper::getObjectManager(); | ||
$this->quoteRepository = $this->objectManager->create(CartRepositoryInterface::class); | ||
} | ||
|
||
/** | ||
* Tests that active quote store id updates after store cookie change. | ||
* | ||
* @magentoDataFixture Magento/Quote/_files/empty_quote.php | ||
* @magentoDataFixture Magento/Store/_files/second_store.php | ||
* @throws \ReflectionException | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function testUpdateQuoteStoreAfterChangeStoreCookie() | ||
{ | ||
$secondStoreCode = 'fixture_second_store'; | ||
$reservedOrderId = 'reserved_order_id'; | ||
|
||
/** @var StoreManagerInterface $storeManager */ | ||
$storeManager = $this->objectManager->get(StoreManagerInterface::class); | ||
$currentStore = $storeManager->getStore(); | ||
|
||
$quote = $this->getQuote($reservedOrderId); | ||
$this->assertEquals( | ||
$currentStore->getId(), | ||
$quote->getStoreId(), | ||
'Current store id and quote store id are not match' | ||
); | ||
|
||
/** @var Session $checkoutSession */ | ||
$checkoutSession = $this->objectManager->get(Session::class); | ||
$checkoutSession->setQuoteId($quote->getId()); | ||
|
||
$storeRepository = $this->objectManager->create(StoreRepository::class); | ||
$secondStore = $storeRepository->get($secondStoreCode); | ||
|
||
$storeCookieManager = $this->getStoreCookieManager($currentStore); | ||
$storeCookieManager->setStoreCookie($secondStore); | ||
|
||
$updatedQuote = $this->getQuote($reservedOrderId); | ||
$this->assertEquals( | ||
$secondStore->getId(), | ||
$updatedQuote->getStoreId(), | ||
'Active quote store id should be equal second store id' | ||
); | ||
} | ||
|
||
/** | ||
* Retrieves quote by reserved order id. | ||
* | ||
* @param string $reservedOrderId | ||
* @return Quote | ||
*/ | ||
private function getQuote(string $reservedOrderId): Quote | ||
{ | ||
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */ | ||
$searchCriteriaBuilder = $this->objectManager->get(SearchCriteriaBuilder::class); | ||
$searchCriteria = $searchCriteriaBuilder->addFilter('reserved_order_id', $reservedOrderId) | ||
->create(); | ||
|
||
$items = $this->quoteRepository->getList($searchCriteria)->getItems(); | ||
|
||
return array_pop($items); | ||
} | ||
|
||
/** | ||
* Returns instance of StoreCookieManagerInterface with mocked cookieManager dependency. | ||
* | ||
* Mock is needed since integration test framework use own cookie manager with | ||
* behavior that differs from real environment. | ||
* | ||
* @param $currentStore | ||
* @return StoreCookieManagerInterface | ||
* @throws \ReflectionException | ||
*/ | ||
private function getStoreCookieManager(StoreInterface $currentStore): StoreCookieManagerInterface | ||
{ | ||
/** @var StoreCookieManagerInterface $storeCookieManager */ | ||
$storeCookieManager = $this->objectManager->get(StoreCookieManagerInterface::class); | ||
$cookieManagerMock = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\PhpCookieManager::class) | ||
->disableOriginalConstructor() | ||
->getMock(); | ||
$cookieManagerMock->method('getCookie') | ||
->willReturn($currentStore->getCode()); | ||
|
||
$reflection = new \ReflectionClass($storeCookieManager); | ||
$cookieManager = $reflection->getProperty('cookieManager'); | ||
$cookieManager->setAccessible(true); | ||
$cookieManager->setValue($storeCookieManager, $cookieManagerMock); | ||
|
||
return $storeCookieManager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters