Skip to content

Commit 4db0172

Browse files
authored
#23972 fix disabled guest checkout issue
Small improvements
1 parent 4dac91c commit 4db0172

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

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

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ class IsAllowedGuestCheckoutObserver implements ObserverInterface
4040
* @param ScopeConfigInterface $scopeConfig
4141
* @param CollectionFactory $linksFactory
4242
*/
43-
public function __construct(
44-
ScopeConfigInterface $scopeConfig,
45-
CollectionFactory $linksFactory
46-
) {
43+
public function __construct(ScopeConfigInterface $scopeConfig, CollectionFactory $linksFactory) {
4744
$this->scopeConfig = $scopeConfig;
4845
$this->linksFactory = $linksFactory;
4946
}
@@ -61,17 +58,17 @@ public function execute(Observer $observer)
6158

6259
/* @var $quote Quote */
6360
$quote = $observer->getEvent()->getQuote();
61+
$isGuestCheckoutDisabled = $this->scopeConfig->isSetFlag(
62+
self::XML_PATH_DISABLE_GUEST_CHECKOUT,
63+
ScopeInterface::SCOPE_STORE,
64+
$storeId
65+
);
6466

6567
foreach ($quote->getAllItems() as $item) {
66-
if (($product = $item->getProduct())
67-
&& $product->getTypeId() == Type::TYPE_DOWNLOADABLE
68-
) {
69-
if ($this->scopeConfig->isSetFlag(
70-
self::XML_PATH_DISABLE_GUEST_CHECKOUT,
71-
ScopeInterface::SCOPE_STORE,
72-
$storeId
73-
)
74-
|| !$this->checkForShareableLinks($item, $storeId)) {
68+
$product = $item->getProduct();
69+
70+
if ((string)$product->getTypeId() === Type::TYPE_DOWNLOADABLE) {
71+
if ($isGuestCheckoutDisabled || !$this->checkForShareableLinks($item, $storeId)) {
7572
$result->setIsAllowed(false);
7673
break;
7774
}
@@ -92,20 +89,24 @@ private function checkForShareableLinks(CartItemInterface $item, int $storeId):
9289
{
9390
$isSharable = true;
9491
$option = $item->getOptionByCode('downloadable_link_ids');
92+
9593
if (!empty($option)) {
9694
$downloadableLinkIds = explode(',', $option->getValue());
9795
$links = $this->linksFactory->create()->addFieldToFilter("link_id", ["in" => $downloadableLinkIds]);
96+
97+
$configDownloadableSharable = $this->scopeConfig->isSetFlag(
98+
self::XML_PATH_DOWNLOADABLE_SHAREABLE,
99+
ScopeInterface::SCOPE_STORE,
100+
$storeId
101+
);
102+
98103
foreach ($links as $link) {
99104
if (!$link->getIsShareable() ||
100-
(
101-
$link->getIsShareable() == 2 && !$this->scopeConfig->isSetFlag(
102-
self::XML_PATH_DOWNLOADABLE_SHAREABLE,
103-
ScopeInterface::SCOPE_STORE,
104-
$storeId
105-
)
106-
)
105+
//Use config default value and it's disabled in config
106+
((int)$link->getIsShareable() === 2 && !$configDownloadableSharable)
107107
) {
108108
$isSharable = false;
109+
break;
109110
}
110111
}
111112
}

0 commit comments

Comments
 (0)