From 070520018bbc968aa7400e5bb90c754816ee422e Mon Sep 17 00:00:00 2001 From: sonikasi22 Date: Fri, 25 Oct 2024 00:04:12 +0530 Subject: [PATCH 1/5] EC-995 #comment stock status fix --- app/code/Ometria/Api/Controller/V1/Products.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/code/Ometria/Api/Controller/V1/Products.php b/app/code/Ometria/Api/Controller/V1/Products.php index c81f917..1e965b4 100755 --- a/app/code/Ometria/Api/Controller/V1/Products.php +++ b/app/code/Ometria/Api/Controller/V1/Products.php @@ -485,8 +485,17 @@ protected function appendPricing($productId, $item, $storeId = null, $baseCurren */ private function appendStock($productId, $item) { - $websiteId = $this->storeManager->getWebsite()->getId(); - $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); + $product = $this->productRepository->getById($productId); + $storeIds = $product->getStoreIds(); + if (empty($storeIds)) { + $websiteId = $this->storeManager->getWebsite()->getId(); + $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); + } else { + $storeId = $storeIds[0]; + $store = $this->storeManager->getStore($storeId); + $websiteId = $store->getWebsiteId(); + $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); + } if (isset($stockItem['is_in_stock'])) { $item['is_in_stock'] = $stockItem['is_in_stock']; From 784e6b2f2e5b9c336ebaca0159235889aa052d4c Mon Sep 17 00:00:00 2001 From: sonikasi22 Date: Fri, 15 Nov 2024 18:51:35 +0530 Subject: [PATCH 2/5] EC-995-2 #comment Store field in Configuration and its conditionds --- .../Ometria/Api/Controller/V1/Products.php | 38 +++++++++++++++---- .../Ometria/Core/etc/adminhtml/system.xml | 4 ++ 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/app/code/Ometria/Api/Controller/V1/Products.php b/app/code/Ometria/Api/Controller/V1/Products.php index 1e965b4..02e0d96 100755 --- a/app/code/Ometria/Api/Controller/V1/Products.php +++ b/app/code/Ometria/Api/Controller/V1/Products.php @@ -14,6 +14,8 @@ use Ometria\Api\Helper\Filter\V1\Service as FilterService; use Ometria\Api\Helper\Format\V1\Products as Helper; use Ometria\Api\Model\ResourceModel\Product as ProductResource; +use Magento\Framework\App\Config\ScopeConfigInterface; +use Magento\Store\Model\ScopeInterface; class Products extends Base { @@ -40,6 +42,8 @@ class Products extends Base protected $directoryHelper; protected $storeUrlHelper; + protected $scopeConfig; + /** @var StockRegistryInterface */ private $stockRegistry; @@ -93,7 +97,8 @@ public function __construct( StockRegistryInterface $stockRegistry, HttpContext $httpContext, AppEmulation $appEmulation, - ProductResource $productResource + ProductResource $productResource, + ScopeConfigInterface $scopeConfig ) { parent::__construct($context); $this->searchCriteriaBuilder = $searchCriteriaBuilder; @@ -118,6 +123,7 @@ public function __construct( $this->httpContext = $httpContext; $this->appEmulation = $appEmulation; $this->productResource = $productResource; + $this->scopeConfig = $scopeConfig; } public function execute() @@ -485,16 +491,25 @@ protected function appendPricing($productId, $item, $storeId = null, $baseCurren */ private function appendStock($productId, $item) { - $product = $this->productRepository->getById($productId); - $storeIds = $product->getStoreIds(); + $storeIds = $this->getStoreIdsForStock(); if (empty($storeIds)) { $websiteId = $this->storeManager->getWebsite()->getId(); $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); } else { - $storeId = $storeIds[0]; - $store = $this->storeManager->getStore($storeId); - $websiteId = $store->getWebsiteId(); - $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); + if (count($storeIds) === 1 && $storeIds[0] === '*') { + $product = $this->productRepository->getById($productId); + $productStoreIds = $product->getStoreIds(); + } else { + $productStoreIds = $storeIds; + } + foreach($productStoreIds as $key => $storeId) { + $store = $this->storeManager->getStore($storeId); + $websiteId = $store->getWebsiteId(); + $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); + if (isset($stockItem['is_in_stock']) && ($stockItem['is_in_stock'] == 1)){ + break; + } + } } if (isset($stockItem['is_in_stock'])) { @@ -508,6 +523,15 @@ private function appendStock($productId, $item) return $item; } + private function getStoreIdsForStock(){ + $configStoreIds = $this->scopeConfig->getValue('ometria/advanced/stock_store_ids', ScopeInterface::SCOPE_STORE); + if (empty($configStoreIds)) { + return []; + } + $storeIds = array_filter(array_map('trim', explode(PHP_EOL, $configStoreIds))); + return $storeIds; + } + protected function getProductPrice( $productId, $storeId, diff --git a/app/code/Ometria/Core/etc/adminhtml/system.xml b/app/code/Ometria/Core/etc/adminhtml/system.xml index 106f9fd..712e9d4 100755 --- a/app/code/Ometria/Core/etc/adminhtml/system.xml +++ b/app/code/Ometria/Core/etc/adminhtml/system.xml @@ -94,6 +94,10 @@ Magento\Config\Model\Config\Source\Yesno + + + + Enter values separated by new lines. Enter * to check all the stores From 95152d8a3d76bf647cfb91330fbe80a4db49665b Mon Sep 17 00:00:00 2001 From: sonikasi22 Date: Wed, 20 Nov 2024 11:59:20 +0530 Subject: [PATCH 3/5] Extension version upgrade for release --- app/code/Ometria/AbandonedCarts/etc/module.xml | 2 +- app/code/Ometria/Api/etc/module.xml | 2 +- app/code/Ometria/Core/etc/module.xml | 2 +- composer.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/code/Ometria/AbandonedCarts/etc/module.xml b/app/code/Ometria/AbandonedCarts/etc/module.xml index c067f8e..1c16853 100755 --- a/app/code/Ometria/AbandonedCarts/etc/module.xml +++ b/app/code/Ometria/AbandonedCarts/etc/module.xml @@ -1,4 +1,4 @@ - + diff --git a/app/code/Ometria/Api/etc/module.xml b/app/code/Ometria/Api/etc/module.xml index c1306a5..2f7b9ec 100755 --- a/app/code/Ometria/Api/etc/module.xml +++ b/app/code/Ometria/Api/etc/module.xml @@ -1,4 +1,4 @@ - + diff --git a/app/code/Ometria/Core/etc/module.xml b/app/code/Ometria/Core/etc/module.xml index 389b39e..d073841 100755 --- a/app/code/Ometria/Core/etc/module.xml +++ b/app/code/Ometria/Core/etc/module.xml @@ -1,4 +1,4 @@ - + diff --git a/composer.json b/composer.json index ad326e1..92a49b4 100755 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "ometria/magento2", "type": "magento2-module", - "version": "2.6.7", + "version": "2.6.8", "description": "Dev composer package for Ometria Extension", "authors": [ { From 697f3a35e4e1783a5b07a1c36bfe20a0108a7475 Mon Sep 17 00:00:00 2001 From: sonikasi22 Date: Wed, 27 Nov 2024 13:42:17 +0530 Subject: [PATCH 4/5] EC-1048 #comment stock status code improvements --- .../Ometria/Api/Controller/V1/Products.php | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/app/code/Ometria/Api/Controller/V1/Products.php b/app/code/Ometria/Api/Controller/V1/Products.php index 02e0d96..1365710 100755 --- a/app/code/Ometria/Api/Controller/V1/Products.php +++ b/app/code/Ometria/Api/Controller/V1/Products.php @@ -491,29 +491,23 @@ protected function appendPricing($productId, $item, $storeId = null, $baseCurren */ private function appendStock($productId, $item) { + $stockStatus = 0; $storeIds = $this->getStoreIdsForStock(); - if (empty($storeIds)) { + if (empty($storeIds) || (count($storeIds) === 1 && $storeIds[0] === '*')) { $websiteId = $this->storeManager->getWebsite()->getId(); $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); - } else { - if (count($storeIds) === 1 && $storeIds[0] === '*') { - $product = $this->productRepository->getById($productId); - $productStoreIds = $product->getStoreIds(); - } else { - $productStoreIds = $storeIds; + if (isset($stockItem['is_in_stock'])) { + $item['is_in_stock'] = $stockItem['is_in_stock']; } + } else { + $productStoreIds = $storeIds; foreach($productStoreIds as $key => $storeId) { $store = $this->storeManager->getStore($storeId); $websiteId = $store->getWebsiteId(); $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); - if (isset($stockItem['is_in_stock']) && ($stockItem['is_in_stock'] == 1)){ - break; - } + $stockStatus = $this->stockRegistry->getProductStockStatus($productId, $websiteId); } - } - - if (isset($stockItem['is_in_stock'])) { - $item['is_in_stock'] = $stockItem['is_in_stock']; + $item['is_in_stock'] = $stockStatus; } if (isset($stockItem['qty'])) { From 2955a11a0167c630670bee0cb00737b12fc91764 Mon Sep 17 00:00:00 2001 From: sonikasi22 Date: Thu, 5 Dec 2024 20:45:49 +0530 Subject: [PATCH 5/5] EC-1048 #comment multiple store id code changes --- app/code/Ometria/Api/Controller/V1/Products.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Ometria/Api/Controller/V1/Products.php b/app/code/Ometria/Api/Controller/V1/Products.php index 1365710..c959d26 100755 --- a/app/code/Ometria/Api/Controller/V1/Products.php +++ b/app/code/Ometria/Api/Controller/V1/Products.php @@ -506,6 +506,9 @@ private function appendStock($productId, $item) $websiteId = $store->getWebsiteId(); $stockItem = $this->stockRegistry->getStockItem($productId, $websiteId); $stockStatus = $this->stockRegistry->getProductStockStatus($productId, $websiteId); + if ($stockStatus == 1){ + break; + } } $item['is_in_stock'] = $stockStatus; }