Skip to content

Commit d9ba0b7

Browse files
Merge remote-tracking branch 'origin/2.4.1-develop' into MC-37313
2 parents 49b2bd0 + 1d47699 commit d9ba0b7

File tree

9 files changed

+292
-16
lines changed

9 files changed

+292
-16
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
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="AdminDeletedCategoryNotShownAsAvailableOnProductPageTest">
12+
<annotations>
13+
<features value="Catalog"/>
14+
<stories value="Delete categories"/>
15+
<title value="Deleted Category not shown as available on Product page"/>
16+
<description value="Deleted category not shown as available Category on Product edit page"/>
17+
<severity value="MAJOR"/>
18+
<testCaseId value="MC-37121"/>
19+
<group value="Catalog"/>
20+
</annotations>
21+
<before>
22+
<createData entity="_defaultCategory" stepKey="createCategory"/>
23+
<createData entity="_defaultProduct" stepKey="createProduct">
24+
<requiredEntity createDataKey="createCategory"/>
25+
</createData>
26+
27+
<actionGroup ref="AdminLoginActionGroup" stepKey="logInAsAdmin"/>
28+
</before>
29+
<after>
30+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/>
31+
32+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
33+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
34+
</after>
35+
36+
<!-- Create Category -->
37+
<actionGroup ref="GoToCreateCategoryPageActionGroup" stepKey="goToCreateCategoryPage"/>
38+
<actionGroup ref="FillCategoryNameAndUrlKeyAndSaveActionGroup" stepKey="fillCategoryForm">
39+
<argument name="categoryName" value="additional"/>
40+
<argument name="categoryUrlKey" value=""/>
41+
</actionGroup>
42+
43+
<!-- Check if Category present on Product page -->
44+
<actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="navigateToProductPage">
45+
<argument name="productId" value="$$createProduct.id$$"/>
46+
</actionGroup>
47+
<waitForPageLoad time="60" stepKey="waitForProductPageLoad"/>
48+
<actionGroup ref="AdminProductFormCategoryExistInCategoryListActionGroup" stepKey="checkExistCategoryInList">
49+
<argument name="categoryName" value="$$createCategory.name$$"/>
50+
</actionGroup>
51+
52+
<!-- Delete Category -->
53+
<actionGroup ref="AdminDeleteCategoryByNameActionGroup" stepKey="deleteAdditionalCategory">
54+
<argument name="categoryName" value="additional"/>
55+
</actionGroup>
56+
57+
<!-- Check if Category absent on Product page -->
58+
<actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="navigateToProductPageAfterDelete">
59+
<argument name="productId" value="$$createProduct.id$$"/>
60+
</actionGroup>
61+
<waitForPageLoad time="60" stepKey="waitForProductPageLoadAfterDelete"/>
62+
<actionGroup ref="AdminProductFormCategoryNotExistInCategoryListActionGroup" stepKey="checkNotExistCategoryInList">
63+
<argument name="categoryName" value="additional"/>
64+
</actionGroup>
65+
</test>
66+
</tests>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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="AdminLoginAsCustomerLoginFromOrderPageManualChooseActionGroup">
12+
<annotations>
13+
<description>Verify Login as Customer Login action is works properly from Order page with manual Store View choose.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="orderId" type="string"/>
17+
<argument name="storeName" type="string" defaultValue="default"/>
18+
</arguments>
19+
20+
<amOnPage url="{{AdminOrderPage.url(orderId)}}" stepKey="gotoOrderPage"/>
21+
<waitForPageLoad stepKey="waitForCustomerPageLoad"/>
22+
<click selector="{{AdminOrderDetailsMainActionsSection.loginAsCustomer}}" stepKey="clickLoginAsCustomerLink"/>
23+
<see selector="{{AdminConfirmationModalSection.title}}" userInput="Login as Customer: Select Store" stepKey="seeModal"/>
24+
<see selector="{{AdminConfirmationModalSection.message}}" userInput="Actions taken while in &quot;Login as Customer&quot; will affect actual customer data." stepKey="seeModalMessage"/>
25+
<selectOption selector="{{AdminLoginAsCustomerConfirmationModalSection.store}}" userInput="{{storeName}}" stepKey="selectStore"/>
26+
<click selector="{{AdminConfirmationModalSection.ok}}" stepKey="clickLogin"/>
27+
<switchToNextTab stepKey="switchToNewTab"/>
28+
<waitForPageLoad stepKey="waitForPageLoad"/>
29+
</actionGroup>
30+
</actionGroups>
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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="AdminLoginAsCustomerManualChooseFromOrderPageTest">
12+
<annotations>
13+
<features value="Login as Customer"/>
14+
<stories value="Select Store based on 'Store View To Login In' setting"/>
15+
<title
16+
value="Admin user directly login into customer account with store View To Login In = Manual Choose on Order Page"/>
17+
<description
18+
value="Verify admin user can directly login into customer account to Custom store view when Store View To Login In = Manual Choose on Order Page"/>
19+
<severity value="CRITICAL"/>
20+
<group value="login_as_customer"/>
21+
</annotations>
22+
<before>
23+
<createData entity="Simple_US_Customer_Assistance_Allowed" stepKey="createCustomer"/>
24+
<createData entity="_defaultCategory" stepKey="createCategory"/>
25+
<createData entity="SimpleProduct" stepKey="createProduct">
26+
<requiredEntity createDataKey="createCategory"/>
27+
</createData>
28+
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 1"
29+
stepKey="enableLoginAsCustomer"/>
30+
<magentoCLI command="config:set {{LoginAsCustomerStoreViewLogin.path}} 1"
31+
stepKey="enableLoginAsCustomerManualChoose"/>
32+
<magentoCLI command="cache:flush config" stepKey="flushCacheBeforeTestRun"/>
33+
<actionGroup ref="AdminLoginActionGroup" stepKey="adminLogin"/>
34+
<actionGroup ref="AdminCreateNewStoreGroupActionGroup" stepKey="createCustomStore">
35+
<argument name="website" value="{{_defaultWebsite.name}}"/>
36+
<argument name="storeGroupName" value="{{customStoreGroup.name}}"/>
37+
<argument name="storeGroupCode" value="{{customStoreGroup.code}}"/>
38+
</actionGroup>
39+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createFirstCustomStoreView">
40+
<argument name="StoreGroup" value="customStoreGroup"/>
41+
<argument name="customStore" value="customStoreEN"/>
42+
</actionGroup>
43+
<actionGroup ref="AdminCreateStoreViewActionGroup" stepKey="createSecondCustomStoreView">
44+
<argument name="StoreGroup" value="customStoreGroup"/>
45+
<argument name="customStore" value="customStoreFR"/>
46+
</actionGroup>
47+
</before>
48+
<after>
49+
<actionGroup ref="DeleteCustomStoreActionGroup" stepKey="deleteCustomStore">
50+
<argument name="storeGroupName" value="customStoreGroup.name"/>
51+
</actionGroup>
52+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logout"/>
53+
<magentoCLI command="config:set {{LoginAsCustomerConfigDataEnabled.path}} 0"
54+
stepKey="disableLoginAsCustomer"/>
55+
<magentoCLI command="config:set {{LoginAsCustomerStoreViewLogin.path}} 0"
56+
stepKey="enableLoginAsCustomerAutoDetection"/>
57+
<magentoCLI command="cache:flush config" stepKey="flushCacheAfterTestRun"/>
58+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
59+
<deleteData createDataKey="createProduct" stepKey="deleteProduct"/>
60+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
61+
</after>
62+
63+
<!-- Create order -->
64+
<actionGroup ref="CreateOrderInStoreActionGroup" stepKey="createOrder">
65+
<argument name="product" value="$$createProduct$$"/>
66+
<argument name="customer" value="$$createCustomer$$"/>
67+
<argument name="storeView" value="customStoreFR"/>
68+
</actionGroup>
69+
<grabFromCurrentUrl regex="~/order_id/(\d+)/~" stepKey="grabOrderId"/>
70+
71+
<!-- Login as Customer from Order page -->
72+
<actionGroup ref="AdminLoginAsCustomerLoginFromOrderPageManualChooseActionGroup"
73+
stepKey="loginAsCustomerFromOrderPage">
74+
<argument name="orderId" value="{$grabOrderId}"/>
75+
<argument name="storeName" value="{{customStoreGroup.name}}"/>
76+
</actionGroup>
77+
78+
<!-- Assert Customer logged on on custom store view -->
79+
<actionGroup ref="StorefrontAssertLoginAsCustomerLoggedInActionGroup" stepKey="assertLoggedInFromCustomerGird">
80+
<argument name="customerFullName" value="$$createCustomer.firstname$$ $$createCustomer.lastname$$"/>
81+
<argument name="customerEmail" value="$$createCustomer.email$$"/>
82+
</actionGroup>
83+
<actionGroup ref="StorefrontAssertCustomerOnStoreViewActionGroup" stepKey="assertCustomStoreView">
84+
<argument name="storeViewName" value="{{customStoreEN.name}}"/>
85+
</actionGroup>
86+
87+
<!-- Log out Customer and close tab -->
88+
<actionGroup ref="StorefrontSignOutAndCloseTabActionGroup" stepKey="signOutAndCloseTab"/>
89+
</test>
90+
</tests>

