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..33e80825f69 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,11 @@ class DataProvider extends AbstractDataProvider
*/
private $positionResolver;
+ /**
+ * @var QuantityAndStock|mixed
+ */
+ private QuantityAndStock $quantityAndStock;
+
/**
* @param string $name
* @param string $primaryFieldName
@@ -56,7 +61,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 +74,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 +96,13 @@ 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');
+ $subSelect = clone($this->collection->getSelect());
+ $this->collection->getSelect()->reset()->from(['e' => $subSelect]);
+ $this->collection->addStaticField('stock');
$this->prepareUpdateUrl();
}
@@ -139,6 +147,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 +202,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['items'] = [];
+ $arrItems['allIds'] = array_map('intval', $this->collection->getAllIds());
+ $arrItems['totalRecords'] = count($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..3ceb7a06bc8 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%
@@ -78,7 +79,7 @@
-
+
textRange
number
diff --git a/vendor/magento/module-visual-merchandiser/view/adminhtml/web/js/mass_sku.js b/vendor/magento/module-visual-merchandiser/view/adminhtml/web/js/mass_sku.js
index b746a2ba352..a48323eb3ce 100644
--- a/vendor/magento/module-visual-merchandiser/view/adminhtml/web/js/mass_sku.js
+++ b/vendor/magento/module-visual-merchandiser/view/adminhtml/web/js/mass_sku.js
@@ -4,8 +4,9 @@
*/
/*global setLocation:true*/
define([
- 'jquery'
-], function ($) {
+ 'jquery',
+ 'uiRegistry'
+], function ($, registry) {
'use strict';
$.widget('mage.visualMerchandiserMassSku', {
@@ -20,6 +21,7 @@ define([
* @private
*/
_create: function () {
+ this.registry = registry;
this.form = this.element.find('form');
this._bind();
},
@@ -28,9 +30,36 @@ define([
* @private
*/
_bind: function () {
+ var self = this;
+
+ self._disableActionButtons(true);
+ this.registry.get(
+ 'merchandiser_product_listing.merchandiser_product_listing_data_source',
+ function (listingDataSource) {
+ if (!listingDataSource.firstLoad) {
+ self._disableActionButtons(false);
+ }
+ listingDataSource.on('reload', function () {
+ self._disableActionButtons(true);
+ });
+ listingDataSource.on('reloaded', function () {
+ self._disableActionButtons(false);
+ });
+ }
+ );
$(this.options.massAssignButton).on('click', $.proxy(this._massAssignAction, this));
},
+ /**
+ * Toggle state of action buttons.
+ *
+ * @param {Boolean} disabled
+ * @private
+ */
+ _disableActionButtons: function (disabled) {
+ $(this.options.massAssignButton).attr('disabled', disabled);
+ },
+
/**
* @param {Event} event
* @private