diff --git a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Alerts.php b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Alerts.php new file mode 100644 index 0000000000000..1f154d3204454 --- /dev/null +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Alerts.php @@ -0,0 +1,172 @@ +scopeConfig = $scopeConfig; + $this->layoutFactory = $layoutFactory; + } + + /** + * {@inheritdoc} + * @since 101.0.0 + */ + public function modifyData(array $data) + { + return $data; + } + + /** + * {@inheritdoc} + * @since 101.0.0 + */ + public function modifyMeta(array $meta) + { + if (!$this->canShowTab()) { + return $meta; + } + + $meta = array_replace_recursive( + $meta, + [ + 'alerts' => [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'additionalClasses' => 'admin__fieldset-section', + 'label' => __('Product Alerts'), + 'collapsible' => true, + 'componentType' => Fieldset::NAME, + 'dataScope' => static::DATA_SCOPE, + 'sortOrder' => + $this->getNextGroupSortOrder( + $meta, + self::$previousGroup, + self::$sortOrder + ), + ], + ], + ], + 'children' => [ + static::DATA_SCOPE_STOCK => $this->getAlertStockFieldset(), + static::DATA_SCOPE_PRICE => $this->getAlertPriceFieldset() + ], + ], + ] + ); + + return $meta; + } + + /** + * @return bool + */ + private function canShowTab() + { + $alertPriceAllow = $this->scopeConfig->getValue( + 'catalog/productalert/allow_price', + ScopeInterface::SCOPE_STORE + ); + $alertStockAllow = $this->scopeConfig->getValue( + 'catalog/productalert/allow_stock', + ScopeInterface::SCOPE_STORE + ); + + return ($alertPriceAllow || $alertStockAllow); + } + + /** + * Prepares config for the alert stock products fieldset + * @return array + */ + private function getAlertStockFieldset() + { + return [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'label' => __('Alert stock'), + 'componentType' => 'container', + 'component' => 'Magento_Ui/js/form/components/html', + 'additionalClasses' => 'admin__fieldset-note', + 'content' => + '