app/code/Magento/LoginAsCustomer/Test/Mftf/Test/AdminUIShownIfLoginAsCustomerEnabledTest.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,7 @@
5959
<argument name="product" value="$$createSimpleProduct$$"/>
6060
<argument name="customer" value="$$createCustomer$$"/>
6161
</actionGroup>
62-
<grabTextFrom selector="{{AdminOrderDetailsInformationSection.orderId}}" stepKey="grabOrderId"/>
63-
<actionGroup ref="FilterOrderGridByIdActionGroup" stepKey="filterOrderGridById">
64-
<argument name="orderId" value="$grabOrderId"/>
65-
</actionGroup>
62+
<grabFromCurrentUrl regex="~/order_id/(\d+)/~" stepKey="grabOrderId"/>
6663

6764
<!-- Verify Login as Customer Login action works correctly from Order page -->
6865
<actionGroup ref="AdminLoginAsCustomerLoginFromOrderPageActionGroup"

app/code/Magento/LoginAsCustomerAdminUi/Ui/Customer/Component/ConfirmationPopup/Options.php

Lines changed: 94 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,23 @@
1010
use Magento\Customer\Api\CustomerRepositoryInterface;
1111
use Magento\Customer\Api\Data\CustomerInterface;
1212
use Magento\Customer\Model\Config\Share;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\App\RequestInterface;
1415
use Magento\Framework\Data\OptionSourceInterface;
1516
use Magento\Framework\Escaper;
17+
use Magento\Framework\Exception\LocalizedException;
18+
use Magento\Sales\Api\CreditmemoRepositoryInterface;
19+
use Magento\Sales\Api\InvoiceRepositoryInterface;
20+
use Magento\Sales\Api\OrderRepositoryInterface;
21+
use Magento\Sales\Api\ShipmentRepositoryInterface;
1622
use Magento\Store\Model\Group;
1723
use Magento\Store\Model\System\Store as SystemStore;
1824
use Magento\Store\Model\Website;
1925

