8
8
9
9
namespace Magento \Quote \Plugin ;
10
10
11
- use Magento \Catalog \Api \ProductRepositoryInterface ;
12
11
use Magento \Framework \Exception \LocalizedException ;
13
12
use Magento \Framework \Exception \NoSuchEntityException ;
14
13
use Magento \Framework \Webapi \Rest \Request as RestRequest ;
@@ -27,14 +26,14 @@ class UpdateCartId
27
26
{
28
27
/**
29
28
* @param RestRequest $request
30
- * @param ProductRepositoryInterface $productRepository
31
29
* @param StoreManagerInterface $storeManager
32
30
* @param QuoteIdMaskFactory $quoteIdMaskFactory
33
31
* @param CartRepositoryInterface $cartRepository
32
+ * @param ProductResource $productResource
33
+ * @param ProductWebsiteLink $productWebsiteLink
34
34
*/
35
35
public function __construct (
36
36
private readonly RestRequest $ request ,
37
- private readonly ProductRepositoryInterface $ productRepository ,
38
37
private readonly StoreManagerInterface $ storeManager ,
39
38
private readonly QuoteIdMaskFactory $ quoteIdMaskFactory ,
40
39
private readonly CartRepositoryInterface $ cartRepository ,
@@ -78,22 +77,33 @@ private function validateProductWebsiteAssignment(CartItemInterface $cartItem):
78
77
return ;
79
78
}
80
79
81
- $ maskedQuoteId = $ cartItem ->getQuoteId ();
82
- $ quoteIdMask = $ this ->quoteIdMaskFactory ->create ()->load ($ maskedQuoteId , 'masked_id ' );
83
- $ quoteId = $ quoteIdMask ->getQuoteId ();
80
+ $ storeId = (int )($ cartItem ->getStoreId () ?? 0 );
84
81
85
- if (!$ quoteId ) {
86
- return ;
82
+ if (!$ storeId ) {
83
+ try {
84
+ $ storeId = (int )$ this ->storeManager ->getStore ()->getId ();
85
+ } catch (\Throwable $ e ) {
86
+ // ignore; fallback to masked quote resolution below
87
+ }
87
88
}
88
89
89
- try {
90
- $ quote = $ this ->cartRepository ->get ($ quoteId );
91
- $ storeId = $ quote ->getStoreId ();
92
- // Product not in quote yet
93
- $ this ->validateWebsiteAssignmentBySku ($ sku , $ storeId );
90
+ if (!$ storeId ) {
91
+ try {
92
+ $ maskedQuoteId = $ cartItem ->getQuoteId ();
93
+ if ($ maskedQuoteId ) {
94
+ $ quoteIdMask = $ this ->quoteIdMaskFactory ->create ()->load ($ maskedQuoteId , 'masked_id ' );
95
+ $ quoteId = (int )$ quoteIdMask ->getQuoteId ();
96
+ if ($ quoteId ) {
97
+ $ storeId = (int )$ this ->cartRepository ->get ($ quoteId )->getStoreId ();
98
+ }
99
+ }
100
+ } catch (NoSuchEntityException ) {
101
+ throw new LocalizedException (__ ('Product that you are trying to add is not available. ' ));
102
+ }
103
+ }
94
104
95
- } catch ( NoSuchEntityException ) {
96
- throw new LocalizedException ( __ ( ' Product that you are trying to add is not available. ' ) );
105
+ if ( $ storeId ) {
106
+ $ this -> validateWebsiteAssignmentBySku ( $ sku , $ storeId );
97
107
}
98
108
}
99
109
0 commit comments