Skip to content

Commit e6eea0e

Browse files
committed
ACP2E-3025: Admin User with limited Role Resources unable to view Shopping Carts
- with test
1 parent 71492c2 commit e6eea0e

File tree

2 files changed

+39
-5
lines changed
  • app/code/Magento/Customer/Block/Adminhtml/Edit/Tab
  • dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/Cart

2 files changed

+39
-5
lines changed

app/code/Magento/Customer/Block/Adminhtml/Edit/Tab/Cart.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Magento\Framework\App\ObjectManager;
1616
use Magento\Framework\Data\CollectionFactory;
1717
use Magento\Framework\Data\FormFactory;
18+
use Magento\Framework\Exception\LocalizedException;
1819
use Magento\Framework\Exception\NoSuchEntityException;
1920
use Magento\Framework\Registry;
2021
use Magento\Quote\Api\CartRepositoryInterface;
@@ -32,8 +33,6 @@
3233
class Cart extends Extended
3334
{
3435
/**
35-
* Core registry
36-
*
3736
* @var Registry
3837
*/
3938
protected $_coreRegistry = null;
@@ -266,16 +265,16 @@ public function getRowUrl($row)
266265
/**
267266
* Get the quote of the cart
268267
*
269-
* @return \Magento\Quote\Model\Quote
268+
* @return Quote
269+
* @throws LocalizedException
270270
*/
271271
protected function getQuote()
272272
{
273273
if (null === $this->quote) {
274274
$customerId = $this->getCustomerId();
275275
$websiteId = $this->getWebsiteId() ?:
276276
$this->_storeManager->getDefaultStoreView()->getWebsiteId();
277-
$storeIds = $this->_storeManager->getWebsite($websiteId)->getStoreIds();
278-
277+
$storeIds = $this->getAssociatedStoreIds((int) $websiteId);
279278
try {
280279
$this->quote = $this->quoteRepository->getForCustomer($customerId, $storeIds);
281280
} catch (NoSuchEntityException $e) {
@@ -334,4 +333,20 @@ private function getWebsiteFilterHtml(): string
334333
{
335334
return $this->getChildHtml('website_filter_block');
336335
}
336+
337+
/**
338+
* Get website associated store IDs
339+
*
340+
* @param int $websiteId
341+
* @return array
342+
* @throws LocalizedException
343+
*/
344+
private function getAssociatedStoreIds(int $websiteId): array
345+
{
346+
$storeIds = $this->_storeManager->getWebsite($websiteId)->getStoreIds();
347+
if (empty($this->getWebsiteId()) && !empty($this->_storeManager->getWebsite()->getStoreIds())) {
348+
$storeIds = $this->_storeManager->getWebsite()->getStoreIds();
349+
}
350+
return $storeIds;
351+
}
337352
}

dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab/Cart/CollectionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,25 @@ public function testCollectionOnDifferentStores(): void
8686
$this->assertCollection($collectionSecondWebsite, 'Simple Product on second website');
8787
}
8888

89+
/**
90+
* Test case to check active quote on non default website
91+
*
92+
* @magentoDataFixture Magento/Checkout/_files/quote_with_address_saved.php
93+
* @magentoDataFixture Magento/Checkout/_files/active_quote_not_default_website.php
94+
*
95+
* @return void
96+
*/
97+
public function testCollectionOnNonDefaultStores(): void
98+
{
99+
$this->registry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
100+
$this->registry->register(RegistryConstants::CURRENT_CUSTOMER_ID, 1);
101+
$collection = $this->executeInStoreContext->execute(
102+
'fixture_second_store',
103+
[$this->layout->createBlock(Cart::class), 'getPreparedCollection']
104+
);
105+
$this->assertCount(0, $collection);
106+
}
107+
89108
/**
90109
* Check is collection match expected value
91110
*

0 commit comments

Comments
 (0)