diff --git a/vendor/magento/module-quote/Model/Quote/Plugin/UpdateQuoteStoreId.php b/vendor/magento/module-quote/Model/Quote/Plugin/UpdateQuoteStoreId.php new file mode 100644 index 00000000000..ad1880a0545 --- /dev/null +++ b/vendor/magento/module-quote/Model/Quote/Plugin/UpdateQuoteStoreId.php @@ -0,0 +1,99 @@ +storeManager = $storeManager; + $this->request = $request; + } + + /** + * Update store id in requested quote by store id from guest's request. + * + * @param Quote $subject + * @param Quote $result + * @return Quote + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterLoadByIdWithoutStore(Quote $subject, Quote $result): Quote + { + return $this->updateStoreId($result); + } + + /** + * Update store id in requested quote by store id from registered customer's request. + * + * @param Quote $subject + * @param Quote $result + * @return Quote + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function afterLoadByCustomer(Quote $subject, Quote $result): Quote + { + return $this->updateStoreId($result); + } + + /** + * Returns store based on web-api request path. + * + * @param string $requestPath + * @return StoreInterface|null + */ + private function getStore(string $requestPath): ?StoreInterface + { + $pathParts = explode('/', trim($requestPath, '/')); + array_shift($pathParts); + $storeCode = current($pathParts); + $stores = $this->storeManager->getStores(false, true); + + return $stores[$storeCode] ?? null; + } + + /** + * Update store id in requested quote by store id from request. + * + * @param Quote $quote + * @return Quote + */ + private function updateStoreId(Quote $quote): Quote + { + $store = $this->getStore($this->request->getPathInfo()); + if ($store) { + $quote->setStoreId($store->getId()); + } + + return $quote; + } +} diff --git a/vendor/magento/module-quote/etc/webapi_rest/di.xml b/vendor/magento/module-quote/etc/webapi_rest/di.xml index a55d2146be1..6ed9909f04e 100644 --- a/vendor/magento/module-quote/etc/webapi_rest/di.xml +++ b/vendor/magento/module-quote/etc/webapi_rest/di.xml @@ -16,4 +16,7 @@ + + + diff --git a/vendor/magento/module-quote/etc/webapi_soap/di.xml b/vendor/magento/module-quote/etc/webapi_soap/di.xml index 27d5ff77534..4b7646b6e1e 100644 --- a/vendor/magento/module-quote/etc/webapi_soap/di.xml +++ b/vendor/magento/module-quote/etc/webapi_soap/di.xml @@ -13,4 +13,7 @@ + + +