| 
 | 1 | +diff --git a/vendor/magento/module-visual-merchandiser/Block/Adminhtml/Category/Merchandiser.php b/vendor/magento/module-visual-merchandiser/Block/Adminhtml/Category/Merchandiser.php  | 
 | 2 | +index 5203bf246c8..1d34f5aedc1 100644  | 
 | 3 | +--- a/vendor/magento/module-visual-merchandiser/Block/Adminhtml/Category/Merchandiser.php  | 
 | 4 | ++++ b/vendor/magento/module-visual-merchandiser/Block/Adminhtml/Category/Merchandiser.php  | 
 | 5 | +@@ -7,6 +7,7 @@ namespace Magento\VisualMerchandiser\Block\Adminhtml\Category;  | 
 | 6 | +   | 
 | 7 | + use Magento\Backend\Block\Template;  | 
 | 8 | + use Magento\Backend\Block\Widget\Context;  | 
 | 9 | ++use Magento\Framework\Exception\NoSuchEntityException;  | 
 | 10 | + use Magento\Framework\Registry;  | 
 | 11 | + use Magento\VisualMerchandiser\Model\Position\Cache;  | 
 | 12 | +   | 
 | 13 | +@@ -49,6 +50,7 @@ class Merchandiser extends Template  | 
 | 14 | +      * Get dialog URL  | 
 | 15 | +      *  | 
 | 16 | +      * @return string  | 
 | 17 | ++     * @throws NoSuchEntityException  | 
 | 18 | +      * @since 100.1.0  | 
 | 19 | +      */  | 
 | 20 | +     public function getDialogUrl()  | 
 | 21 | +@@ -58,7 +60,8 @@ class Merchandiser extends Template  | 
 | 22 | +             [  | 
 | 23 | +                 'cache_key' => $this->getPositionCacheKey(),  | 
 | 24 | +                 'componentJson' => true,  | 
 | 25 | +-                'category_id' => $this->getCategoryId()  | 
 | 26 | ++                'category_id' => $this->getCategoryId(),  | 
 | 27 | ++                'store_id' => $this->getStoreId()  | 
 | 28 | +             ]  | 
 | 29 | +         );  | 
 | 30 | +     }  | 
 | 31 | +@@ -96,6 +99,17 @@ class Merchandiser extends Template  | 
 | 32 | +         return $this->getRequest()->getParam('id');  | 
 | 33 | +     }  | 
 | 34 | +   | 
 | 35 | ++    /**  | 
 | 36 | ++     * Retrieve current store id  | 
 | 37 | ++     *  | 
 | 38 | ++     * @return int  | 
 | 39 | ++     * @throws NoSuchEntityException  | 
 | 40 | ++     */  | 
 | 41 | ++    private function getStoreId(): int  | 
 | 42 | ++    {  | 
 | 43 | ++        return $this->_storeManager->getStore()->getId();  | 
 | 44 | ++    }  | 
 | 45 | ++  | 
 | 46 | +     /**  | 
 | 47 | +      * Get position cache key  | 
 | 48 | +      *  | 
 | 49 | +diff --git a/vendor/magento/module-visual-merchandiser/Model/Category/Products.php b/vendor/magento/module-visual-merchandiser/Model/Category/Products.php  | 
 | 50 | +index 8a809eaae39..d2fcb04e8b3 100644  | 
 | 51 | +--- a/vendor/magento/module-visual-merchandiser/Model/Category/Products.php  | 
 | 52 | ++++ b/vendor/magento/module-visual-merchandiser/Model/Category/Products.php  | 
 | 53 | +@@ -146,6 +146,9 @@ class Products  | 
 | 54 | +                     'small_image'  | 
 | 55 | +                 ]  | 
 | 56 | +             );  | 
 | 57 | ++        if ($store !== null) {  | 
 | 58 | ++            $collection->setStoreId((int)$store);  | 
 | 59 | ++        }  | 
 | 60 | +   | 
 | 61 | +         $collection = $this->quantityStockResolver->joinStock($collection);  | 
 | 62 | +   | 
 | 63 | +diff --git a/vendor/magento/module-visual-merchandiser/Model/Product/DataProvider.php b/vendor/magento/module-visual-merchandiser/Model/Product/DataProvider.php  | 
 | 64 | +index e403151caa2..55f9b921877 100755  | 
 | 65 | +--- a/vendor/magento/module-visual-merchandiser/Model/Product/DataProvider.php  | 
 | 66 | ++++ b/vendor/magento/module-visual-merchandiser/Model/Product/DataProvider.php  | 
 | 67 | +@@ -12,9 +12,9 @@ use Magento\Framework\Api\Filter;  | 
 | 68 | + use Magento\Framework\App\ObjectManager;  | 
 | 69 | + use Magento\Framework\App\RequestInterface;  | 
 | 70 | + use Magento\Framework\Exception\LocalizedException;  | 
 | 71 | +-use Magento\Store\Model\Store;  | 
 | 72 | + use Magento\Ui\DataProvider\AbstractDataProvider;  | 
 | 73 | + use Magento\VisualMerchandiser\Model\Position\Cache;  | 
 | 74 | ++use Magento\VisualMerchandiser\Model\Resolver\QuantityAndStock;  | 
 | 75 | +   | 
 | 76 | + /**  | 
 | 77 | +  * Class DataProvider for the Visual Merchandiser product selection grid  | 
 | 78 | +@@ -46,6 +46,12 @@ class DataProvider extends AbstractDataProvider  | 
 | 79 | +      */  | 
 | 80 | +     private $positionResolver;  | 
 | 81 | +   | 
 | 82 | ++    /**  | 
 | 83 | ++     * @var QuantityAndStock|mixed  | 
 | 84 | ++     */  | 
 | 85 | ++    private QuantityAndStock $quantityAndStock;  | 
 | 86 | ++  | 
 | 87 | ++  | 
 | 88 | +     /**  | 
 | 89 | +      * @param string $name  | 
 | 90 | +      * @param string $primaryFieldName  | 
 | 91 | +@@ -56,7 +62,9 @@ class DataProvider extends AbstractDataProvider  | 
 | 92 | +      * @param array $meta  | 
 | 93 | +      * @param array $data  | 
 | 94 | +      * @param PositionResolver|null $positionResolver  | 
 | 95 | ++     * @param QuantityAndStock|null $quantityAndStock  | 
 | 96 | +      * @throws LocalizedException  | 
 | 97 | ++     * @SuppressWarnings(PHPMD.ExcessiveParameterList)  | 
 | 98 | +      */  | 
 | 99 | +     public function __construct(  | 
 | 100 | +         $name,  | 
 | 101 | +@@ -67,13 +75,15 @@ class DataProvider extends AbstractDataProvider  | 
 | 102 | +         Cache $cache,  | 
 | 103 | +         array $meta = [],  | 
 | 104 | +         array $data = [],  | 
 | 105 | +-        ?PositionResolver $positionResolver = null  | 
 | 106 | ++        ?PositionResolver $positionResolver = null,  | 
 | 107 | ++        ?QuantityAndStock $quantityAndStock = null  | 
 | 108 | +     ) {  | 
 | 109 | +         parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);  | 
 | 110 | +   | 
 | 111 | +         $this->request = $request;  | 
 | 112 | +         $this->cache = $cache;  | 
 | 113 | +         $this->positionResolver = $positionResolver ?: ObjectManager::getInstance()->get(PositionResolver::class);  | 
 | 114 | ++        $this->quantityAndStock = $quantityAndStock ?: ObjectManager::getInstance()->get(QuantityAndStock::class);  | 
 | 115 | +   | 
 | 116 | +         $this->collection = $collectionFactory->create()->addAttributeToSelect(  | 
 | 117 | +             'sku'  | 
 | 118 | +@@ -87,14 +97,9 @@ class DataProvider extends AbstractDataProvider  | 
 | 119 | +             'price'  | 
 | 120 | +         );  | 
 | 121 | +   | 
 | 122 | +-        $this->collection->joinField(  | 
 | 123 | +-            'qty',  | 
 | 124 | +-            'cataloginventory_stock_item',  | 
 | 125 | +-            'qty',  | 
 | 126 | +-            'product_id=entity_id',  | 
 | 127 | +-            '{{table}}.stock_id=1',  | 
 | 128 | +-            'left'  | 
 | 129 | +-        );  | 
 | 130 | ++        $this->collection->setStoreId($this->request->getParam('store_id', "0"));  | 
 | 131 | ++        $this->collection = $this->quantityAndStock->joinStock($this->collection);  | 
 | 132 | ++        $this->collection->getSelect()->group('e.entity_id');  | 
 | 133 | +   | 
 | 134 | +         $this->prepareUpdateUrl();  | 
 | 135 | +     }  | 
 | 136 | +@@ -139,6 +144,8 @@ class DataProvider extends AbstractDataProvider  | 
 | 137 | +                 $this->positionCacheKey = $paramValue;  | 
 | 138 | +             } elseif ('%category_id%' === $paramValue) {  | 
 | 139 | +                 $paramValue = $this->request->getParam($paramName);  | 
 | 140 | ++            } elseif ('%store_id%' === $paramValue) {  | 
 | 141 | ++                $paramValue = $this->request->getParam($paramName, "0");  | 
 | 142 | +             }  | 
 | 143 | +   | 
 | 144 | +             if ($paramValue) {  | 
 | 145 | +@@ -192,23 +199,25 @@ class DataProvider extends AbstractDataProvider  | 
 | 146 | +      */  | 
 | 147 | +     public function getData()  | 
 | 148 | +     {  | 
 | 149 | +-        $this->collection->setStoreId(Store::DEFAULT_STORE_ID);  | 
 | 150 | +         $this->collection->getLimitationFilters()->setUsePriceIndex(false);  | 
 | 151 | +         $this->addPositionData();  | 
 | 152 | +         $positions = $this->cache->getPositions($this->positionCacheKey);  | 
 | 153 | +         $categoryId = $this->request->getParam('category_id');  | 
 | 154 | +         $arrItems = [];  | 
 | 155 | +-        $arrItems['totalRecords'] = $this->collection->getSize();  | 
 | 156 | ++        $arrItems['totalRecords'] = count($this->collection->getItems());  | 
 | 157 | +         $arrItems['items'] = [];  | 
 | 158 | ++        $arrItems['allIds'] = [];  | 
 | 159 | +         if ($positions === false && $categoryId !== null) {  | 
 | 160 | +             $arrItems['selectedData'] = $this->positionResolver->getPositions((int) $categoryId);  | 
 | 161 | +         } else {  | 
 | 162 | +             $arrItems['selectedData'] = $positions;  | 
 | 163 | +         }  | 
 | 164 | +-        $arrItems['allIds'] = $this->collection->getAllIds();  | 
 | 165 | +   | 
 | 166 | +         foreach ($this->collection->getItems() as $item) {  | 
 | 167 | +-            $arrItems['items'][] =  $item->toArray();  | 
 | 168 | ++            $itemDetails = $item->toArray();  | 
 | 169 | ++            $itemDetails['qty'] = $itemDetails['stock'] ?? 0;  | 
 | 170 | ++            $arrItems['items'][] = $itemDetails;  | 
 | 171 | ++            $arrItems['allIds'][] = $item->getId();  | 
 | 172 | +         }  | 
 | 173 | +   | 
 | 174 | +         return $arrItems;  | 
 | 175 | +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  | 
 | 176 | +index 848bf1f059d..d3c3b9c5147 100755  | 
 | 177 | +--- a/vendor/magento/module-visual-merchandiser/view/adminhtml/ui_component/merchandiser_product_listing.xml  | 
 | 178 | ++++ b/vendor/magento/module-visual-merchandiser/view/adminhtml/ui_component/merchandiser_product_listing.xml  | 
 | 179 | +@@ -23,6 +23,7 @@  | 
 | 180 | +             <filterUrlParams>  | 
 | 181 | +                 <param name="cache_key">*</param>  | 
 | 182 | +                 <param name="category_id">%category_id%</param>  | 
 | 183 | ++                <param name="store_id">%store_id%</param>  | 
 | 184 | +             </filterUrlParams>  | 
 | 185 | +             <updateUrl path="mui/index/render"/>  | 
 | 186 | +         </settings>  | 
0 commit comments