Skip to content

Commit 0deaefb

Browse files
ENGCOM-6667: Checked if quote object contains id before looking for quote items #26489
- Merge Pull Request #26489 from rav-redchamps/magento2:issue-26437-customer-shopping-cart-tab - Merged commits: 1. 2312289 2. e9cb043 3. 8e2d9d4 4. 1dd3d90 5. 0173e34 6. a3dc450 7. 12b43c5 8. 58c4cc9 9. 907d0d6
2 parents 7404d9d + 907d0d6 commit 0deaefb

File tree

2 files changed

+116
-13
lines changed
  • app/code/Magento/Customer/Block/Adminhtml/Edit/Tab
  • dev/tests/integration/testsuite/Magento/Customer/Block/Adminhtml/Edit/Tab

2 files changed

+116
-13
lines changed

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,13 @@ protected function _prepareCollection()
105105
{
106106
$quote = $this->getQuote();
107107

108-
if ($quote) {
108+
if ($quote && $quote->getId()) {
109109
$collection = $quote->getItemsCollection(false);
110+
$collection->addFieldToFilter('parent_item_id', ['null' => true]);
110111
} else {
111112
$collection = $this->_dataCollectionFactory->create();
112113
}
113114

114-
$collection->addFieldToFilter('parent_item_id', ['null' => true]);
115-
116115
$this->setCollection($collection);
117116

118117
return parent::_prepareCollection();

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

Lines changed: 114 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,52 @@
55
*/
66
namespace Magento\Customer\Block\Adminhtml\Edit\Tab;
77

8+
use Magento\Backend\Block\Template\Context;
9+
use Magento\Backend\Model\Session\Quote as SessionQuote;
810
use Magento\Customer\Controller\RegistryConstants;
11+
use Magento\Framework\ObjectManagerInterface;
12+
use Magento\Framework\Registry;
13+
use Magento\Quote\Model\Quote;
14+
use Magento\Store\Model\StoreManagerInterface;
915

1016
/**
1117
* Magento\Customer\Block\Adminhtml\Edit\Tab\Cart
1218
*
1319
* @magentoAppArea adminhtml
20+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1421
*/
1522
class CartTest extends \PHPUnit\Framework\TestCase
1623
{
1724
const CUSTOMER_ID_VALUE = 1234;
1825

19-
/** @var \Magento\Backend\Block\Template\Context */
26+
/**
27+
* @var Context
28+
*/
2029
private $_context;
2130

22-
/** @var \Magento\Framework\Registry */
31+
/**
32+
* @var Registry
33+
*/
2334
private $_coreRegistry;
2435

25-
/** @var \Magento\Store\Model\StoreManagerInterface */
36+
/**
37+
* @var StoreManagerInterface
38+
*/
2639
private $_storeManager;
2740

28-
/** @var Cart */
41+
/**
42+
* @var Cart
43+
*/
2944
private $_block;
3045

31-
/** @var \Magento\Framework\ObjectManagerInterface */
46+
/**
47+
* @var ObjectManagerInterface
48+
*/
3249
private $_objectManager;
3350

51+
/**
52+
* @inheritdoc
53+
*/
3454
public function setUp()
3555
{
3656
$this->_objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
@@ -53,22 +73,96 @@ public function setUp()
5373
);
5474
}
5575

76+
/**
77+
* @inheritdoc
78+
*/
5679
public function tearDown()
5780
{
5881
$this->_coreRegistry->unregister(RegistryConstants::CURRENT_CUSTOMER_ID);
5982
}
6083

61-
public function testGetCustomerId()
84+
/**
85+
* Verify Grid with quote items
86+
*
87+
* @magentoDataFixture Magento/Sales/_files/quote_with_two_products_and_customer.php
88+
* @magentoDataFixture Magento/Customer/_files/customer.php
89+
* @dataProvider getQuoteDataProvider
90+
*
91+
* @param int $customerId
92+
* @param bool $guest
93+
* @param bool $contains
94+
* @return void
95+
*/
96+
public function testVerifyCollectionWithQuote(int $customerId, bool $guest, bool $contains): void
97+
{
98+
$session = $this->_objectManager->create(SessionQuote::class);
99+
$session->setCustomerId($customerId);
100+
$quoteFixture = $this->_objectManager->create(Quote::class);
101+
$quoteFixture->load('test01', 'reserved_order_id');
102+
$quoteFixture->setCustomerIsGuest($guest)
103+
->setCustomerId($customerId)
104+
->save();
105+
$this->_block->toHtml();
106+
if ($contains) {
107+
$this->assertContains(
108+
"We couldn't find any records",
109+
$this->_block->getGridParentHtml()
110+
);
111+
} else {
112+
$this->assertNotContains(
113+
"We couldn't find any records",
114+
$this->_block->getGridParentHtml()
115+
);
116+
}
117+
}
118+
119+
/**
120+
* Data provider for withQuoteTest
121+
*
122+
* @return array
123+
*/
124+
public function getQuoteDataProvider(): array
125+
{
126+
return [
127+
[
128+
6,
129+
false,
130+
true
131+
],
132+
[
133+
self::CUSTOMER_ID_VALUE,
134+
true,
135+
false
136+
],
137+
];
138+
}
139+
140+
/**
141+
* Verify Customer id
142+
*
143+
* @return void
144+
*/
145+
public function testGetCustomerId(): void
62146
{
63147
$this->assertEquals(self::CUSTOMER_ID_VALUE, $this->_block->getCustomerId());
64148
}
65149

66-
public function testGetGridUrl()
150+
/**
151+
* Verify get grid url
152+
*
153+
* @return void
154+
*/
155+
public function testGetGridUrl(): void
67156
{
68157
$this->assertContains('/backend/customer/index/cart', $this->_block->getGridUrl());
69158
}
70159

71-
public function testGetGridParentHtml()
160+
/**
161+
* Verify grid parent html
162+
*
163+
* @return void
164+
*/
165+
public function testGetGridParentHtml(): void
72166
{
73167
$this->_block = $this->_objectManager->get(
74168
\Magento\Framework\View\LayoutInterface::class
@@ -87,14 +181,24 @@ public function testGetGridParentHtml()
87181
);
88182
}
89183

90-
public function testGetRowUrl()
184+
/**
185+
* Verify row url
186+
*
187+
* @return void
188+
*/
189+
public function testGetRowUrl(): void
91190
{
92191
$row = new \Magento\Framework\DataObject();
93192
$row->setProductId(1);
94193
$this->assertContains('/backend/catalog/product/edit/id/1', $this->_block->getRowUrl($row));
95194
}
96195

97-
public function testGetHtml()
196+
/**
197+
* Verify get html
198+
*
199+
* @return void
200+
*/
201+
public function testGetHtml(): void
98202
{
99203
$html = $this->_block->toHtml();
100204
$this->assertContains("<div id=\"customer_cart_grid\"", $html);

0 commit comments

Comments
 (0)