@@ -74,31 +74,23 @@ private function validateProductWebsiteAssignment(CartItemInterface $cartItem):
74
74
return ;
75
75
}
76
76
77
- $ maskedQuoteId = $ cartItem ->getQuoteId ();
78
- $ quoteIdMask = $ this ->quoteIdMaskFactory ->create ()->load ($ maskedQuoteId , 'masked_id ' );
79
- $ quoteId = $ quoteIdMask ->getQuoteId ();
80
-
81
- if (!$ quoteId ) {
82
- return ;
83
- }
84
-
85
- try {
86
- $ quote = $ this ->cartRepository ->get ($ quoteId );
87
- $ storeId = $ quote ->getStoreId ();
88
-
89
- foreach ($ quote ->getAllItems () as $ item ) {
90
- if ($ sku === $ item ->getSku ()) {
91
- $ this ->validateWebsiteAssignment ($ item ->getProductId (), $ storeId );
92
- return ;
93
- }
77
+ $ storeId = (int )($ cartItem ->getStoreId () ?? 0 );
78
+ if (!$ storeId ) {
79
+ $ maskedQuoteId = $ cartItem ->getQuoteId ();
80
+ $ quoteIdMask = $ this ->quoteIdMaskFactory ->create ()->load ($ maskedQuoteId , 'masked_id ' );
81
+ $ quoteId = (int )$ quoteIdMask ->getQuoteId ();
82
+ if (!$ quoteId ) {
83
+ return ;
84
+ }
85
+ try {
86
+ $ quote = $ this ->cartRepository ->get ($ quoteId );
87
+ $ storeId = (int )$ quote ->getStoreId ();
88
+ } catch (NoSuchEntityException ) {
89
+ throw new LocalizedException (__ ('Product that you are trying to add is not available. ' ));
94
90
}
95
-
96
- // Product not in quote yet
97
- $ this ->validateWebsiteAssignmentBySku ($ sku , $ storeId );
98
-
99
- } catch (NoSuchEntityException ) {
100
- throw new LocalizedException (__ ('Product that you are trying to add is not available. ' ));
101
91
}
92
+
93
+ $ this ->validateWebsiteAssignmentBySku ($ sku , $ storeId );
102
94
}
103
95
104
96
/**
@@ -119,27 +111,6 @@ private function validateWebsiteAssignmentBySku(string $sku, int $storeId): void
119
111
}
120
112
}
121
113
122
- /**
123
- * Validate by product ID for existing items
124
- *
125
- * @param int $productId
126
- * @param int $storeId
127
- * @return void
128
- * @throws LocalizedException
129
- */
130
- private function validateWebsiteAssignment (int $ productId , int $ storeId ): void
131
- {
132
- try {
133
- $ product = $ this ->productRepository ->getById ($ productId , false , $ storeId );
134
- if (empty ($ product ->getWebsiteIds ())) {
135
- return ;
136
- }
137
- $ this ->checkProductInWebsite ($ product ->getWebsiteIds (), $ storeId );
138
- } catch (NoSuchEntityException ) {
139
- throw new LocalizedException (__ ('Product that you are trying to add is not available. ' ));
140
- }
141
- }
142
-
143
114
/**
144
115
* Validate by product ID for existing items
145
116
*
0 commit comments