diff --git a/Model/Category/DataProvider/Plugin.php b/Model/Category/DataProvider/Plugin.php new file mode 100644 index 00000000..244fc00d --- /dev/null +++ b/Model/Category/DataProvider/Plugin.php @@ -0,0 +1,102 @@ +eavConfig = $eavConfig; + $this->auth = $auth ?? ObjectManager::getInstance()->get(AuthorizationInterface::class); + } + + /** + * @param CategoryDataProvider $subject + * @param array $meta + * + * @return array + * + * @throws LocalizedException + */ + public function afterPrepareMeta(CategoryDataProvider $subject, $meta) + { + $meta = array_replace_recursive( + $meta, + $this->prepareFieldsMeta( + $this->getFieldsMap(), + $subject->getAttributesMeta($this->eavConfig->getEntityType('catalog_category')) + ) + ); + + return $meta; + } + + /** + * @param array $fieldsMap + * @param array $fieldsMeta + * + * @return array + */ + private function prepareFieldsMeta($fieldsMap, $fieldsMeta) + { + $canEditDesign = $this->auth->isAllowed('Magento_Catalog::edit_category_design'); + + $result = []; + foreach ($fieldsMap as $fieldSet => $fields) { + foreach ($fields as $field) { + if (isset($fieldsMeta[$field])) { + $config = $fieldsMeta[$field]; + if (($fieldSet === 'design' || $fieldSet === 'schedule_design_update') && !$canEditDesign) { + $config['required'] = 1; + $config['disabled'] = 1; + $config['serviceDisabled'] = true; + } + + $result[$fieldSet]['children'][$field]['arguments']['data']['config'] = $config; + } + } + } + + return $result; + } + + /** + * @return array + */ + protected function getFieldsMap() + { + return [ + 'tweakwise' => [ + 'tweakwise_featured_template', + 'tweakwise_crosssell_template', + 'tweakwise_crosssell_group_code', + 'tweakwise_upsell_template', + 'tweakwise_upsell_group_code', + ], + ]; + } +} diff --git a/etc/di.xml b/etc/di.xml index 193a8ee2..5a688be4 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -66,6 +66,10 @@ + + + +