Skip to content

Commit 866bc0b

Browse files
committed
ACP2E-13: Customer shopping cart in admin - Multi store
- fix - add test - add missing mftf actionGroups - add element to mftf section
1 parent 70870ed commit 866bc0b

File tree

7 files changed

+322
-28
lines changed

7 files changed

+322
-28
lines changed

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
3636
/**
3737
* Product type code
3838
*/
39-
const TYPE_CODE = 'configurable';
39+
public const TYPE_CODE = 'configurable';
4040

4141
/**
4242
* Cache key for Used Product Attribute Ids
@@ -117,45 +117,32 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
117117
protected $_scopeConfig;
118118

119119
/**
120-
* Catalog product type configurable
121-
*
122120
* @var \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable
123121
*/
124122
protected $_catalogProductTypeConfigurable;
125123

126124
/**
127-
* Attribute collection factory
128-
*
129-
* @var
130-
* \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\CollectionFactory
125+
* @var \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Attribute\CollectionFactory
131126
*/
132127
protected $_attributeCollectionFactory;
133128

134129
/**
135-
* Product collection factory
136-
*
137130
* @var \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\Configurable\Product\CollectionFactory
138131
*/
139132
protected $_productCollectionFactory;
140133

141134
/**
142-
* Configurable attribute factory
143-
*
144135
* @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable\AttributeFactory
145136
* @since 100.1.0
146137
*/
147138
protected $configurableAttributeFactory;
148139

149140
/**
150-
* Eav attribute factory
151-
*
152141
* @var \Magento\Catalog\Model\ResourceModel\Eav\AttributeFactory
153142
*/
154143
protected $_eavAttributeFactory;
155144

156145
/**
157-
* Type configurable factory
158-
*
159146
* @var \Magento\ConfigurableProduct\Model\ResourceModel\Product\Type\ConfigurableFactory
160147
* @since 100.1.0
161148
*/
@@ -192,8 +179,6 @@ class Configurable extends \Magento\Catalog\Model\Product\Type\AbstractType
192179
private $customerSession;
193180

194181
/**
195-
* Product factory
196-
*
197182
* @var ProductInterfaceFactory
198183
*/
199184
private $productFactory;
@@ -772,6 +757,9 @@ public function isSalable($product)
772757
if ($storeId instanceof \Magento\Store\Model\Store) {
773758
$storeId = $storeId->getId();
774759
}
760+
if ($storeId === null && $product->getStoreId()) {
761+
$storeId = $product->getStoreId();
762+
}
775763

