From 69bb06b5b4daec0e95031ba0d0b6dbf83605f629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mateos?= Date: Sat, 14 Oct 2017 01:36:40 +0200 Subject: [PATCH 1/2] Show product alerts in admin product detail --- .../Product/Form/Modifier/Alerts.php | 173 ++++++++++++++++++ app/code/Magento/Catalog/etc/adminhtml/di.xml | 4 + 2 files changed, 177 insertions(+) create mode 100644 app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Alerts.php 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..96e00a911610c --- /dev/null +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Alerts.php @@ -0,0 +1,173 @@ +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' => + '

' . __('Alert Stock') . '

' . + $this->layoutFactory->create()->createBlock( + Stock::class + )->toHtml(), + ] + ] + ] + ]; + } + + /** + * Prepares config for the alert price products fieldset + * @return array + */ + private function getAlertPriceFieldset() + { + return [ + 'arguments' => [ + 'data' => [ + 'config' => [ + 'label' => __('Alert price'), + 'componentType' => 'container', + 'component' => 'Magento_Ui/js/form/components/html', + 'additionalClasses' => 'admin__fieldset-note', + 'content' => + '

' . __('Alert Price') . '

' . + $this->layoutFactory->create()->createBlock( + Price::class + )->toHtml(), + ] + ] + ] + ]; + } +} diff --git a/app/code/Magento/Catalog/etc/adminhtml/di.xml b/app/code/Magento/Catalog/etc/adminhtml/di.xml index 790bd163a6f17..b97e6fc1aa318 100644 --- a/app/code/Magento/Catalog/etc/adminhtml/di.xml +++ b/app/code/Magento/Catalog/etc/adminhtml/di.xml @@ -143,6 +143,10 @@ Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Attributes 120 + + Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Alerts + 130 + Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\TierPrice 150 From 168d8cb87ef550a89d9cb2ad6ed57efbe38718cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Mateos?= Date: Sat, 14 Oct 2017 14:02:54 +0200 Subject: [PATCH 2/2] Improve PHP Code Sniffer --- .../Catalog/Ui/DataProvider/Product/Form/Modifier/Alerts.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 index 96e00a911610c..1f154d3204454 100644 --- a/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Alerts.php +++ b/app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Alerts.php @@ -38,8 +38,7 @@ class Alerts extends AbstractModifier * @var LayoutFactory */ private $layoutFactory; - - + /** * Alerts constructor. * @param ScopeConfigInterface $scopeConfig