Skip to content

Commit e2389ee

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-98656' into 2.3-develop-pr21
2 parents 404f4f6 + fd369e7 commit e2389ee

7 files changed

+195
-35
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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="StorefrontRegisterCustomerFromOrderSuccessPage">
12+
<arguments>
13+
<argument name="customer" />
14+
</arguments>
15+
<click selector="{{CheckoutSuccessRegisterSection.createAccountButton}}" stepKey="clickCreateAccountButton"/>
16+
<fillField selector="{{StorefrontCustomerCreateFormSection.passwordField}}" userInput="{{customer.password}}" stepKey="typePassword"/>
17+
<fillField selector="{{StorefrontCustomerCreateFormSection.confirmPasswordField}}" userInput="{{customer.password}}" stepKey="typeConfirmationPassword"/>
18+
<click selector="{{StorefrontCustomerCreateFormSection.createAccountButton}}" stepKey="clickOnCreateAccount"/>
19+
<see selector="{{StorefrontMessagesSection.success}}" userInput="Thank you for registering" stepKey="verifyAccountCreated"/>
20+
</actionGroup>
21+
</actionGroups>

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

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
namespace Magento\Downloadable\Observer;
99

10+
use Magento\Downloadable\Model\ResourceModel\Link\Purchased\Collection as PurchasedCollection;
11+
use Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Framework\Event\Observer;
1014
use Magento\Framework\Event\ObserverInterface;
1115

1216
/**
@@ -16,65 +20,65 @@ class UpdateLinkPurchasedObserver implements ObserverInterface
1620
{
1721
/**
1822
* Core store config
19-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
23+
*
24+
* @var ScopeConfigInterface
2025
*/
2126
private $scopeConfig;
2227

2328
/**
24-
* @var \Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory
25-
*/
26-
private $purchasedFactory;
27-
28-
/**
29-
* @var \Magento\Framework\DataObject\Copy
29+
* Purchased links collection factory
30+
*
31+
* @var CollectionFactory
3032
*/
31-
private $objectCopyService;
33+
private $purchasedCollectionFactory;
3234

3335
/**
34-
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
35-
* @param \Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory $purchasedFactory
36-
* @param \Magento\Framework\DataObject\Copy $objectCopyService
36+
* @param ScopeConfigInterface $scopeConfig
37+
* @param CollectionFactory $purchasedCollectionFactory
3738
*/
3839
public function __construct(
39-
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
40-
\Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory $purchasedFactory,
41-
\Magento\Framework\DataObject\Copy $objectCopyService
40+
ScopeConfigInterface $scopeConfig,
41+
CollectionFactory $purchasedCollectionFactory
4242
) {
4343
$this->scopeConfig = $scopeConfig;
44-
$this->purchasedFactory = $purchasedFactory;
45-
$this->objectCopyService = $objectCopyService;
44+
$this->purchasedCollectionFactory = $purchasedCollectionFactory;
4645
}
4746