776764
$sku = $product->getSku();
777765
if (isset($this->isSaleableBySku[$storeId][$sku])) {

app/code/Magento/Customer/Controller/Adminhtml/Cart/Product/Composite/Cart.php

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88

99
use Magento\Backend\App\Action;
1010
use Magento\Framework\Exception\LocalizedException;
11+
use Magento\Quote\Api\CartRepositoryInterface;
12+
use Magento\Quote\Model\Quote\Item;
13+
use Magento\Quote\Model\QuoteFactory;
14+
use Magento\Quote\Model\ResourceModel\QuoteItemRetriever;
1115

1216
/**
1317
* Catalog composite product configuration controller
14-
*
15-
* @author Magento Core Team <core@magentocommerce.com>
1618
*/
1719
abstract class Cart extends \Magento\Backend\App\Action
1820
{
@@ -21,7 +23,7 @@ abstract class Cart extends \Magento\Backend\App\Action
2123
*
2224
* @see _isAllowed()
2325
*/
24-
const ADMIN_RESOURCE = 'Magento_Customer::manage';
26+
public const ADMIN_RESOURCE = 'Magento_Customer::manage';
2527

2628
/**
2729
* Customer we're working with
@@ -40,32 +42,39 @@ abstract class Cart extends \Magento\Backend\App\Action
4042
/**
4143
* Quote item we're working with
4244
*
43-
* @var \Magento\Quote\Model\Quote\Item
45+
* @var Item
4446
*/
4547
protected $_quoteItem = null;
4648

4749
/**
48-
* @var \Magento\Quote\Api\CartRepositoryInterface
50+
* @var CartRepositoryInterface
4951
*/
5052
protected $quoteRepository;
5153

5254
/**
53-
* @var \Magento\Quote\Model\QuoteFactory
55+
* @var QuoteFactory
5456
*/
5557
protected $quoteFactory;
5658

59+
/**
60+
* @var QuoteItemRetriever
61+
*/
62+
private $quoteItemRetriever;
5763
/**
5864
* @param Action\Context $context
59-
* @param \Magento\Quote\Api\CartRepositoryInterface $quoteRepository
60-
* @param \Magento\Quote\Model\QuoteFactory $quoteFactory
65+
* @param CartRepositoryInterface $quoteRepository
66+
* @param QuoteFactory $quoteFactory
67+
* @param QuoteItemRetriever $quoteItemRetriever
6168
*/
6269
public function __construct(
6370
Action\Context $context,
64-
\Magento\Quote\Api\CartRepositoryInterface $quoteRepository,
65-
\Magento\Quote\Model\QuoteFactory $quoteFactory
71+
CartRepositoryInterface $quoteRepository,
72+
QuoteFactory $quoteFactory,
73+
QuoteItemRetriever $quoteItemRetriever
6674
) {
6775
$this->quoteRepository = $quoteRepository;
6876
$this->quoteFactory = $quoteFactory;
77+
$this->quoteItemRetriever = $quoteItemRetriever;
6978
parent::__construct($context);
7079
}
7180

@@ -86,7 +95,9 @@ protected function _initData()
8695
$websiteId = (int)$this->getRequest()->getParam('website_id');
8796

8897
try {
89-
$this->_quote = $this->quoteRepository->getForCustomer($this->_customerId);
98+
/** @var Item $quoteItem */
99+
$quoteItem = $this->quoteItemRetriever->getById($quoteItemId);
100+
$this->_quote = $this->quoteRepository->getForCustomer($this->_customerId, [$quoteItem->getStoreId()]);
90101
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
91102
$this->_quote = $this->quoteFactory->create();
92103
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
11+
<actionGroup name="AdminOpenShoppingCartTabFromCustomerEditPageActionGroup">
12+
<annotations>
13+
<description>Open Shopping Cart tab from Customer's edit page</description>
14+
</annotations>
15+
<waitForElementVisible selector="{{AdminCustomerInformationSection.shoppingCart}}" stepKey="waitForShoppingCartTab"/>
16+
<click selector="{{AdminCustomerInformationSection.shoppingCart}}" stepKey="clickShoppingCartTab"/>
17+
<waitForPageLoad stepKey="waitForPageLoad"/>
18+
<waitForElementVisible selector="{{AdminCustomerCartSection.grid}}" stepKey="waitForShoppingCartGrid"/>
19+
</actionGroup>
20+
</actionGroups>
Lines changed: 190 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Test\Unit\Controller\Adminhtml\Cart\Product\Composite\Cart;
9+
10+
use Magento\Backend\App\Action\Context;
11+
use Magento\Catalog\Helper\Product\Composite;
12+
use Magento\Customer\Controller\Adminhtml\Cart\Product\Composite\Cart\Configure;
13+
use Magento\Framework\App\Request\Http;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\Quote\Api\CartRepositoryInterface;
16+
use Magento\Quote\Model\Quote;
17+
use Magento\Quote\Model\Quote\Item;
18+
use Magento\Quote\Model\Quote\Item\Option;
19+
use Magento\Quote\Model\QuoteFactory;
20+
use Magento\Quote\Model\ResourceModel\Quote\Item\Option\Collection;
21+
use Magento\Quote\Model\ResourceModel\QuoteItemRetriever;
22+
use Magento\Store\Model\StoreManagerInterface;
23+
use PHPUnit\Framework\MockObject\MockObject;
24+
use PHPUnit\Framework\TestCase;
25+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
26+
27+
class ConfigureTest extends TestCase
28+
{
29+
/**
30+
* @var int
31+
*/
32+
private $quoteItemId;
33+
34+
/**
35+
* @var int
36+
*/
37+
private $websiteId;
38+
39+
/**
40+
* @var StoreManagerInterface|MockObject
41+
*/
42+
private $storeManager;
43+
44+
/**
45+
* @var Option|MockObject
46+
*/
47+
private $option;
48+
49+
/**
50+
* @var Composite|MockObject
51+
*/
52+
private $composite;
53+
54+
/**
55+
* @var CartRepositoryInterface|MockObject
56+
*/
57+
private $cartRepository;
58+
59+
/**
60+
* @var QuoteItemRetriever|MockObject
61+
*/
62+
private $quoteItemRetriever;
63+
64+
/**
65+
* @var Configure
66+
*/
67+
private $subject;
68+
69+
protected function setUp(): void
70+
{
71+
$customerId = 10;
72+
$this->quoteItemId = 20;
73+
$this->websiteId = 1;
74+
$request = $this->getMockBuilder(Http::class)
75+
->disableOriginalConstructor()
76+
->getMock();
77+
78+
$request->expects($this->exactly(3))
79+
->method('getParam')
80+
->withConsecutive(['customer_id'], ['id'], ['website_id'])
81+
->willReturnOnConsecutiveCalls($customerId, $this->quoteItemId, $this->websiteId);
82+
83+
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
84+
->disableOriginalConstructor()
85+
->getMock();
86+
$this->option = $this->getMockBuilder(Option::class)
87+
->disableOriginalConstructor()
88+
->getMock();
89+
$this->composite = $this->getMockBuilder(Composite::class)
90+
->disableOriginalConstructor()
91+
->getMock();
92+
$objectManager = $this->getMockBuilder(ObjectManagerInterface::class)
93+
->disableOriginalConstructor()
94+
->getMock();
95+
$objectManager->expects($this->any())
96+
->method('get')
97+
->willReturnOnConsecutiveCalls($this->storeManager, $this->composite);
98+
99+
$objectManager->expects($this->any())
100+
->method('create')
101+
->willReturn($this->option);
102+
103+
$context = $this->getMockBuilder(Context::class)
104+
->setMethods(['getRequest', 'getObjectManager'])
105+
->disableOriginalConstructor()
106+
->getMock();
107+
$context->expects($this->any())
108+
->method('getRequest')
109+
->willReturn($request);
110+
$context->expects($this->any())
111+
->method('getObjectManager')
112+
->willReturn($objectManager);
113+
114+
$this->cartRepository = $this->getMockBuilder(CartRepositoryInterface::class)
115+
->disableOriginalConstructor()
116+
->getMock();
117+
118+
$quoteFactory = $this->getMockBuilder(QuoteFactory::class)
119+
->disableOriginalConstructor()
120+
->getMock();
121+
122+
$this->quoteItemRetriever = $this->getMockBuilder(QuoteItemRetriever::class)
123+
->setMethods(['getById'])
124+
->disableOriginalConstructor()
125+
->getMock();
126+
127+
$objectManagerHelper = new ObjectManagerHelper($this);
128+
$this->subject = $objectManagerHelper->getObject(
129+
Configure::class,
130+
[
131+
'context' => $context,
132+
'quoteRepository' => $this->cartRepository,
133+
'quoteFactory' => $quoteFactory,
134+
'quoteItemRetriever' => $this->quoteItemRetriever
135+
]
136+
);
137+
}
138+
139+
/**
140+
* Test Execute method
141+
*/
142+
public function testExecute()
143+
{
144+
$quoteItem = $this->getMockBuilder(Item::class)
145+
->disableOriginalConstructor()
146+
->getMock();
147+
148+
$quote = $this->getMockBuilder(Quote::class)
149+
->setMethods(['setWebsite', 'getItemById'])
150+
->disableOriginalConstructor()
151+
->getMock();
152+
$quote->expects($this->once())
153+
->method('setWebsite')
154+
->willReturnSelf();
155+
$quote->expects($this->once())
156+
->method('getItemById')
157+
->willReturn($quoteItem);
158+
159+
$this->storeManager->expects($this->once())
160+
->method('getWebsite')
161+
->with($this->websiteId)
162+
->willReturnSelf();
163+
164+
$this->cartRepository->expects($this->once())
165+
->method('getForCustomer')
166+
->willReturn($quote);
167+
168+
$this->quoteItemRetriever->expects($this->once())
169+
->method('getById')
170+
->with($this->quoteItemId)
171+
->willReturn($quoteItem);
172+
173+
$collection = $this->getMockBuilder(Collection::class)
174+
->disableOriginalConstructor()
175+
->getMock();
176+
$collection->expects($this->once())
177+
->method('addItemFilter')
178+
->willReturnSelf();
179+
180+
$this->option->expects($this->once())
181+
->method('getCollection')
182+
->willReturn($collection);
183+
184+
$this->composite->expects($this->once())
185+
->method('renderConfigureResult')
186+
->willReturnSelf();
187+
188+
$this->subject->execute();
189+
}
190+
}

0 commit comments

Comments
 (0)