Skip to content

Commit dbbf519

Browse files
committed
ACP2E-13: Customer shopping cart in admin - Multi store
- fix - add test - add missing actionGroups
1 parent 7431f26 commit dbbf519

File tree

9 files changed

+377
-26
lines changed

9 files changed

+377
-26
lines changed

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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])) {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
11+
<section name="AdminCustomerCartSection">
12+
<element name="configureCartItem" type="button" selector="#customer_cart_grid_table tbody tr:nth-of-type({{row}}) .col-action .configure-item-link" parameterized="true" timeout="5"/>
13+
<element name="slidePanelFirstOptionDropdown" type="select" selector="aside[role='dialog'] #product_composite_configure select"/>
14+
<element name="slidePanelOkButton" type="button" selector="aside[role='dialog'] .page-actions .action-primary" timeout="5"/>
15+
</section>
16+
</sections>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminUpdatesConfigurableProductOptionsInCustomersCartTest">
12+
<annotations>
13+
<features value="Configurable Product"/>
14+
<stories value="Edit configurable product"/>
15+
<title value="Admin should be able to edit configurable product's options in Customers Cart"/>
16+
<description value="Verify that Admin can edit configurable product's options in Customers Cart"/>
17+
<severity value="AVERAGE"/>
18+
<testCaseId value="MC-43289"/>
19+
<group value="customer"/>
20+
<group value="ConfigurableProduct"/>
21+
</annotations>
22+
23+
<before>
24+
<!-- Set customer account to Global -->
25+
<magentoCLI command="config:set {{CustomerAccountShareGlobalConfigData.path}} {{CustomerAccountShareGlobalConfigData.value}}" stepKey="shareCustomerAccountsToGlobal"/>
26+
27+
<!-- Login as Admin -->
28+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
29+
30+
<!-- Create second website, store group, and store view -->
31+
<actionGroup ref="AdminCreateWebsiteActionGroup" stepKey="createNewWebsite">
32+
<argument name="newWebsiteName" value="{{NewWebSiteData.name}}"/>
33+
<argument name="websiteCode" value="{{NewWebSiteData.code}}"/>
34+
</actionGroup>
35+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createNewStore">
36+
<argument name="website" value="{{NewWebSiteData.name}}"/>
37+
<argument name="storeGroupName" value="{{NewStoreData.name}}"/>
38+
<argument name="storeGroupCode" value="{{NewStoreData.code}}"/>
39+
</actionGroup>
40+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createNewStoreView">
41+
<argument name="StoreGroup" value="NewStoreData"/>
42+
<argument name="customStore" value="NewStoreViewData"/>
43+
</actionGroup>
44+
45+
<!-- Create customer -->
46+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
47+
48+
<!-- Create category -->
49+
<createData entity="_defaultCategory" stepKey="createCategory"/>
50+
51+
<!-- Create configurable product -->
52+
<createData entity="ApiConfigurableProduct" stepKey="createConfigProduct">
53+
<requiredEntity createDataKey="createCategory"/>
54+
</createData>
55+
56+
<!-- Create Attribute and two Options -->
57+
<createData entity="productAttributeWithTwoOptions" stepKey="createConfigProductAttribute"/>
58+
<createData entity="productAttributeOption1" stepKey="createConfigProductAttributeOption1">
59+
<requiredEntity createDataKey="createConfigProductAttribute"/>
60+
</createData>
61+
<createData entity="productAttributeOption2" stepKey="createConfigProductAttributeOption2">
62+
<requiredEntity createDataKey="createConfigProductAttribute"/>
63+
</createData>
64+
65+
<!-- Add to Default Set-->
66+
<createData entity="AddToDefaultSet" stepKey="createConfigAddToAttributeSet">
67+
<requiredEntity createDataKey="createConfigProductAttribute"/>
68+
</createData>
69+
70+
<!-- Get Configurable Attribute Options -->
71+
<getData entity="ProductAttributeOptionGetter" index="1" stepKey="getConfigAttributeOption1">
72+
<requiredEntity createDataKey="createConfigProductAttribute"/>
73+
</getData>
74+
<getData entity="ProductAttributeOptionGetter" index="2" stepKey="getConfigAttributeOption2">
75+
<requiredEntity createDataKey="createConfigProductAttribute"/>
76+
</getData>
77+
78+
<!-- Create tow Simple products as children options for Configurable -->
79+
<createData entity="ApiSimpleOne" stepKey="createFirstChildProduct">
80+
<requiredEntity createDataKey="createConfigProductAttribute"/>
81+
<requiredEntity createDataKey="getConfigAttributeOption1"/>
82+
<requiredEntity createDataKey="createCategory"/>
83+
</createData>
84+
<createData entity="ApiSimpleTwo" stepKey="createSecondChildProduct">
85+
<requiredEntity createDataKey="createConfigProductAttribute"/>
86+
<requiredEntity createDataKey="getConfigAttributeOption2"/>
87+
<requiredEntity createDataKey="createCategory"/>
88+
</createData>
89+
<createData entity="ConfigurableProductTwoOptions" stepKey="createConfigProductOption1">
90+
<requiredEntity createDataKey="createConfigProduct"/>
91+
<requiredEntity createDataKey="createConfigProductAttribute"/>
92+
<requiredEntity createDataKey="getConfigAttributeOption1"/>
93+
</createData>
94+
<createData entity="ConfigurableProductTwoOptions" stepKey="createConfigProductOption2">
95+
<requiredEntity createDataKey="createConfigProduct"/>
96+
<requiredEntity createDataKey="createConfigProductAttribute"/>
97+
<requiredEntity createDataKey="getConfigAttributeOption2"/>
98+
</createData>
99+
100+
<!-- Add child products to Configurable-->
101+
<createData entity="ConfigurableProductAddChild" stepKey="AddFirstChildProductToFirstConfigurable">
102+
<requiredEntity createDataKey="createConfigProduct"/>
103+
<requiredEntity createDataKey="createFirstChildProduct"/>
104+
</createData>
105+
<createData entity="ConfigurableProductAddChild" stepKey="AddSecondChildProductToFirstConfigurable">
106+
<requiredEntity createDataKey="createConfigProduct"/>
107+
<requiredEntity createDataKey="createSecondChildProduct"/>
108+
</createData>
109+
110+
<!-- Assign Configurable and both Child Products to Custom Website -->
111+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForProductOnAdmin">
112+
<argument name="product" value="$$createConfigProduct$$"/>
113+
</actionGroup>
114+
<actionGroup ref="CreatedProductConnectToWebsiteActionGroup" stepKey="processProductWebsites">
115+
<argument name="website" value="NewWebSiteData"/>
116+
<argument name="product" value="$$createConfigProduct$$"/>
117+
</actionGroup>
118+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForFirstChildProduct">
119+
<argument name="product" value="$$createFirstChildProduct$$"/>
120+
</actionGroup>
121+
<actionGroup ref="CreatedProductConnectToWebsiteActionGroup" stepKey="processFirstChildProduct">
122+
<argument name="website" value="NewWebSiteData"/>
123+
<argument name="product" value="$$createFirstChildProduct$$"/>
124+
</actionGroup>
125+
<actionGroup ref="SearchForProductOnBackendActionGroup" stepKey="searchForSecondChildProduct">
126+
<argument name="product" value="$$createSecondChildProduct$$"/>
127+
</actionGroup>
128+
<actionGroup ref="CreatedProductConnectToWebsiteActionGroup" stepKey="processSecondChildProduct">
129+
<argument name="website" value="NewWebSiteData"/>
130+
<argument name="product" value="$$createSecondChildProduct$$"/>
131+
</actionGroup>
132+
133+
<actionGroup ref="CliIndexerReindexActionGroup" stepKey="indexerReindexAfterCreate">
134+
<argument name="indices" value="catalog_product_price"/>
135+
</actionGroup>
136+
<actionGroup ref="CliCacheFlushActionGroup" stepKey="flushCache">
137+
<argument name="tags" value="config"/>
138+
</actionGroup>
139+
</before>
140+
141+
<after>
142+
<!-- Cleaning Customer's cart on both Websites -->
143+
<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToStorefrontPageForCustomWebsite"/>
144+
<actionGroup ref="RemoveProductFromMiniCartActionGroup" stepKey="clearShoppingCartForCustomWebsite">
145+
<argument name="productName" value="$createConfigProduct.name$"/>
146+
</actionGroup>
147+
<actionGroup ref="AdminSetWebsiteAsDefaultActionGroup" stepKey="setCustomWebsiteAsDefault">
148+
<argument name="websiteName" value="{{_defaultWebsite.name}}"/>
149+
</actionGroup>
150+
<actionGroup ref="StorefrontOpenHomePageActionGroup" stepKey="goToStorefrontPageForDefaultWebsite"/>
151+
<actionGroup ref="RemoveProductFromMiniCartActionGroup" stepKey="clearShoppingCartForDefaultWebsite">
152+
<argument name="productName" value="$createConfigProduct.name$"/>
153+
</actionGroup>
154+
155+
<!-- Delete Configurable and Child Products, Delete Category and Attribute -->
156+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteConfigurableProduct">
157+
<argument name="sku" value="$$createConfigProduct.sku$$"/>
158+
</actionGroup>
159+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteFirstChildProduct">
160+
<argument name="sku" value="$$createFirstChildProduct.sku$$"/>
161+
</actionGroup>
162+
<actionGroup ref="DeleteProductBySkuActionGroup" stepKey="deleteSecondChildProduct">
163+
<argument name="sku" value="$$createSecondChildProduct.sku$$"/>
164+
</actionGroup>
165+
<deleteData stepKey="deleteCategory" createDataKey="createCategory"/>
166+
<deleteData createDataKey="createConfigProductAttribute" stepKey="deleteConfigProductAttribute"/>
167+
168+
<!-- Delete second Website -->
169+
<actionGroup ref="AdminDeleteWebsiteActionGroup" stepKey="deleteNewWebsite">
170+
<argument name="websiteName" value="{{NewWebSiteData.name}}"/>
171+
</actionGroup>
172+
173+
<!-- Set customer account to Per Website, Logout -->
174+
<magentoCLI command="config:set {{CustomerAccountShareWebsiteConfigData.path}} {{CustomerAccountShareWebsiteConfigData.value}}" stepKey="shareCustomerAccountsToPerWebsite"/>
175+
<actionGroup ref="AdminLogoutActionGroup" stepKey="amOnLogoutPage"/>
176+
</after>
177+
178+
<!-- Login as customer -->
179+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="loginToStorefrontAccount">
180+
<argument name="Customer" value="$$createCustomer$$"/>
181+
</actionGroup>
182+
183+
<!-- Add configurable product to the cart -->
184+
<actionGroup ref="StorefrontAddConfigurableProductToTheCartActionGroup" stepKey="addConfigurableProductToCartOnDefaultWebsite">
185+
<argument name="urlKey" value="$$createConfigProduct.custom_attributes[url_key]$$" />
186+
<argument name="productAttribute" value="$$createConfigProductAttribute.default_value$$"/>
187+
<argument name="productOption" value="$$getConfigAttributeOption1.value$$"/>
188+
<argument name="qty" value="1"/>
189+
</actionGroup>
190+
191+
<actionGroup ref="AdminSetWebsiteAsDefaultActionGroup" stepKey="setCustomWebsiteAsDefault">
192+
<argument name="websiteName" value="{{NewWebSiteData.name}}"/>
193+
</actionGroup>
194+
195+
<actionGroup ref="StorefrontAddConfigurableProductToTheCartActionGroup" stepKey="addConfigurableProductToCartOnCustomWebsite">
196+
<argument name="urlKey" value="$$createConfigProduct.custom_attributes[url_key]$$" />
197+
<argument name="productAttribute" value="$$createConfigProductAttribute.default_value$$"/>
198+
<argument name="productOption" value="$$getConfigAttributeOption1.value$$"/>
199+
<argument name="qty" value="1"/>
200+
</actionGroup>
201+
202+
<!-- Go to shopping cart of Customer in Admin-->
203+
<actionGroup ref="AdminOpenCustomerEditPageActionGroup" stepKey="openCustomerEditPage">
204+
<argument name="customerId" value="$$createCustomer.id$$"/>
205+
</actionGroup>
206+
<actionGroup ref="AdminOpenShoppingCartTabFromCustomerEditPageActionGroup" stepKey="openShoppingCartTabFromCustomerEditPage"/>
207+
208+
<!-- Perform Assertions. That Product Options correctly updated after being changed by Admin for Customer carts on both websites -->
209+
<click selector="{{AdminCustomerCartSection.configureCartItem('1')}}" stepKey="configureProductOfCustomWebsite"/>
210+
<selectOption selector="{{AdminCustomerCartSection.slidePanelFirstOptionDropdown}}" userInput="$$getConfigAttributeOption2.value$$" stepKey="selectOptionForCustomWebsite"/>
211+
<click selector="{{AdminCustomerCartSection.slidePanelOkButton}}" stepKey="clickOk1"/>
212+
<grabTextFrom selector="{{AdminCustomerCartSection.productName('1')}}" stepKey="grabProductName1"/>
213+
<assertStringContainsString stepKey="assertProductOption1">
214+
<actualResult type="const">$grabProductName1</actualResult>
215+
<expectedResult type="const">$$getConfigAttributeOption2.label$$</expectedResult>
216+
</assertStringContainsString>
217+
<selectOption selector="{{AdminCustomerCartSection.websiteFilter}}" userInput="{{_defaultWebsite.name}}" stepKey="selectDefaultWebsite"/>
218+
<waitForPageLoad stepKey="waitForPageLoadingCompleteAfterWebsiteSwitched"/>
219+
<click selector="{{AdminCustomerCartSection.configureCartItem('1')}}" stepKey="configureProductOfDefaultWebsite"/>
220+
<selectOption selector="{{AdminCustomerCartSection.slidePanelFirstOptionDropdown}}" userInput="$$getConfigAttributeOption2.value$$" stepKey="selectOptionForDefaultWebsite"/>
221+
<click selector="{{AdminCustomerCartSection.slidePanelOkButton}}" stepKey="clickOk2"/>
222+
<grabTextFrom selector="{{AdminCustomerCartSection.productName('1')}}" stepKey="grabProductName2"/>
223+
<assertStringContainsString stepKey="assertProductOption2">
224+
<actualResult type="const">$grabProductName2</actualResult>
225+
<expectedResult type="const">$$getConfigAttributeOption2.label$$</expectedResult>
226+
</assertStringContainsString>
227+
</test>
228+
</tests>

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

Lines changed: 21 additions & 10 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
{
@@ -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
}

0 commit comments

Comments
 (0)