Skip to content

Commit 22a4d00

Browse files
committed
Merge branch 'ACP2E-13' of https://github.com/magento-l3/magento2ce into PR-2021-12-21
2 parents 9497135 + cbc2890 commit 22a4d00

File tree

5 files changed

+275
-28
lines changed

5 files changed

+275
-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
}
Lines changed: 193 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,193 @@
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+
/**
28+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
29+
*/
30+
class ConfigureTest extends TestCase
31+
{
32+
/**
33+
* @var int
34+
*/
35+
private $quoteItemId;
36+
37+
/**
38+
* @var int
39+
*/
40+
private $websiteId;
41+
42+
/**
43+
* @var StoreManagerInterface|MockObject
44+
*/
45+
private $storeManager;
46+
47+
/**
48+
* @var Option|MockObject
49+
*/
50+
private $option;
51+
52+
/**
53+
* @var Composite|MockObject
54+
*/
55+
private $composite;
56+
57+
/**
58+
* @var CartRepositoryInterface|MockObject
59+
*/
60+
private $cartRepository;
61+
62+
/**
63+
* @var QuoteItemRetriever|MockObject
64+
*/
65+
private $quoteItemRetriever;
66+
67+
/**
68+
* @var Configure
69+
*/
70+
private $subject;
71+
72+
protected function setUp(): void
73+
{
74+
$customerId = 10;
75+
$this->quoteItemId = 20;
76+
$this->websiteId = 1;
77+
$request = $this->getMockBuilder(Http::class)
78+
->disableOriginalConstructor()
79+
->getMock();
80+
81+
$request->expects($this->exactly(3))
82+
->method('getParam')
83+
->withConsecutive(['customer_id'], ['id'], ['website_id'])
84+
->willReturnOnConsecutiveCalls($customerId, $this->quoteItemId, $this->websiteId);
85+
86+
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
87+
->disableOriginalConstructor()
88+
->getMock();
89+
$this->option = $this->getMockBuilder(Option::class)
90+
->disableOriginalConstructor()
91+
->getMock();
92+
$this->composite = $this->getMockBuilder(Composite::class)
93+
->disableOriginalConstructor()
94+
->getMock();
95+
$objectManager = $this->getMockBuilder(ObjectManagerInterface::class)
96+
->disableOriginalConstructor()
97+
->getMock();
98+
$objectManager->expects($this->any())
99+
->method('get')
100+
->willReturnOnConsecutiveCalls($this->storeManager, $this->composite);
101+
102+
$objectManager->expects($this->any())
103+
->method('create')
104+
->willReturn($this->option);
105+
106+
$context = $this->getMockBuilder(Context::class)
107+
->setMethods(['getRequest', 'getObjectManager'])
108+
->disableOriginalConstructor()
109+
->getMock();
110+
$context->expects($this->any())
111+
->method('getRequest')
112+
->willReturn($request);
113+
$context->expects($this->any())
114+
->method('getObjectManager')
115+
->willReturn($objectManager);
116+
117+
$this->cartRepository = $this->getMockBuilder(CartRepositoryInterface::class)
118+
->disableOriginalConstructor()
119+
->getMock();
120+
121+
$quoteFactory = $this->getMockBuilder(QuoteFactory::class)
122+
->disableOriginalConstructor()
123+
->getMock();
124+
125+
$this->quoteItemRetriever = $this->getMockBuilder(QuoteItemRetriever::class)
126+
->setMethods(['getById'])
127+
->disableOriginalConstructor()
128+
->getMock();
129+
130+
$objectManagerHelper = new ObjectManagerHelper($this);
131+
$this->subject = $objectManagerHelper->getObject(
132+
Configure::class,
133+
[
134+
'context' => $context,
135+
'quoteRepository' => $this->cartRepository,
136+
'quoteFactory' => $quoteFactory,
137+
'quoteItemRetriever' => $this->quoteItemRetriever
138+
]
139+
);
140+
}
141+
142+
/**
143+
* Test Execute method
144+
*/
145+
public function testExecute()
146+
{
147+
$quoteItem = $this->getMockBuilder(Item::class)
148+
->disableOriginalConstructor()
149+
->getMock();
150+
151+
$quote = $this->getMockBuilder(Quote::class)
152+
->setMethods(['setWebsite', 'getItemById'])
153+
->disableOriginalConstructor()
154+
->getMock();
155+
$quote->expects($this->once())
156+
->method('setWebsite')
157+
->willReturnSelf();
158+
$quote->expects($this->once())
159+
->method('getItemById')
160+
->willReturn($quoteItem);
161+
162+
$this->storeManager->expects($this->once())
163+
->method('getWebsite')
164+
->with($this->websiteId)
165+
->willReturnSelf();
166+
167+
$this->cartRepository->expects($this->once())
168+
->method('getForCustomer')
169+
->willReturn($quote);
170+
171+
$this->quoteItemRetriever->expects($this->once())
172+
->method('getById')
173+
->with($this->quoteItemId)
174+
->willReturn($quoteItem);
175+
176+
$collection = $this->getMockBuilder(Collection::class)
177+
->disableOriginalConstructor()
178+
->getMock();
179+
$collection->expects($this->once())
180+
->method('addItemFilter')
181+
->willReturnSelf();
182+
183+
$this->option->expects($this->once())
184+
->method('getCollection')
185+
->willReturn($collection);
186+
187+
$this->composite->expects($this->once())
188+
->method('renderConfigureResult')
189+
->willReturnSelf();
190+
191+
$this->subject->execute();
192+
}
193+
}

0 commit comments

Comments
 (0)