-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Purchasing a downloadable product as guest then creating an account on the onepagesuccess step doesn't link product with account #21711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fc1434b
8652bc8
95b1d53
0ade930
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,80 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
<?php | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Copyright © Magento, Inc. All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* See COPYING.txt for license details. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
declare(strict_types=1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
namespace Magento\Downloadable\Observer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
use Magento\Framework\Event\ObserverInterface; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Assign Downloadable links to customer created after issuing guest order. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class UpdateLinkPurchasedObserver implements ObserverInterface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @Jitheesh. Thank you for your contribution. Could you explain, please, is there any reason why the observer was created instead of fixing the issue directly in the code where it appears? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @rogyar This issue is related to downloadable component and issue is appears at sales component, magento2/app/code/Magento/Sales/Model/Order/CustomerManagement.php Lines 99 to 125 in ab66a14
so I thought it would be good to add this fix on corresponding component. We already have other Observer based on this rule.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Core store config | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @var \Magento\Framework\App\Config\ScopeConfigInterface | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private $scopeConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @var \Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private $purchasedFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @var \Magento\Framework\DataObject\Copy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
private $objectCopyService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param \Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory $purchasedFactory | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param \Magento\Framework\DataObject\Copy $objectCopyService | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function __construct( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\Magento\Downloadable\Model\ResourceModel\Link\Purchased\CollectionFactory $purchasedFactory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\Magento\Framework\DataObject\Copy $objectCopyService | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$this->scopeConfig = $scopeConfig; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$this->purchasedFactory = $purchasedFactory; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$this->objectCopyService = $objectCopyService; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* Re-save order data after order update. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @param \Magento\Framework\Event\Observer $observer | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
* @return $this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
public function execute(\Magento\Framework\Event\Observer $observer) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$order = $observer->getEvent()->getOrder(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if (!$order->getId()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
//order not saved in the database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return $this; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$purchasedLinks = $this->purchasedFactory->create()->addFieldToFilter( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'order_id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
['eq' => $order->getId()] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
foreach ($purchasedLinks as $linkPurchased) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$this->objectCopyService->copyFieldsetToTarget( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\downloadable_sales_copy_order::class, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'to_downloadable', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$order, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$linkPurchased | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$linkPurchased->save(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return $this; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Uh oh!
There was an error while loading. Please reload this page.