@@ -40,10 +40,7 @@ class IsAllowedGuestCheckoutObserver implements ObserverInterface
40
40
* @param ScopeConfigInterface $scopeConfig
41
41
* @param CollectionFactory $linksFactory
42
42
*/
43
- public function __construct (
44
- ScopeConfigInterface $ scopeConfig ,
45
- CollectionFactory $ linksFactory
46
- ) {
43
+ public function __construct (ScopeConfigInterface $ scopeConfig , CollectionFactory $ linksFactory ) {
47
44
$ this ->scopeConfig = $ scopeConfig ;
48
45
$ this ->linksFactory = $ linksFactory ;
49
46
}
@@ -61,17 +58,17 @@ public function execute(Observer $observer)
61
58
62
59
/* @var $quote Quote */
63
60
$ quote = $ observer ->getEvent ()->getQuote ();
61
+ $ isGuestCheckoutDisabled = $ this ->scopeConfig ->isSetFlag (
62
+ self ::XML_PATH_DISABLE_GUEST_CHECKOUT ,
63
+ ScopeInterface::SCOPE_STORE ,
64
+ $ storeId
65
+ );
64
66
65
67
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 )) {
75
72
$ result ->setIsAllowed (false );
76
73
break ;
77
74
}
@@ -92,20 +89,24 @@ private function checkForShareableLinks(CartItemInterface $item, int $storeId):
92
89
{
93
90
$ isSharable = true ;
94
91
$ option = $ item ->getOptionByCode ('downloadable_link_ids ' );
92
+
95
93
if (!empty ($ option )) {
96
94
$ downloadableLinkIds = explode (', ' , $ option ->getValue ());
97
95
$ 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
+
98
103
foreach ($ links as $ link ) {
99
104
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 )
107
107
) {
108
108
$ isSharable = false ;
109
+ break ;
109
110
}
110
111
}
111
112
}
0 commit comments