Skip to content

Commit b93a17d

Browse files
authored
ENGCOM-7679: Fix Downloadable product after refund #28413
2 parents 1cff238 + ed6c29f commit b93a17d

8 files changed

+303
-13
lines changed

app/code/Magento/Catalog/Test/Mftf/Test/VerifyCategoryProductAndProductCategoryPartialReindexTest.xml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,9 @@
5858
<argument name="categoryName" value="$$categoryN.name$$, $$categoryM.name$$"/>
5959
</actionGroup>
6060

61-
<wait stepKey="waitBeforeRunCronIndex" time="30"/>
61+
<wait stepKey="waitBeforeRunCronIndex" time="60"/>
6262
<magentoCLI stepKey="runCronIndex" command="cron:run --group=index"/>
63-
<wait stepKey="waitAfterRunCronIndex" time="60"/>
63+
<wait stepKey="waitAfterRunCronIndex" time="120"/>
6464
</before>
6565
<after>
6666
<!-- Change "Category Products" and "Product Categories" indexers to "Update on Save" mode -->
@@ -108,6 +108,8 @@
108108
<argument name="categoryName" value="$$categoryK.name$$"/>
109109
</actionGroup>
110110

111+
<wait stepKey="waitAfterAssignCategoryK" time="60"/>
112+
111113
<!-- Unassign category M from Product B -->
112114
<actionGroup ref="AdminProductPageOpenByIdActionGroup" stepKey="amOnEditCategoryPageB">
113115
<argument name="productId" value="$$productB.id$$"/>
@@ -147,8 +149,9 @@
147149
<see userInput="$$productC.name$$" selector="{{StorefrontCategoryMainSection.productName}}" stepKey="seeProductInCategoryN"/>
148150

149151
<!-- Run cron -->
150-
<wait stepKey="waitBeforeRunMagentoCron" time="30"/>
152+
<wait stepKey="waitBeforeRunMagentoCron" time="60"/>
151153
<magentoCLI stepKey="runMagentoCron" command="cron:run --group=index"/>
154+
152155
<wait stepKey="waitAfterRunMagentoCron" time="90"/>
153156

154157
<!-- Open categories K, L, M, N on Storefront in order to make sure that new assigments are applied -->
@@ -213,8 +216,9 @@
213216
<see userInput="$$productC.name$$" selector="{{StorefrontCategoryMainSection.productName}}" stepKey="productCOnCategoryN"/>
214217

215218
<!-- Run Cron once to reindex product changes -->
216-
<wait stepKey="waitBeforeRunCronIndexAfterProductAssignToCategory" time="30"/>
219+
<wait stepKey="waitBeforeRunCronIndexAfterProductAssignToCategory" time="60"/>
217220
<magentoCLI stepKey="runCronIndexAfterProductAssignToCategory" command="cron:run --group=index"/>
221+
218222
<wait stepKey="waitAfterRunCronIndexAfterProductAssignToCategory" time="90"/>
219223

220224
<!-- Open categories K, L, M, N on Storefront in order to make sure that new assigments are applied -->

app/code/Magento/Customer/Test/Mftf/ActionGroup/AdminCustomerFindWishlistItemActionGroup.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
</arguments>
1515
<fillField userInput="{{productName}}" selector="{{AdminCustomerWishlistSection.productName}}" stepKey="fillProductNameField"/>
1616
<click selector="{{AdminCustomerWishlistSection.searchButton}}" stepKey="clickSearchButton"/>
17-
<waitForPageLoad stepKey="waitForGridLoading"/>
17+
<waitForAjaxLoad time="60" stepKey="waitForLoading"/>
1818
</actionGroup>
1919
</actionGroups>

app/code/Magento/Downloadable/Observer/SetLinkStatusObserver.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
6161
'payment_pending' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING_PAYMENT,
6262
'payment_review' => \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PAYMENT_REVIEW,
6363
];
64+
$expiredOrderItemIds = [];
6465

6566
$downloadableItemsStatuses = [];
6667
$orderItemStatusToEnable = $this->_scopeConfig->getValue(
@@ -114,6 +115,10 @@ public function execute(\Magento\Framework\Event\Observer $observer)
114115
if (in_array($item->getStatusId(), $availableStatuses)) {
115116
$downloadableItemsStatuses[$item->getId()] = $linkStatuses['avail'];
116117
}
118+
119+
if ($item->getQtyOrdered() - $item->getQtyRefunded() == 0) {
120+
$expiredOrderItemIds[] = $item->getId();
121+
}
117122
}
118123
}
119124
}
@@ -141,10 +146,22 @@ public function execute(\Magento\Framework\Event\Observer $observer)
141146
}
142147
}
143148

