Skip to content

Commit d87f852

Browse files
MAGETWO-98656: Purchasing a downloadable product as guest then creating an account on the onepagesuccess step doesn't link product with account
1 parent d3fdecf commit d87f852

7 files changed

+194
-37
lines changed
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>
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>
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_Customer">
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>

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

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,78 +3,81 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
76

87
namespace Magento\Downloadable\Observer;
98

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

1215
/**
13-
* Assign Downloadable links to customer created after issuing guest order.
16+
* Update link purchased observer
1417
*/
1518
class UpdateLinkPurchasedObserver implements ObserverInterface
1619
{
1720
/**
1821
* Core store config
19-
* @var \Magento\Framework\App\Config\ScopeConfigInterface
22+
*
23+
* @var ScopeConfigInterface
2024
*/
2125
private $scopeConfig;
2226

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

3334
/**
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
35+
* @param ScopeConfigInterface $scopeConfig
36+
* @param CollectionFactory $purchasedCollectionFactory
3737
*/
3838
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
39+
ScopeConfigInterface $scopeConfig,
40+
CollectionFactory $purchasedCollectionFactory
4241
) {
4342
$this->scopeConfig = $scopeConfig;
44-
$this->purchasedFactory = $purchasedFactory;
45-
$this->objectCopyService = $objectCopyService;
43+
$this->purchasedCollectionFactory = $purchasedCollectionFactory;
4644
}
4745

4846
/**
49-
* Re-save order data after order update.
47+
* Link customer_id to downloadable link purchased after update order
5048
*
51-
* @param \Magento\Framework\Event\Observer $observer
49+
* @param Observer $observer
5250
* @return $this
5351
*/
54-
public function execute(\Magento\Framework\Event\Observer $observer)
52+
public function execute(Observer $observer)
5553
{
5654
$order = $observer->getEvent()->getOrder();
57-
58-
if (!$order->getId()) {
59-
//order not saved in the database
55+
$orderId = $order->getId();
56+
$customerId = $order->getCustomerId();
57+
if (!$orderId || !$customerId) {
6058
return $this;
6159
}
60+
$purchasedLinksCollection = $this->getPurchasedCollection((int)$orderId);
61+
foreach ($purchasedLinksCollection as $linkPurchased) {
62+
$linkPurchased->setCustomerId($customerId)->save();
63+
}
6264

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

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;
81+
return $purchasedCollection;
7982
}
8083
}
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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
<testCaseId value="MC-16011"/>
18+
</annotations>
19+
<before>
20+
<magentoCLI command="config:set {{EnableGuestCheckoutWithDownloadableItems.path}} {{EnableGuestCheckoutWithDownloadableItems.value}}" stepKey="enableGuestCheckoutWithDownloadableItems" />
21+
<createData entity="_defaultCategory" stepKey="createCategory"/>
22+
<createData entity="DownloadableProductWithOneLink" stepKey="createProduct">
23+
<requiredEntity createDataKey="createCategory"/>
24+
</createData>
25+
<createData entity="downloadableLink1" stepKey="addDownloadableLink">
26+
<requiredEntity createDataKey="createProduct"/>
27+
</createData>
28+
</before>
29+
<after>
30+
<magentoCLI command="config:set {{DisableGuestCheckoutWithDownloadableItems.path}} {{DisableGuestCheckoutWithDownloadableItems.value}}" stepKey="disableGuestCheckoutWithDownloadableItems" />
31+
<deleteData stepKey="deleteProduct" createDataKey="createProduct"/>
32+
<deleteData stepKey="deleteCategory" createDataKey="createCategory"/>
33+
</after>
34+
<!--Step 1: Go to Storefront as Guest-->
35+
<amOnPage url="{{StorefrontHomePage.url}}" stepKey="amOnStorefrontPage"/>
36+
<!--Step 2: Add virtual product to shopping cart-->
37+
<amOnPage url="{{StorefrontProductPage.url($$createProduct.name$$)}}" stepKey="amOnStorefrontProductPage"/>
38+
<actionGroup ref="StorefrontAddProductToCartActionGroup" stepKey="addProductToCart">
39+
<argument name="product" value="$$createProduct$$"/>
40+
<argument name="productCount" value="1"/>
41+
</actionGroup>
42+
<!--Step 3: Go to checkout-->
43+
<actionGroup ref="GoToCheckoutFromMinicartActionGroup" stepKey="goToCheckoutFromMinicart" />
44+
<!--Step 4: Checkout select Check/Money Order payment, fill required fields and click Update and Place Order-->
45+
<actionGroup ref="CheckoutSelectCheckMoneyOrderPaymentActionGroup" stepKey="selectCheckMoneyOrderPayment"/>
46+
<actionGroup ref="GuestCheckoutSelectPaymentAndFillNewBillingAddressActionGroup" stepKey="changeAddress">
47+
<argument name="customerVar" value="Simple_US_Customer_NY"/>
48+
<argument name="customerAddressVar" value="US_Address_NY"/>
49+
<argument name="paymentMethod" value="Check / Money order"/>
50+
</actionGroup>
51+
<click selector="{{CheckoutShippingSection.updateAddress}}" stepKey="saveAddress"/>
52+
<actionGroup ref="CheckoutPlaceOrderActionGroup" stepKey="placeOrder">
53+
<argument name="orderNumberMessage" value="CONST.successGuestCheckoutOrderNumberMessage"/>
54+
<argument name="emailYouMessage" value="CONST.successCheckoutEmailYouMessage" />
55+
</actionGroup>
56+
<!--Step 5: Create customer account after placing order-->
57+
<actionGroup ref="StorefrontRegisterCustomerFromOrderSuccessPage" stepKey="createCustomerAfterPlaceOrder">
58+
<argument name="customer" value="CustomerEntityOne"/>
59+
</actionGroup>
60+
<!--Step 6: Go To My Account -> My Downloadable Products and check if downloadable product link exist-->
61+
<actionGroup ref="StorefrontAssertDownloadableProductIsPresentInCustomerAccount" stepKey="seeStorefontMyDownloadableProductsProductName">
62+
<argument name="product" value="$$createProduct$$"/>
63+
</actionGroup>
64+
</test>
65+
</tests>

0 commit comments

Comments
 (0)