diff --git a/vendor/magento/module-visual-merchandiser/Block/Adminhtml/Category/Merchandiser.php b/vendor/magento/module-visual-merchandiser/Block/Adminhtml/Category/Merchandiser.php
index 5203bf246c8..1d34f5aedc1 100644
--- a/vendor/magento/module-visual-merchandiser/Block/Adminhtml/Category/Merchandiser.php
+++ b/vendor/magento/module-visual-merchandiser/Block/Adminhtml/Category/Merchandiser.php
@@ -7,6 +7,7 @@ namespace Magento\VisualMerchandiser\Block\Adminhtml\Category;
use Magento\Backend\Block\Template;
use Magento\Backend\Block\Widget\Context;
+use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Registry;
use Magento\VisualMerchandiser\Model\Position\Cache;
@@ -49,6 +50,7 @@ class Merchandiser extends Template
* Get dialog URL
*
* @return string
+ * @throws NoSuchEntityException
* @since 100.1.0
*/
public function getDialogUrl()
@@ -58,7 +60,8 @@ class Merchandiser extends Template
[
'cache_key' => $this->getPositionCacheKey(),
'componentJson' => true,
- 'category_id' => $this->getCategoryId()
+ 'category_id' => $this->getCategoryId(),
+ 'store_id' => $this->getStoreId()
]
);
}
@@ -96,6 +99,17 @@ class Merchandiser extends Template
return $this->getRequest()->getParam('id');
}
+ /**
+ * Retrieve current store id
+ *
+ * @return int
+ * @throws NoSuchEntityException
+ */
+ private function getStoreId(): int
+ {
+ return $this->_storeManager->getStore()->getId();
+ }
+
/**
* Get position cache key
*
diff --git a/vendor/magento/module-visual-merchandiser/Model/Category/Products.php b/vendor/magento/module-visual-merchandiser/Model/Category/Products.php
index 8a809eaae39..d2fcb04e8b3 100644
--- a/vendor/magento/module-visual-merchandiser/Model/Category/Products.php
+++ b/vendor/magento/module-visual-merchandiser/Model/Category/Products.php
@@ -146,6 +146,9 @@ class Products
'small_image'
]
);
+ if ($store !== null) {
+ $collection->setStoreId((int)$store);
+ }
$collection = $this->quantityStockResolver->joinStock($collection);
diff --git a/vendor/magento/module-visual-merchandiser/Model/Product/DataProvider.php b/vendor/magento/module-visual-merchandiser/Model/Product/DataProvider.php
index e403151caa2..55f9b921877 100755
--- a/vendor/magento/module-visual-merchandiser/Model/Product/DataProvider.php
+++ b/vendor/magento/module-visual-merchandiser/Model/Product/DataProvider.php
@@ -12,9 +12,9 @@ use Magento\Framework\Api\Filter;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\Exception\LocalizedException;
-use Magento\Store\Model\Store;
use Magento\Ui\DataProvider\AbstractDataProvider;
use Magento\VisualMerchandiser\Model\Position\Cache;
+use Magento\VisualMerchandiser\Model\Resolver\QuantityAndStock;
/**
* Class DataProvider for the Visual Merchandiser product selection grid
@@ -46,6 +46,12 @@ class DataProvider extends AbstractDataProvider
*/
private $positionResolver;
+ /**
+ * @var QuantityAndStock|mixed
+ */
+ private QuantityAndStock $quantityAndStock;
+
+
/**
* @param string $name
* @param string $primaryFieldName
@@ -56,7 +62,9 @@ class DataProvider extends AbstractDataProvider
* @param array $meta
* @param array $data
* @param PositionResolver|null $positionResolver
+ * @param QuantityAndStock|null $quantityAndStock
* @throws LocalizedException
+ * @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
$name,
@@ -67,13 +75,15 @@ class DataProvider extends AbstractDataProvider
Cache $cache,
array $meta = [],
array $data = [],
- ?PositionResolver $positionResolver = null
+ ?PositionResolver $positionResolver = null,
+ ?QuantityAndStock $quantityAndStock = null
) {
parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->request = $request;
$this->cache = $cache;
$this->positionResolver = $positionResolver ?: ObjectManager::getInstance()->get(PositionResolver::class);
+ $this->quantityAndStock = $quantityAndStock ?: ObjectManager::getInstance()->get(QuantityAndStock::class);
$this->collection = $collectionFactory->create()->addAttributeToSelect(
'sku'
@@ -87,14 +97,9 @@ class DataProvider extends AbstractDataProvider
'price'
);
- $this->collection->joinField(
- 'qty',
- 'cataloginventory_stock_item',
- 'qty',
- 'product_id=entity_id',
- '{{table}}.stock_id=1',
- 'left'
- );
+ $this->collection->setStoreId($this->request->getParam('store_id', "0"));
+ $this->collection = $this->quantityAndStock->joinStock($this->collection);
+ $this->collection->getSelect()->group('e.entity_id');
$this->prepareUpdateUrl();
}
@@ -139,6 +144,8 @@ class DataProvider extends AbstractDataProvider
$this->positionCacheKey = $paramValue;
} elseif ('%category_id%' === $paramValue) {
$paramValue = $this->request->getParam($paramName);
+ } elseif ('%store_id%' === $paramValue) {
+ $paramValue = $this->request->getParam($paramName, "0");
}
if ($paramValue) {
@@ -192,23 +199,25 @@ class DataProvider extends AbstractDataProvider
*/
public function getData()
{
- $this->collection->setStoreId(Store::DEFAULT_STORE_ID);
$this->collection->getLimitationFilters()->setUsePriceIndex(false);
$this->addPositionData();
$positions = $this->cache->getPositions($this->positionCacheKey);
$categoryId = $this->request->getParam('category_id');
$arrItems = [];
- $arrItems['totalRecords'] = $this->collection->getSize();
+ $arrItems['totalRecords'] = count($this->collection->getItems());
$arrItems['items'] = [];
+ $arrItems['allIds'] = [];
if ($positions === false && $categoryId !== null) {
$arrItems['selectedData'] = $this->positionResolver->getPositions((int) $categoryId);
} else {
$arrItems['selectedData'] = $positions;
}
- $arrItems['allIds'] = $this->collection->getAllIds();
foreach ($this->collection->getItems() as $item) {
- $arrItems['items'][] = $item->toArray();
+ $itemDetails = $item->toArray();
+ $itemDetails['qty'] = $itemDetails['stock'] ?? 0;
+ $arrItems['items'][] = $itemDetails;
+ $arrItems['allIds'][] = $item->getId();
}
return $arrItems;
diff --git a/vendor/magento/module-visual-merchandiser/view/adminhtml/ui_component/merchandiser_product_listing.xml b/vendor/magento/module-visual-merchandiser/view/adminhtml/ui_component/merchandiser_product_listing.xml
index 848bf1f059d..d3c3b9c5147 100755
--- a/vendor/magento/module-visual-merchandiser/view/adminhtml/ui_component/merchandiser_product_listing.xml
+++ b/vendor/magento/module-visual-merchandiser/view/adminhtml/ui_component/merchandiser_product_listing.xml
@@ -23,6 +23,7 @@
*
%category_id%
+ %store_id%