Skip to content

Commit db0bf0f

Browse files
ENGCOM-5637: Fixed product back redirect navigate from customer view cart product #24089
- Merge Pull Request #24089 from ravi-chandra3197/magento2:patch-product-back-redirect - Merged commits: 1. cd8f6bf 2. b2e78e3
2 parents 52f9fd4 + b2e78e3 commit db0bf0f

File tree

6 files changed

+140
-5
lines changed

6 files changed

+140
-5
lines changed

app/code/Magento/Catalog/Block/Adminhtml/Product/Edit/Button/Back.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,32 @@
1111
class Back extends Generic
1212
{
1313
/**
14+
* Get Button Data
15+
*
1416
* @return array
1517
*/
1618
public function getButtonData()
1719
{
1820
return [
1921
'label' => __('Back'),
20-
'on_click' => sprintf("location.href = '%s';", $this->getUrl('*/*/')),
22+
'on_click' => sprintf("location.href = '%s';", $this->getBackUrl()),
2123
'class' => 'back',
2224
'sort_order' => 10
2325
];
2426
}
27+
/**
28+
* Get URL for back
29+
*
30+
* @return string
31+
*/
32+
private function getBackUrl()
33+
{
34+
if ($this->context->getRequestParam('customerId')) {
35+
return $this->getUrl(
36+
'customer/index/edit',
37+
['id' => $this->context->getRequestParam('customerId')]
38+
);
39+
}
40+
return $this->getUrl('*/*/');
41+
}
2542
}

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(
7575
}
7676

7777
/**
78-
* {@inheritdoc}
78+
* @inheritdoc
7979
*/
8080
protected function _construct()
8181
{
@@ -119,7 +119,7 @@ protected function _prepareCollection()
119119
}
120120

121121
/**
122-
* {@inheritdoc}
122+
* @inheritdoc
123123
*/
124124
protected function _prepareColumns()
125125
{
@@ -201,7 +201,7 @@ public function getCustomerId()
201201
}
202202

203203
/**
204-
* {@inheritdoc}
204+
* @inheritdoc
205205
*/
206206
public function getGridUrl()
207207
{
@@ -224,7 +224,13 @@ public function getGridParentHtml()
224224
*/
225225
public function getRowUrl($row)
226226
{
227-
return $this->getUrl('catalog/product/edit', ['id' => $row->getProductId()]);
227+
return $this->getUrl(
228+
'catalog/product/edit',
229+
[
230+
'id' => $row->getProductId(),
231+
'customerId' => $this->getCustomerId()
232+
]
233+
);
228234
}
229235

230236
/**

app/code/Magento/Customer/Test/Mftf/Page/AdminEditCustomerPage.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<section name="AdminCustomerAddressesGridSection"/>
1313
<section name="AdminCustomerAddressesGridActionsSection"/>
1414
<section name="AdminCustomerAddressesSection"/>
15+
<section name="AdminCustomerCartSection" />
16+
<section name="AdminCustomerInformationSection" />
1517
<section name="AdminCustomerMainActionsSection"/>
1618
<section name="AdminEditCustomerAddressesSection" />
1719
</page>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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="cartItem" type="button" selector="#customer_cart_grid_table tbody tr:nth-of-type({{row}}) .col-product_id" parameterized="true" timeout="5"/>
13+
</section>
14+
</sections>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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="AdminCustomerInformationSection">
12+
<element name="customerView" type="button" selector="#tab_customer_edit_tab_view_content"/>
13+
<element name="accountInformation" type="button" selector="#tab_customer"/>
14+
<element name="addresses" type="button" selector="#tab_address"/>
15+
<element name="orders" type="button" selector="#tab_orders_content"/>
16+
<element name="shoppingCart" type="button" selector="#tab_cart_content"/>
17+
<element name="newsletter" type="button" selector="#tab_newsletter_content"/>
18+
<element name="billingAgreements" type="button" selector="#tab_customer_edit_tab_agreements_content"/>
19+
<element name="productReviews" type="button" selector="#tab_reviews_content"/>
20+
<element name="wishList" type="button" selector="#tab_wishlist_content"/>
21+
</section>
22+
</sections>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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="AdminProductBackRedirectNavigateFromCustomerViewCartProduct">
12+
<annotations>
13+
<features value="Customer"/>
14+
<title value="Product back redirect navigate from customer view cart product"/>
15+
<description value="Back button on product page is redirecting to customer page if opened form shopping cart"/>
16+
<severity value="MINOR"/>
17+
<group value="Customer"/>
18+
</annotations>
19+
<before>
20+
<!-- Create new product-->
21+
<createData entity="_defaultCategory" stepKey="createCategory"/>
22+
<createData entity="_defaultProduct" stepKey="createProduct">
23+
<requiredEntity createDataKey="createCategory"/>
24+
</createData>
25+
26+
<!-- Create new customer-->
27+
<createData entity="Simple_US_Customer" stepKey="createCustomer"/>
28+
29+
<!-- Login as admin-->
30+
<actionGroup ref="LoginAsAdmin" stepKey="loginAsAdmin"/>
31+
</before>
32+
33+
<!-- Go to storefront as customer-->
34+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="customerLogin">
35+
<argument name="Customer" value="$$createCustomer$$"/>
36+
</actionGroup>
37+
38+
<!-- Add product to cart -->
39+
<actionGroup ref="AddSimpleProductToCart" stepKey="addProductToCart">
40+
<argument name="product" value="$$createProduct$$"/>
41+
</actionGroup>
42+
43+
<!-- Navigate to customer edit page in admin -->
44+
<amOnPage url="{{AdminCustomerPage.url}}edit/id/$$createCustomer.id$$/" stepKey="openCustomerEditPage"/>
45+
<waitForPageLoad stepKey="waitForCustomerEditPage"/>
46+
47+
<!-- Open shopping cart -->
48+
<click selector="{{AdminCustomerInformationSection.shoppingCart}}" stepKey="clickShoppingCartButton"/>
49+
<waitForPageLoad stepKey="waitForPageLoaded"/>
50+
51+
<!-- Open product -->
52+
<click selector="{{AdminCustomerCartSection.cartItem('1')}}" stepKey="openProduct"/>
53+
54+
<!-- Go back to customer page -->
55+
<click selector="{{AdminProductFormActionSection.backButton}}" stepKey="goBackToCustomerPage"/>
56+
57+
<!-- Check current page is customer page -->
58+
<seeInCurrentUrl stepKey="onCustomerAccountPage" url="{{AdminCustomerPage.url}}edit/id/$$createCustomer.id$$/"/>
59+
60+
<after>
61+
<!--Delete product-->
62+
<deleteData stepKey="deleteProduct" createDataKey="createProduct"/>
63+
64+
<!--Delete category-->
65+
<deleteData stepKey="deleteCategory" createDataKey="createCategory"/>
66+
67+
<!--Delete customer-->
68+
<deleteData stepKey="deleteCustomer" createDataKey="createCustomer"/>
69+
70+
<!-- Sign out-->
71+
<actionGroup ref="SignOut" stepKey="signOut"/>
72+
</after>
73+
</test>
74+
</tests>

0 commit comments

Comments
 (0)