From 40903fa2bc39e27f411abd927bc291ffefaf32ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20Bulet=C3=A9?= Date: Sat, 9 Nov 2024 19:02:33 +0100 Subject: [PATCH] feat: refactor & optimize ProductEavDataProviderPlugin plugin --- Plugin/ProductEavDataProviderPlugin.php | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/Plugin/ProductEavDataProviderPlugin.php b/Plugin/ProductEavDataProviderPlugin.php index d0e8dc6..d89257e 100644 --- a/Plugin/ProductEavDataProviderPlugin.php +++ b/Plugin/ProductEavDataProviderPlugin.php @@ -46,30 +46,28 @@ public function __construct( public function afterSetupAttributeMeta(Eav $subject, array $result): array { $storeSvg = ""; - if (!isset($result['arguments']['data']['config']['code']) - || $result['arguments']['data']['config']['globalScope'] - || !\in_array($result['arguments']['data']['config']['dataType'], - $this->betterBoConfig->getAttributesFieldsType(), true) - ) { + + $config = $result['arguments']['data']['config'] ?? null; + if (!$config || $config['globalScope'] || !\in_array($config['dataType'], $this->betterBoConfig->getAttributesFieldsType(), true)) { return $result; } - $attributeCode = $result['arguments']['data']['config']['code']; + $attributeCode = $config['code']; $product = $this->registry->registry('current_product'); if (!$product || !$product->getId()) { return $result; } - - $adminStoreViewId = \Magento\Store\Model\Store::DEFAULT_STORE_ID; + $adminStoreViewId = Store::DEFAULT_STORE_ID; $currentStoreViewId = $this->storeManager->getStore()->getId(); - if ($result['arguments']['data']['config']['globalScope']) { - return $result; - } - if ((int) $currentStoreViewId === (int) $adminStoreViewId && $result['arguments']['data']['config']['globalScope'] == false) { - $result['arguments']['data']['config']['storebtn'] = ''; + if ((int)$currentStoreViewId === (int)$adminStoreViewId && !$config['globalScope']) { + $result['arguments']['data']['config']['storebtn'] = sprintf( + "", + $attributeCode, + $storeSvg + ); } return $result;