149+
if ($expiredOrderItemIds) {
150+
$linkPurchased = $this->_createItemsCollection()->addFieldToFilter(
151+
'order_item_id',
152+
['in' => $expiredOrderItemIds]
153+
);
154+
foreach ($linkPurchased as $link) {
155+
$link->setStatus(\Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_EXPIRED)->save();
156+
}
157+
}
158+
144159
return $this;
145160
}
146161

147162
/**
163+
* Returns purchased item collection
164+
*
148165
* @return \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\Collection
149166
*/
150167
protected function _createItemsCollection()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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="StorefrontNotAssertDownloadableProductLinkInCustomerAccountActionGroup">
12+
<annotations>
13+
<description>Goes to the Storefront Customer Dashboard page. Clicks on 'My Downloadable Products'. Validates that the provided Downloadable Product is present and Downloadable link not exist.</description>
14+
</annotations>
15+
<arguments>
16+
<argument name="product"/>
17+
</arguments>
18+
19+
<amOnPage url="{{StorefrontCustomerDashboardPage.url}}" stepKey="goToMyAccountPage"/>
20+
<click selector="{{StorefrontCustomerSidebarSection.sidebarTab('My Downloadable Products')}}" stepKey="clickDownloadableProducts"/>
21+
<waitForPageLoad stepKey="waitForDownloadableProductsPageLoad"/>
22+
<seeElement selector="{{StorefrontCustomerDownloadableProductsSection.productName(product.name)}}" stepKey="seeStorefrontDownloadableProductsProductName"/>
23+
<dontSeeElement selector="{{StorefrontCustomerDownloadableProductsSection.downloadableLink}}" stepKey="dontSeeStorefrontMyDownloadableProductsLink"/>
24+
25+
</actionGroup>
26+
</actionGroups>