4847
/**
49-
* Re-save order data after order update.
48+
* Link customer_id to downloadable link purchased after update order
5049
*
51-
* @param \Magento\Framework\Event\Observer $observer
50+
* @param Observer $observer
5251
* @return $this
5352
*/
54-
public function execute(\Magento\Framework\Event\Observer $observer)
53+
public function execute(Observer $observer)
5554
{
5655
$order = $observer->getEvent()->getOrder();
57-
58-
if (!$order->getId()) {
59-
//order not saved in the database
56+
$orderId = $order->getId();
57+
$customerId = $order->getCustomerId();
58+
if (!$orderId || !$customerId) {
6059
return $this;
6160
}
61+
$purchasedLinksCollection = $this->getPurchasedCollection((int)$orderId);
62+
foreach ($purchasedLinksCollection as $linkPurchased) {
63+
$linkPurchased->setCustomerId($customerId)->save();
64+
}
6265

63-
$purchasedLinks = $this->purchasedFactory->create()->addFieldToFilter(
66+
return $this;
67+
}
68+
69+
/**
70+
* Get purchased collection by order id
71+
*
72+
* @param int $orderId
73+
* @return PurchasedCollection
74+
*/
75+
private function getPurchasedCollection(int $orderId): PurchasedCollection
76+
{
77+
$purchasedCollection = $this->purchasedCollectionFactory->create()->addFieldToFilter(
6478
'order_id',
65-
['eq' => $order->getId()]
79+
['eq' => $orderId]
6680
);
6781

68-
foreach ($purchasedLinks as $linkPurchased) {
69-
$this->objectCopyService->copyFieldsetToTarget(
70-
\downloadable_sales_copy_order::class,
71-
'to_downloadable',
72-
$order,
73-
$linkPurchased
74-
);
75-
$linkPurchased->save();
76-
}
77-
78-
return $this;
82+
return $purchasedCollection;
7983
}
8084
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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="StorefrontAssertDownloadableProductIsPresentInCustomerAccount">
12+
<arguments>
13+
<argument name="product"/>
14+
</arguments>
15+
<amOnPage url="{{StorefrontCustomerDashboardPage.url}}" stepKey="goToMyAccountPage"/>
16+
<click selector="{{StorefrontCustomerSidebarSection.sidebarTab('My Downloadable Products')}}" stepKey="clickDownloadableProducts"/>
17+
<waitForPageLoad stepKey="waitForDownloadableProductsPageLoad" />
18+
<seeElement selector="{{StorefrontCustomerDownloadableProductsSection.productName(product.name)}}" stepKey="seeStorefontDownloadableProductsProductName" />
19+
</actionGroup>
20+
</actionGroups>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
<entities xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:DataGenerator/etc/dataProfileSchema.xsd">
11+
<entity name="EnableGuestCheckoutWithDownloadableItems">
12+
<data key="path">catalog/downloadable/disable_guest_checkout</data>
13+
<data key="scope_id">0</data>
14+
<data key="value">0</data>
15+
</entity>
16+
<entity name="DisableGuestCheckoutWithDownloadableItems">
17+
<data key="path">catalog/downloadable/disable_guest_checkout</data>
18+
<data key="scope_id">0</data>
19+
<data key="value">1</data>
20+
</entity>
21+
</entities>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
<pages xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Page/etc/PageObject.xsd">
10+
<page name="StorefrontCustomerDownloadableProductsPage" url="downloadable/customer/products/" area="storefront" module="Magento_Downloadable">
11+
<section name="StorefrontCustomerDownloadableProductsSection"/>
12+
</page>
13+
</pages>
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="StorefrontCustomerDownloadableProductsSection">
12+
<element name="productName" type="text" selector="//table[@id='my-downloadable-products-table']//strong[contains(@class, 'product-name') and normalize-space(.)='{{productName}}']" parameterized="true"/>
13+
</section>
14+
</sections>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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="LinkDownloadableProductFromGuestToCustomerTest">
12+
<annotations>
13+
<stories value="Customer Account"/>
14+
<title value="Customer should see downloadable products after place order as guest and registering after that"/>
15+
<description value="Verify that in 'My Downloadable Products' section in customer account user can see products."/>
16+
<severity value="AVERAGE"/>
17+
<useCaseId value="MAGETWO-98656"/>
18+
<testCaseId value="MC-16011"/>
19+
</annotations>
20+
<before>
21+
<magentoCLI command="config:set {{EnableGuestCheckoutWithDownloadableItems.path}} {{EnableGuestCheckoutWithDownloadableItems.value}}" stepKey="enableGuestCheckoutWithDownloadableItems" />
22+
<createData entity="_defaultCategory" stepKey="createCategory"/>
23+
<createData entity="DownloadableProductWithOneLink" stepKey="createProduct">
24+
<requiredEntity createDataKey="createCategory"/>
25+
</createData>
26+
<createData entity="downloadableLink1" stepKey="addDownloadableLink">
27+
<requiredEntity createDataKey="createProduct"/>
28+
</createData>
29+
</before>
30+
<after>
31+
<magentoCLI command="config:set {{DisableGuestCheckoutWithDownloadableItems.path}} {{DisableGuestCheckoutWithDownloadableItems.value}}" stepKey="disableGuestCheckoutWithDownloadableItems" />
32+
<deleteData stepKey="deleteProduct" createDataKey="createProduct"/>
33+
<deleteData stepKey="deleteCategory" createDataKey="createCategory"/>
34+
</after>
35+
<!--Step 1: Go to Storefront as Guest-->
36+
<amOnPage url="{{StorefrontHomePage.url}}" stepKey="amOnStorefrontPage"/>
37+
<!--Step 2: Add downloadable product to shopping cart-->
38+
<amOnPage url="{{StorefrontProductPage.url($$createProduct.custom_attributes[url_key]$$)}}" stepKey="amOnStorefrontProductPage"/>
39+
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
40+
<argument name="product" value="$$createProduct$$"/>
41+
<argument name="productCount" value="1"/>
42+
</actionGroup>
43+
<!--Step 3: Go to checkout-->
44+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart" />
45+
<!--Step 4: Select Check/Money Order payment, fill required fields and click Update and Place Order-->
46+
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyOrderPayment"/>
47+
<actionGroup ref="GuestCheckoutSelectPaymentAndFillNewBillingAddressActionGroup" stepKey="changeAddress">
48+
<argument name="customerVar" value="Simple_US_Customer_NY"/>
49+
<argument name="customerAddressVar" value="US_Address_NY"/>
50+
<argument name="paymentMethod" value="Check / Money order"/>
51+
</actionGroup>
52+
<click selector="{{CheckoutShippingSection.updateAddress}}" stepKey="saveAddress"/>
53+
<waitForPageLoad stepKey="waitUpdateAddress"/>
54+
<actionGroup ref="CheckoutPlaceOrderActionGroup" stepKey="placeOrder">
55+
<argument name="orderNumberMessage" value="CONST.successGuestCheckoutOrderNumberMessage"/>
56+
<argument name="emailYouMessage" value="CONST.successCheckoutEmailYouMessage" />
57+
</actionGroup>
58+
<!--Step 5: Create customer account after placing order-->
59+
<actionGroup ref="StorefrontRegisterCustomerFromOrderSuccessPage" stepKey="createCustomerAfterPlaceOrder">
60+
<argument name="customer" value="CustomerEntityOne"/>
61+
</actionGroup>
62+
<!--Step 6: Go To My Account -> My Downloadable Products and check if downloadable product link exist-->
63+
<actionGroup ref="StorefrontAssertDownloadableProductIsPresentInCustomerAccount" stepKey="seeStorefontMyDownloadableProductsProductName">
64+
<argument name="product" value="$$createProduct$$"/>
65+
</actionGroup>
66+
</test>
67+
</tests>

0 commit comments

Comments
 (0)