|
| 1 | +diff --git a/vendor/magento/module-shared-catalog/Controller/Adminhtml/SharedCatalog/Configure/Save.php b/vendor/magento/module-shared-catalog/Controller/Adminhtml/SharedCatalog/Configure/Save.php |
| 2 | +index 15e9457744..f1c5db7e5a 100644 |
| 3 | +--- a/vendor/magento/module-shared-catalog/Controller/Adminhtml/SharedCatalog/Configure/Save.php |
| 4 | ++++ b/vendor/magento/module-shared-catalog/Controller/Adminhtml/SharedCatalog/Configure/Save.php |
| 5 | +@@ -27,6 +27,9 @@ use Psr\Log\LoggerInterface; |
| 6 | + |
| 7 | + /** |
| 8 | + * Save shared catalog structure and pricing. |
| 9 | ++ * |
| 10 | ++ * @SuppressWarnings(PHPMD.CouplingBetweenObjects) |
| 11 | ++ * @SuppressWarnings(PHPMD.ExcessiveParameterList) |
| 12 | + */ |
| 13 | + class Save extends Action implements HttpPostActionInterface |
| 14 | + { |
| 15 | +@@ -137,7 +140,8 @@ class Save extends Action implements HttpPostActionInterface |
| 16 | + try { |
| 17 | + $resultDiff = $this->diffProcessor->getDiff($currentStorage, $sharedCatalogId); |
| 18 | + |
| 19 | +- $storeId = $this->getRequest()->getParam('store_id'); |
| 20 | ++ // store_id filter stand for store group id (group_id from store_group) |
| 21 | ++ $storeId = (int)$this->getRequest()->getParam('store_id'); |
| 22 | + $sharedCatalog = $this->configureCategory->saveConfiguredCategories( |
| 23 | + $currentStorage, |
| 24 | + $sharedCatalogId, |
| 25 | +@@ -185,7 +189,7 @@ class Save extends Action implements HttpPostActionInterface |
| 26 | + * @throws LocalizedException |
| 27 | + * @throws NoSuchEntityException |
| 28 | + */ |
| 29 | +- private function excludeWebsites($storeId, $customerGroupId) |
| 30 | ++ private function excludeWebsites(?int $storeId, int $customerGroupId) |
| 31 | + { |
| 32 | + if ($storeId > 0) { |
| 33 | + $allWebsiteIds = []; |
| 34 | +@@ -195,8 +199,8 @@ class Save extends Action implements HttpPostActionInterface |
| 35 | + $allWebsiteIds[] = $website->getId(); |
| 36 | + } |
| 37 | + |
| 38 | +- //get website id which should be included |
| 39 | +- $websiteId = $this->storeManager->getStore($storeId)->getWebsiteId(); |
| 40 | ++ //get website id which should be included based on selected store group |
| 41 | ++ $websiteId = $this->storeManager->getGroup($storeId)->getWebsiteId(); |
| 42 | + |
| 43 | + //exclude websites from customer group |
| 44 | + $excludeWebsiteIds = array_diff($allWebsiteIds, [$websiteId]); |
| 45 | +diff --git a/vendor/magento/module-shared-catalog/Model/Configure/Category.php b/vendor/magento/module-shared-catalog/Model/Configure/Category.php |
| 46 | +index 4612b47f2d..b4f4e5277f 100644 |
| 47 | +--- a/vendor/magento/module-shared-catalog/Model/Configure/Category.php |
| 48 | ++++ b/vendor/magento/module-shared-catalog/Model/Configure/Category.php |
| 49 | +@@ -62,6 +62,7 @@ class Category |
| 50 | + $assignedCategoriesIds = $currentStorage->getAssignedCategoriesIds(); |
| 51 | + $unassignedCategoriesIds = $currentStorage->getUnassignedCategoriesIds(); |
| 52 | + |
| 53 | ++ //store_id actually stands for store group id ( group_id ) |
| 54 | + if ($sharedCatalog->getStoreId() === null) { |
| 55 | + $sharedCatalog->setStoreId($storeId); |
| 56 | + $this->sharedCatalogRepository->save($sharedCatalog); |
| 57 | +diff --git a/vendor/magento/module-shared-catalog/Plugin/Backend/Block/Adminhtml/Store/SwitcherRolePermissions.php b/vendor/magento/module-shared-catalog/Plugin/Backend/Block/Adminhtml/Store/SwitcherRolePermissions.php |
| 58 | +new file mode 100644 |
| 59 | +index 0000000000..6060fe1d09 |
| 60 | +--- /dev/null |
| 61 | ++++ b/vendor/magento/module-shared-catalog/Plugin/Backend/Block/Adminhtml/Store/SwitcherRolePermissions.php |
| 62 | +@@ -0,0 +1,59 @@ |
| 63 | ++<?php |
| 64 | ++/** |
| 65 | ++ * Copyright © Magento, Inc. All rights reserved. |
| 66 | ++ * See COPYING.txt for license details. |
| 67 | ++ */ |
| 68 | ++declare(strict_types=1); |
| 69 | ++ |
| 70 | ++namespace Magento\SharedCatalog\Plugin\Backend\Block\Adminhtml\Store; |
| 71 | ++ |
| 72 | ++use Magento\Backend\Model\Auth\Session; |
| 73 | ++use Magento\Framework\Stdlib\ArrayManager; |
| 74 | ++use Magento\SharedCatalog\Block\Adminhtml\Store\Switcher; |
| 75 | ++ |
| 76 | ++/** |
| 77 | ++ * Plugin for store switch permission based on role |
| 78 | ++ */ |
| 79 | ++class SwitcherRolePermissions |
| 80 | ++{ |
| 81 | ++ /** |
| 82 | ++ * @var Session |
| 83 | ++ */ |
| 84 | ++ private $backendAuthSession; |
| 85 | ++ |
| 86 | ++ /** |
| 87 | ++ * @var ArrayManager |
| 88 | ++ */ |
| 89 | ++ private $arrayManager; |
| 90 | ++ |
| 91 | ++ /** |
| 92 | ++ * @param Session $backendAuthSession |
| 93 | ++ * @param ArrayManager $arrayManager |
| 94 | ++ */ |
| 95 | ++ public function __construct( |
| 96 | ++ Session $backendAuthSession, |
| 97 | ++ ArrayManager $arrayManager |
| 98 | ++ ) { |
| 99 | ++ $this->backendAuthSession = $backendAuthSession; |
| 100 | ++ $this->arrayManager = $arrayManager; |
| 101 | ++ } |
| 102 | ++ |
| 103 | ++ /** |
| 104 | ++ * Remove 'All Stores' for website restricted users |
| 105 | ++ * |
| 106 | ++ * @param Switcher $subject |
| 107 | ++ * @param array $result |
| 108 | ++ * @return array |
| 109 | ++ * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 110 | ++ */ |
| 111 | ++ public function afterGetStoreOptionsAsArray( |
| 112 | ++ Switcher $subject, |
| 113 | ++ array $result |
| 114 | ++ ):array { |
| 115 | ++ $role = $this->backendAuthSession->getUser()->getRole(); |
| 116 | ++ if (!$role->getGwsIsAll() && $this->arrayManager->exists(Switcher::ALL_STORES_ID, $result)) { |
| 117 | ++ array_shift($result); |
| 118 | ++ } |
| 119 | ++ return $result; |
| 120 | ++ } |
| 121 | ++} |
| 122 | +diff --git a/vendor/magento/module-shared-catalog/Plugin/Ui/DataProvider/WebsiteRolePermissions.php b/vendor/magento/module-shared-catalog/Plugin/Ui/DataProvider/WebsiteRolePermissions.php |
| 123 | +new file mode 100644 |
| 124 | +index 0000000000..1399345b75 |
| 125 | +--- /dev/null |
| 126 | ++++ b/vendor/magento/module-shared-catalog/Plugin/Ui/DataProvider/WebsiteRolePermissions.php |
| 127 | +@@ -0,0 +1,61 @@ |
| 128 | ++<?php |
| 129 | ++/** |
| 130 | ++ * Copyright © Magento, Inc. All rights reserved. |
| 131 | ++ * See COPYING.txt for license details. |
| 132 | ++ */ |
| 133 | ++declare(strict_types=1); |
| 134 | ++ |
| 135 | ++namespace Magento\SharedCatalog\Plugin\Ui\DataProvider; |
| 136 | ++ |
| 137 | ++use Magento\Backend\Model\Auth\Session; |
| 138 | ++use Magento\Framework\Stdlib\ArrayManager; |
| 139 | ++use Magento\SharedCatalog\Ui\DataProvider\Website as Websites; |
| 140 | ++ |
| 141 | ++/** |
| 142 | ++ * Plugin for store switch permission based on role |
| 143 | ++ * |
| 144 | ++ * @SuppressWarnings(PHPMD.CookieAndSessionMisuse) |
| 145 | ++ */ |
| 146 | ++class WebsiteRolePermissions |
| 147 | ++{ |
| 148 | ++ /** |
| 149 | ++ * @var ArrayManager |
| 150 | ++ */ |
| 151 | ++ private $arrayManager; |
| 152 | ++ |
| 153 | ++ /** |
| 154 | ++ * @var Session |
| 155 | ++ */ |
| 156 | ++ private $backendAuthSession; |
| 157 | ++ |
| 158 | ++ /** |
| 159 | ++ * @param Session $backendAuthSession |
| 160 | ++ * @param ArrayManager $arrayManager |
| 161 | ++ */ |
| 162 | ++ public function __construct( |
| 163 | ++ Session $backendAuthSession, |
| 164 | ++ ArrayManager $arrayManager |
| 165 | ++ ) { |
| 166 | ++ $this->backendAuthSession = $backendAuthSession; |
| 167 | ++ $this->arrayManager = $arrayManager; |
| 168 | ++ } |
| 169 | ++ |
| 170 | ++ /** |
| 171 | ++ * Remove 'All Stores' for website restricted users |
| 172 | ++ * |
| 173 | ++ * @param Websites $subject |
| 174 | ++ * @param array $result |
| 175 | ++ * @return array |
| 176 | ++ * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
| 177 | ++ */ |
| 178 | ++ public function afterGetWebsites( |
| 179 | ++ Websites $subject, |
| 180 | ++ array $result |
| 181 | ++ ):array { |
| 182 | ++ $role = $this->backendAuthSession->getUser()->getRole(); |
| 183 | ++ if (!$role->getGwsIsAll() && $this->arrayManager->exists(0, $result)) { |
| 184 | ++ array_shift($result); |
| 185 | ++ } |
| 186 | ++ return $result; |
| 187 | ++ } |
| 188 | ++} |
| 189 | +diff --git a/vendor/magento/module-shared-catalog/Ui/DataProvider/Configure/AbstractDataProvider.php b/vendor/magento/module-shared-catalog/Ui/DataProvider/Configure/AbstractDataProvider.php |
| 190 | +index da9714ad5f..719ce9bbf3 100644 |
| 191 | +--- a/vendor/magento/module-shared-catalog/Ui/DataProvider/Configure/AbstractDataProvider.php |
| 192 | ++++ b/vendor/magento/module-shared-catalog/Ui/DataProvider/Configure/AbstractDataProvider.php |
| 193 | +@@ -5,8 +5,9 @@ |
| 194 | + */ |
| 195 | + namespace Magento\SharedCatalog\Ui\DataProvider\Configure; |
| 196 | + |
| 197 | +-use Magento\SharedCatalog\Model\Form\Storage\WizardFactory as WizardStorageFactory; |
| 198 | + use Magento\SharedCatalog\Model\Form\Storage\UrlBuilder; |
| 199 | ++use Magento\SharedCatalog\Model\Form\Storage\WizardFactory as WizardStorageFactory; |
| 200 | ++use Magento\Store\Model\Store; |
| 201 | + |
| 202 | + /** |
| 203 | + * Products grid in shared catalog wizard data provider. |
| 204 | +@@ -68,6 +69,7 @@ abstract class AbstractDataProvider extends \Magento\SharedCatalog\Ui\DataProvid |
| 205 | + */ |
| 206 | + public function addFilter(\Magento\Framework\Api\Filter $filter) |
| 207 | + { |
| 208 | ++ //@phpstan-ignore-next-line as adding return statement cause of backward compatibility issue |
| 209 | + switch ($filter->getField()) { |
| 210 | + case 'websites': |
| 211 | + if ($filter->getValue() != 0) { |
| 212 | +@@ -113,8 +115,17 @@ abstract class AbstractDataProvider extends \Magento\SharedCatalog\Ui\DataProvid |
| 213 | + $categoryId = !empty($filters['category_id']) ? $filters['category_id'] : ''; |
| 214 | + $collection = $this->categoryTree->getCategoryProductsCollectionById($categoryId); |
| 215 | + if (empty($filters['store_id']) && empty($filters['websites'])) { |
| 216 | +- $collection->setStore(\Magento\Store\Model\Store::DEFAULT_STORE_ID); |
| 217 | ++ $collection->setStore(Store::DEFAULT_STORE_ID); |
| 218 | + } |
| 219 | ++ |
| 220 | ++ //from ui the "Stores" dropdown contains group_id from store_group, |
| 221 | ++ //instead of store_id from store table |
| 222 | ++ //so the default_store_id from the selected store group is chosen for filtering |
| 223 | ++ if (!empty($filters['store_id'])) { |
| 224 | ++ $storeId = $this->storeManager->getGroup($filters['store_id'])->getDefaultStoreId(); |
| 225 | ++ $collection->setStore($storeId); |
| 226 | ++ } |
| 227 | ++ |
| 228 | + $collection->addWebsiteNamesToResult(); |
| 229 | + |
| 230 | + return $collection; |
| 231 | +diff --git a/vendor/magento/module-shared-catalog/etc/adminhtml/di.xml b/vendor/magento/module-shared-catalog/etc/adminhtml/di.xml |
| 232 | +index a07a514023..f8e0e0182c 100644 |
| 233 | +--- a/vendor/magento/module-shared-catalog/etc/adminhtml/di.xml |
| 234 | ++++ b/vendor/magento/module-shared-catalog/etc/adminhtml/di.xml |
| 235 | +@@ -136,4 +136,12 @@ |
| 236 | + <plugin name="catalog_category_permissions_row_block_plugin" |
| 237 | + type="Magento\SharedCatalog\Plugin\CatalogPermissions\Block\Adminhtml\Catalog\Category\Tab\Permissions\RowPlugin" /> |
| 238 | + </type> |
| 239 | ++ <type name="Magento\SharedCatalog\Block\Adminhtml\Store\Switcher"> |
| 240 | ++ <plugin name="shared_catalog_restrict_stores_for_restricted_users" |
| 241 | ++ type="Magento\SharedCatalog\Plugin\Backend\Block\Adminhtml\Store\SwitcherRolePermissions" /> |
| 242 | ++ </type> |
| 243 | ++ <type name="Magento\SharedCatalog\Ui\DataProvider\Website"> |
| 244 | ++ <plugin name="shared_catalog_restrict_websites_for_restricted_users" |
| 245 | ++ type="Magento\SharedCatalog\Plugin\Ui\DataProvider\WebsiteRolePermissions" /> |
| 246 | ++ </type> |
| 247 | + </config> |
| 248 | +diff --git a/vendor/magento/module-shared-catalog/view/adminhtml/web/js/grid/filters/configure/filters.js b/vendor/magento/module-shared-catalog/view/adminhtml/web/js/grid/filters/configure/filters.js |
| 249 | +index c2536b28c4..ba9694f971 100644 |
| 250 | +--- a/vendor/magento/module-shared-catalog/view/adminhtml/web/js/grid/filters/configure/filters.js |
| 251 | ++++ b/vendor/magento/module-shared-catalog/view/adminhtml/web/js/grid/filters/configure/filters.js |
| 252 | +@@ -59,6 +59,7 @@ define([ |
| 253 | + selectedStoreId = selectedStore.id; |
| 254 | + } |
| 255 | + this.storeFilter().value(selectedStoreId); |
| 256 | ++ this.filters['store_id'] = selectedStoreId; |
| 257 | + this.apply(); |
| 258 | + }, |
| 259 | + |
0 commit comments