app/code/Magento/Downloadable/Test/Mftf/Section/StorefrontCustomerDownloadableProductsSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/SectionObject.xsd">
1111
<section name="StorefrontCustomerDownloadableProductsSection">
1212
<element name="productName" type="text" selector="//table[@id='my-downloadable-products-table']//strong[contains(@class, 'product-name') and normalize-space(.)='{{productName}}']" parameterized="true"/>
13+
<element name="downloadableLink" type="button" selector="//table[@id='my-downloadable-products-table']//a[contains(@class, 'download')]"/>
1314
</section>
1415
</sections>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="StorefrontAccountDownloadableProductLinkAfterPartialRefundTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Customer Account Downloadable Products Link"/>
14+
<title value="My Account Downloadable Product Link after Partially Refunded"/>
15+
<description value="Verify that Downloadable product is not available in My Download Products tab after it has been partially refunded."/>
16+
<severity value="CRITICAL"/>
17+
<testCaseId value="MC-35198"/>
18+
<group value="Downloadable"/>
19+
</annotations>
20+
21+
<before>
22+
<magentoCLI stepKey="addDownloadableDomain" command="downloadable:domains:add example.com static.magento.com"/>
23+
<magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" stepKey="enableFlatRate"/>
24+
25+
<createData entity="ApiCategory" stepKey="createCategory"/>
26+
<createData entity="ApiSimpleProduct" stepKey="createSimpleProduct">
27+
<requiredEntity createDataKey="createCategory"/>
28+
</createData>
29+
<createData entity="ApiDownloadableProduct" stepKey="createDownloadableProduct"/>
30+
<createData entity="downloadableLink1" stepKey="addDownloadableLink1">
31+
<requiredEntity createDataKey="createDownloadableProduct"/>
32+
</createData>
33+
34+
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
35+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
36+
37+
<createData entity="Simple_US_Customer_Multiple_Addresses" stepKey="createCustomer"/>
38+
<actionGroup ref="LoginToStorefrontActionGroup" stepKey="signIn">
39+
<argument name="Customer" value="$$createCustomer$$"/>
40+
</actionGroup>
41+
</before>
42+
43+
<after>
44+
<actionGroup ref="AdminLogoutActionGroup" stepKey="logoutFromAdmin"/>
45+
<actionGroup ref="StorefrontCustomerLogoutActionGroup" stepKey="customerLogout"/>
46+
47+
<deleteData createDataKey="createCustomer" stepKey="deleteCustomer"/>
48+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
49+
<deleteData createDataKey="createSimpleProduct" stepKey="deleteSimpleProduct"/>
50+
<deleteData createDataKey="createDownloadableProduct" stepKey="deleteDownloadableProduct"/>
51+
52+
<magentoCLI stepKey="removeDownloadableDomain" command="downloadable:domains:remove example.com static.magento.com"/>
53+
<magentoCLI command="config:set {{EnableFlatRateConfigData.path}} {{EnableFlatRateConfigData.value}}" stepKey="enableFlatRate"/>
54+
<magentoCLI command="indexer:reindex" stepKey="reindex"/>
55+
<magentoCLI command="cache:flush" stepKey="flushCache"/>
56+
</after>
57+
58+
<actionGroup ref="StorefrontAddSimpleProductToShoppingCartActionGroup" stepKey="addSimpleProductToCart">
59+
<argument name="product" value="$$createSimpleProduct$$"/>
60+
</actionGroup>
61+
62+
<amOnPage url="{{StorefrontProductPage.url($$createDownloadableProduct.custom_attributes[url_key]$$)}}" stepKey="OpenStoreFrontProductPage"/>
63+
<waitForPageLoad stepKey="waitForPageToLoad"/>
64+
65+
<actionGroup ref="StorefrontAddToCartCustomOptionsProductPageActionGroup" stepKey="addToTheCart">
66+
<argument name="productName" value="$$createDownloadableProduct.name$$"/>
67+
</actionGroup>
68+
69+
<actionGroup ref="ClickViewAndEditCartFromMiniCartActionGroup" stepKey="goToShoppingCartFromMinicart"/>
70+
<click selector="{{CheckoutCartSummarySection.proceedToCheckout}}" stepKey="clickProceedToCheckout"/>
71+
<waitForPageLoad stepKey="waitForProceedToCheckout"/>
72+
<waitForElementVisible selector="{{CheckoutShippingSection.shipHereButton(UK_Not_Default_Address.street[0])}}" stepKey="waitForShipHereVisible"/>
73+
<click selector="{{CheckoutShippingSection.shipHereButton(UK_Not_Default_Address.street[0])}}" stepKey="clickShipHere"/>
74+
<click selector="{{CheckoutShippingGuestInfoSection.next}}" stepKey="clickNext"/>
75+
<waitForPageLoad stepKey="waitForShipmentPageLoad"/>
76+
<checkOption selector="{{CheckoutPaymentSection.billingAddressNotSameCheckbox}}" stepKey="selectPaymentSolution"/>
77+
<waitForElement selector="{{CheckoutPaymentSection.paymentSectionTitle}}" stepKey="waitForPaymentSectionLoaded"/>
78+
<click selector="{{CheckoutPaymentSection.placeOrder}}" stepKey="clickPlaceOrderButton"/>
79+
<seeElement selector="{{CheckoutSuccessMainSection.success}}" stepKey="orderIsSuccessfullyPlaced"/>
80+
<grabTextFrom selector="{{CheckoutSuccessMainSection.orderNumber22}}" stepKey="grabOrderNumber"/>
81+
82+
<actionGroup ref="AdminLoginActionGroup" stepKey="LoginAsAdmin"/>
83+
84+
<amOnPage url="{{AdminOrdersPage.url}}" stepKey="onOrdersPage"/>
85+
<actionGroup ref="SearchAdminDataGridByKeywordActionGroup" stepKey="searchOrder">
86+
<argument name="keyword" value="$grabOrderNumber"/>
87+
</actionGroup>
88+
<actionGroup ref="AdminOrderGridClickFirstRowActionGroup" stepKey="clickOrderRow"/>
89+
90+
<actionGroup ref="AdminCreateInvoiceActionGroup" stepKey="createCreditMemo"/>
91+
92+
<actionGroup ref="OpenOrderByIdActionGroup" stepKey="openOrder">
93+
<argument name="orderId" value="{$grabOrderNumber}"/>
94+
</actionGroup>
95+
96+
<actionGroup ref="AdminOpenAndFillCreditMemoRefundActionGroup" stepKey="fillCreditMemoRefund">
97+
<argument name="itemQtyToRefund" value="0"/>
98+
<argument name="rowNumber" value="1"/>
99+
</actionGroup>
100+
101+
<click selector="{{AdminCreditMemoTotalSection.submitRefundOffline}}" stepKey="clickRefundOffline"/>
102+
<waitForPageLoad stepKey="waitForResultPage"/>
103+
104+
<actionGroup ref="StorefrontNotAssertDownloadableProductLinkInCustomerAccountActionGroup" stepKey="dontSeeStorefrontMyAccountDownloadableProductsLink">
105+
<argument name="product" value="$$createDownloadableProduct$$"/>
106+
</actionGroup>
107+
108+
</test>
109+
</tests>

0 commit comments

Comments
 (0)