2026
/**
2127
* Store group options for Login As Customer confirmation pop-up.
28+
*
29+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2230
*/
2331
class Options implements OptionSourceInterface
2432
{
@@ -52,37 +60,75 @@ class Options implements OptionSourceInterface
5260
*/
5361
private $options;
5462

63+
/**
64+
* @var OrderRepositoryInterface
65+
*/
66+
private $orderRepository;
67+
68+
/**
69+
* @var InvoiceRepositoryInterface
70+
*/
71+
private $invoiceRepository;
72+
73+
/**
74+
* @var ShipmentRepositoryInterface
75+
*/
76+
private $shipmentRepository;
77+
78+
/**
79+
* @var CreditmemoRepositoryInterface
80+
*/
81+
private $creditmemoRepository;
82+
5583
/**
5684
* @param CustomerRepositoryInterface $customerRepository
5785
* @param Escaper $escaper
5886
* @param RequestInterface $request
5987
* @param Share $share
6088
* @param SystemStore $systemStore
89+
* @param OrderRepositoryInterface|null $orderRepository
90+
* @param InvoiceRepositoryInterface|null $invoiceRepository
91+
* @param ShipmentRepositoryInterface|null $shipmentRepository
92+
* @param CreditmemoRepositoryInterface|null $creditmemoRepository
6193
*/
6294
public function __construct(
6395
CustomerRepositoryInterface $customerRepository,
6496
Escaper $escaper,
6597
RequestInterface $request,
6698
Share $share,
67-
SystemStore $systemStore
99+
SystemStore $systemStore,
100+
?OrderRepositoryInterface $orderRepository = null,
101+
?InvoiceRepositoryInterface $invoiceRepository = null,
102+
?ShipmentRepositoryInterface $shipmentRepository = null,
103+
?CreditmemoRepositoryInterface $creditmemoRepository = null
68104
) {
69105
$this->customerRepository = $customerRepository;
70106
$this->escaper = $escaper;
71107
$this->request = $request;
72108
$this->share = $share;
73109
$this->systemStore = $systemStore;
110+
$this->orderRepository = $orderRepository
111+
?? ObjectManager::getInstance()->get(OrderRepositoryInterface::class);
112+
$this->invoiceRepository = $invoiceRepository
113+
?? ObjectManager::getInstance()->get(InvoiceRepositoryInterface::class);
114+
$this->shipmentRepository = $shipmentRepository
115+
?? ObjectManager::getInstance()->get(ShipmentRepositoryInterface::class);
116+
$this->creditmemoRepository = $creditmemoRepository
117+
?? ObjectManager::getInstance()->get(CreditmemoRepositoryInterface::class);
74118
}
75119

76120
/**
77121
* @inheritdoc
122+
*
123+
* @throws LocalizedException
78124
*/
79125
public function toOptionArray(): array
80126
{
81127
if ($this->options !== null) {
82128
return $this->options;
83129
}
84130

85-
$customerId = (int)$this->request->getParam('id');
131+
$customerId = $this->getCustomerId();
86132
$this->options = $this->generateCurrentOptions($customerId);
87133

88134
return $this->options;
@@ -167,4 +213,50 @@ private function fillStoreGroupOptions(Website $website, CustomerInterface $cust
167213

168214
return $groups;
169215
}
216+
217+
/**
218+
* Get Customer id from request param.
219+
*
220+
* @return int
221+
* @throws LocalizedException
222+
*/
223+
private function getCustomerId(): int
224+
{
225+
$customerId = $this->request->getParam('id');
226+
if ($customerId) {
227+
return (int)$customerId;
228+
}
229+
try {
230+
$orderId = $this->getOrderId();
231+
} catch (LocalizedException $exception) {
232+
throw new LocalizedException(__('Unable to get Customer ID.'));
233+
}
234+
235+
return (int)$this->orderRepository->get($orderId)->getCustomerId();
236+
}
237+
238+
/**
239+
* Get Order id from request param
240+
*
241+
* @return int
242+
* @throws LocalizedException
243+
*/
244+
private function getOrderId(): int
245+
{
246+
$orderId = $this->request->getParam('order_id');
247+
if ($orderId) {
248+
return (int)$orderId;
249+
}
250+
$shipmentId = $this->request->getParam('shipment_id');
251+
$creditmemoId = $this->request->getParam('creditmemo_id');
252+
$invoiceId = $this->request->getParam('invoice_id');
253+
if ($invoiceId) {
254+
return (int)$this->invoiceRepository->get($invoiceId)->getOrderId();
255+
} elseif ($shipmentId) {
256+
return (int)$this->shipmentRepository->get($shipmentId)->getOrderId();
257+
} elseif ($creditmemoId) {
258+
return (int)$this->creditmemoRepository->get($creditmemoId)->getOrderId();
259+
}
260+
throw new LocalizedException(__('Unable to get Order ID.'));
261+
}
170262
}

app/code/Magento/LoginAsCustomerAdminUi/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"magento/module-login-as-customer-frontend-ui": "*",
99
"magento/module-backend": "*",
1010
"magento/module-customer": "*",
11+
"magento/module-sales": "*",
1112
"magento/module-store": "*"
1213
},
1314
"suggest": {

app/code/Magento/PageCache/Model/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public function __construct(
121121
*/
122122
public function getType()
123123
{
124-
return (int)$this->_scopeConfig->getValue(self::XML_PAGECACHE_TYPE);
124+
return $this->_scopeConfig->getValue(self::XML_PAGECACHE_TYPE);
125125
}
126126

127127
/**

lib/internal/Magento/Framework/App/Cache/FlushCacheByTags.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,17 @@ public function aroundSave(AbstractResource $subject, \Closure $proceed, Abstrac
7777
* Clean cache on delete object
7878
*
7979
* @param AbstractResource $subject
80-
* @param \Closure $proceed
80+
* @param AbstractResource $result
8181
* @param AbstractModel $object
8282
* @return AbstractResource
8383
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
8484
*/
85-
public function aroundDelete(AbstractResource $subject, \Closure $proceed, AbstractModel $object): AbstractResource
86-
{
85+
public function afterDelete(
86+
AbstractResource $subject,
87+
AbstractResource $result,
88+
AbstractModel $object
89+
): AbstractResource {
8790
$tags = $this->tagResolver->getTags($object);
88-
$result = $proceed($object);
8991
$this->cleanCacheByTags($tags);
9092

9193
return $result;

0 commit comments

Comments
 (0)