Skip to content

Commit

Permalink
feat: refactor & optimize ProductEavDataProviderPlugin plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandreBulete committed Nov 9, 2024
1 parent cc8d3b5 commit 40903fa
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions Plugin/ProductEavDataProviderPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,28 @@ public function __construct(
public function afterSetupAttributeMeta(Eav $subject, array $result): array
{
$storeSvg = "<svg stroke='currentColor' fill='currentColor' stroke-width='0' viewBox='0 0 616 512' height='200px' width='200px' xmlns='http://www.w3.org/2000/svg'><path d='M602 118.6L537.1 15C531.3 5.7 521 0 510 0H106C95 0 84.7 5.7 78.9 15L14 118.6c-33.5 53.5-3.8 127.9 58.8 136.4 4.5.6 9.1.9 13.7.9 29.6 0 55.8-13 73.8-33.1 18 20.1 44.3 33.1 73.8 33.1 29.6 0 55.8-13 73.8-33.1 18 20.1 44.3 33.1 73.8 33.1 29.6 0 55.8-13 73.8-33.1 18.1 20.1 44.3 33.1 73.8 33.1 4.7 0 9.2-.3 13.7-.9 62.8-8.4 92.6-82.8 59-136.4zM529.5 288c-10 0-19.9-1.5-29.5-3.8V384H116v-99.8c-9.6 2.2-19.5 3.8-29.5 3.8-6 0-12.1-.4-18-1.2-5.6-.8-11.1-2.1-16.4-3.6V480c0 17.7 14.3 32 32 32h448c17.7 0 32-14.3 32-32V283.2c-5.4 1.6-10.8 2.9-16.4 3.6-6.1.8-12.1 1.2-18.2 1.2z'></path></svg>";
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'] = '<button class=\'btn-store-view\' data-attribute-code=\'' . $attributeCode . '\'>' . $storeSvg . '</button>';
if ((int)$currentStoreViewId === (int)$adminStoreViewId && !$config['globalScope']) {
$result['arguments']['data']['config']['storebtn'] = sprintf(
"<button class='btn-store-view' data-attribute-code='%s'>%s</button>",
$attributeCode,
$storeSvg
);
}

return $result;
Expand Down

0 comments on commit 40903fa

Please sign in to comment.