From 9f2a1ff90a98448ba0386851eff145a10b86384c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wac=C5=82awczyk=20Adam?= Date: Tue, 17 Oct 2023 13:20:48 +0200 Subject: [PATCH 01/20] #94738 add serialized customer groups field to nodes --- Api/Data/NodeInterface.php | 14 ++++++++ Block/Adminhtml/Edit/Tab/Nodes.php | 12 ++++++- Block/Menu.php | 12 ++++++- Block/NodeType/CmsPage.php | 7 ++++ CHANGELOG.md | 2 ++ Model/CustomerGroupsProvider.php | 36 ++++++++++++++++++++ Model/GraphQl/Resolver/DataProvider/Node.php | 4 ++- Model/Menu/Node.php | 27 +++++++++++++++ Service/Menu/SaveRequestProcessor.php | 1 + Setup/UpgradeSchema.php | 24 +++++++++++++ etc/module.xml | 2 +- view/adminhtml/templates/menu/nodes.phtml | 4 ++- view/adminhtml/web/vue/app.vue | 3 +- view/adminhtml/web/vue/menu-type.vue | 2 ++ view/frontend/templates/menu.phtml | 6 ++++ 15 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 Model/CustomerGroupsProvider.php diff --git a/Api/Data/NodeInterface.php b/Api/Data/NodeInterface.php index bf831ddd..be4f22bc 100644 --- a/Api/Data/NodeInterface.php +++ b/Api/Data/NodeInterface.php @@ -23,6 +23,7 @@ interface NodeInterface const IS_ACTIVE = 'is_active'; const ADDITIONAL_DATA = 'additional_data'; const SELECTED_ITEM_ID = 'selected_item_id'; + const CUSTOMER_GROUPS = 'customer_groups'; /** * Get node id @@ -274,4 +275,17 @@ public function getSelectedItemId(); * @return $this */ public function setSelectedItemId($selectedItemId); + + /** + * Get customer groups + * + * @return int[] + */ + public function getCustomerGroups(); + + /** + * @param int[] $customerGroups + * @return $this + */ + public function setCustomerGroups($customerGroups); } diff --git a/Block/Adminhtml/Edit/Tab/Nodes.php b/Block/Adminhtml/Edit/Tab/Nodes.php index 1b55ebf9..26fe3a2f 100644 --- a/Block/Adminhtml/Edit/Tab/Nodes.php +++ b/Block/Adminhtml/Edit/Tab/Nodes.php @@ -7,6 +7,7 @@ use Magento\Framework\Registry; use Snowdog\Menu\Api\NodeRepositoryInterface; use Snowdog\Menu\Controller\Adminhtml\Menu\Edit; +use Snowdog\Menu\Model\CustomerGroupsProvider; use Snowdog\Menu\Model\Menu\Node\Image\File as ImageFile; use Snowdog\Menu\Model\NodeTypeProvider; use Snowdog\Menu\Model\VueProvider; @@ -41,6 +42,7 @@ class Nodes extends Template implements TabInterface * @var VueProvider */ private $vueProvider; + private CustomerGroupsProvider $customerGroupsProvider; public function __construct( Template\Context $context, @@ -49,6 +51,7 @@ public function __construct( NodeTypeProvider $nodeTypeProvider, Registry $registry, VueProvider $vueProvider, + CustomerGroupsProvider $customerGroupsProvider, array $data = [] ) { parent::__construct($context, $data); @@ -57,6 +60,7 @@ public function __construct( $this->nodeTypeProvider = $nodeTypeProvider; $this->imageFile = $imageFile; $this->vueProvider = $vueProvider; + $this->customerGroupsProvider = $customerGroupsProvider; } public function renderNodes() @@ -180,7 +184,8 @@ private function renderNodeList($level, $parent, $data) 'image_url' => $node->getImage() ? $this->imageFile->getUrl($node->getImage()) : null, 'image_alt_text' => $node->getImageAltText(), 'columns' => $this->renderNodeList($level + 1, $node->getId(), $data) ?: [], - 'selected_item_id' => $node->getSelectedItemId() + 'selected_item_id' => $node->getSelectedItemId(), + 'customer_groups' => $node->getCustomerGroups() ]; } return $menu; @@ -203,4 +208,9 @@ public function getVueComponents(): array { return $this->vueProvider->getComponents(); } + + public function getCustomerGroups() + { + return $this->customerGroupsProvider->getAll(); + } } diff --git a/Block/Menu.php b/Block/Menu.php index 07a0853e..e8a7b8cf 100644 --- a/Block/Menu.php +++ b/Block/Menu.php @@ -2,6 +2,7 @@ namespace Snowdog\Menu\Block; +use Magento\Customer\Model\Session; use Magento\Framework\Api\Search\FilterGroupBuilder; use Magento\Framework\Api\Search\SearchCriteriaFactory; use Magento\Framework\App\Cache\Type\Block; @@ -83,6 +84,7 @@ class Menu extends Template implements DataObject\IdentityInterface * @var Escaper */ private $escaper; + private Session $customerSession; /** * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -98,6 +100,7 @@ public function __construct( TemplateResolver $templateResolver, ImageFile $imageFile, Escaper $escaper, + Session $customerSession, array $data = [] ) { parent::__construct($context, $data); @@ -112,6 +115,7 @@ public function __construct( $this->escaper = $escaper; $this->setTemplate($this->getMenuTemplate($this->_template)); $this->submenuTemplate = $this->getSubmenuTemplate(); + $this->customerSession = $customerSession; } /** @@ -406,7 +410,8 @@ private function getMenuNodeBlock($node) ->setImageAltText($node->getImageAltText()) ->setCustomTemplate($node->getNodeTemplate()) ->setAdditionalData($node->getAdditionalData()) - ->setSelectedItemId($node->getSelectedItemId()); + ->setSelectedItemId($node->getSelectedItemId()) + ->setCustomerGroups($node->getCustomerGroups()); return $nodeBlock; } @@ -498,4 +503,9 @@ private function getSubmenuTemplate() return $this->getMenuTemplate($baseSubmenuTemplate); } + + public function getCustomerGroupId() + { + return $this->customerSession->getCustomerGroupId(); + } } diff --git a/Block/NodeType/CmsPage.php b/Block/NodeType/CmsPage.php index 4241e9a6..e2b71c44 100644 --- a/Block/NodeType/CmsPage.php +++ b/Block/NodeType/CmsPage.php @@ -5,6 +5,7 @@ use Magento\Framework\View\Element\Template\Context; use Magento\Cms\Api\Data\PageInterface; use Magento\Store\Model\StoreManagerInterface; +use Snowdog\Menu\Model\CustomerGroupsProvider; use Snowdog\Menu\Model\TemplateResolver; use Snowdog\Menu\Model\NodeType\CmsPage as CmsPageModel; @@ -50,6 +51,7 @@ class CmsPage extends AbstractNode * @var StoreManagerInterface */ private $storesList; + private CustomerGroupsProvider $customerGroupsProvider; /** * CmsPage constructor. @@ -66,12 +68,14 @@ public function __construct( CmsPageModel $cmsPageModel, TemplateResolver $templateResolver, StoreManagerInterface $storeManager, + CustomerGroupsProvider $customerGroupsProvider, $data = [] ) { parent::__construct($context, $templateResolver, $data); $this->_cmsPageModel = $cmsPageModel; $this->page = $page; $this->storesList = $storeManager->getStores(); + $this->customerGroupsProvider = $customerGroupsProvider; } /** @@ -104,6 +108,9 @@ public function getJsonConfig() 'defaultTemplate' => 'sub_menu', 'options' => $this->templateResolver->getCustomTemplateOptions('sub_menu'), 'message' => __('Template not found'), + ], + 'snowMenuCustomerGroups' => [ + 'options' => $this->customerGroupsProvider->getAll() ] ]; } diff --git a/CHANGELOG.md b/CHANGELOG.md index 39b690c5..b8e50625 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added +- Option to specify customer groups for each node (DEV-94738) ### Changed - Updated eslint version to `8.45.0` and `eslint-plugin-vue` to 9.15.1 (DEV-95002) ### Fixed diff --git a/Model/CustomerGroupsProvider.php b/Model/CustomerGroupsProvider.php new file mode 100644 index 00000000..21ee81ff --- /dev/null +++ b/Model/CustomerGroupsProvider.php @@ -0,0 +1,36 @@ +groupCollectionFactory = $groupCollectionFactory; + } + + public function getAll() + { + $customerGroups = []; + $customerGroups[] = [ + 'label' => __('All Customer Groups'), + 'value' => "" + ]; + + /** @var \Magento\Customer\Model\Group $customerGroup */ + foreach($this->groupCollectionFactory->create() as $customerGroup) { + $customerGroups[] = [ + 'label' => $customerGroup->getCode(), + 'value' => $customerGroup->getId() + ]; + } + + return $customerGroups; + } + +} diff --git a/Model/GraphQl/Resolver/DataProvider/Node.php b/Model/GraphQl/Resolver/DataProvider/Node.php index 9eba6cd1..fff05a4d 100644 --- a/Model/GraphQl/Resolver/DataProvider/Node.php +++ b/Model/GraphQl/Resolver/DataProvider/Node.php @@ -107,7 +107,9 @@ private function convertData(NodeInterface $node): array self::SUBMENU_TEMPLATE_FIELD => $node->getSubmenuTemplate(), NodeInterface::CREATION_TIME => $node->getCreationTime(), NodeInterface::UPDATE_TIME => $node->getUpdateTime(), - NodeInterface::ADDITIONAL_DATA => $node->getAdditionalData() + NodeInterface::ADDITIONAL_DATA => $node->getAdditionalData(), + NodeInterface::SELECTED_ITEM_ID => $node->getSelectedItemId(), + NodeInterface::CUSTOMER_GROUPS => $node->getCustomerGroups() ]; } diff --git a/Model/Menu/Node.php b/Model/Menu/Node.php index be2e040f..71d13788 100644 --- a/Model/Menu/Node.php +++ b/Model/Menu/Node.php @@ -293,4 +293,31 @@ public function setSelectedItemId($selectedItemId) { return $this->setData(NodeInterface::SELECTED_ITEM_ID, $selectedItemId); } + + public function getCustomerGroups() + { + $customerGroups = $this->_getData(NodeInterface::CUSTOMER_GROUPS); + if (!empty($customerGroups)) { + $customerGroups = unserialize($customerGroups); + if (is_array($customerGroups) && !empty($customerGroups)) { + return $customerGroups; + } + } + + return []; + } + + public function setCustomerGroups($customerGroups) + { + if (empty($customerGroups)) { + $this->setData(NodeInterface::CUSTOMER_GROUPS); + return $this; + } + + if (is_string($customerGroups) && unserialize($customerGroups)) { + return $this->setData(NodeInterface::CUSTOMER_GROUPS, $customerGroups); + } + + return $this->setData(NodeInterface::CUSTOMER_GROUPS, serialize($customerGroups)); + } } diff --git a/Service/Menu/SaveRequestProcessor.php b/Service/Menu/SaveRequestProcessor.php index 546feec8..4213c1c0 100644 --- a/Service/Menu/SaveRequestProcessor.php +++ b/Service/Menu/SaveRequestProcessor.php @@ -210,6 +210,7 @@ private function processNodeObject( $nodeObject->setImageAltText($nodeData['image_alt_text'] ?? null); $nodeObject->setSelectedItemId($nodeData['selected_item_id'] ?? null); + $nodeObject->setCustomerGroups($nodeData[NodeInterface::CUSTOMER_GROUPS] ?? null); } /** diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 69f29186..70e3e0f1 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -59,6 +59,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con $this->addNodeSelectedItemId($setup); } + if (version_compare($context->getVersion(), '0.2.8', '<')) { + $this->addNodeCustomerGroups($setup); + } + $setup->endSetup(); } @@ -298,4 +302,24 @@ private function addNodeSelectedItemId(SchemaSetupInterface $setup) return $this; } + + private function addNodeCustomerGroups(SchemaSetupInterface $setup) + { + $connection = $setup->getConnection(); + $table = $setup->getTable('snowmenu_node'); + + $connection->addColumn( + $table, + NodeInterface::CUSTOMER_GROUPS, + [ + 'type' => Table::TYPE_TEXT, + 'length' => 255, + 'nullable' => true, + 'after' => NodeInterface::SELECTED_ITEM_ID, + 'comment' => "Customer Groups Serialized" + ] + ); + + return $this; + } } diff --git a/etc/module.xml b/etc/module.xml index f58fd655..1db65ee8 100644 --- a/etc/module.xml +++ b/etc/module.xml @@ -1,6 +1,6 @@ - + diff --git a/view/adminhtml/templates/menu/nodes.phtml b/view/adminhtml/templates/menu/nodes.phtml index e4a61867..b1beabe8 100644 --- a/view/adminhtml/templates/menu/nodes.phtml +++ b/view/adminhtml/templates/menu/nodes.phtml @@ -44,6 +44,7 @@ $vueComponents = $block->getVueComponents(); "imageDeleteUrl" : "getImageDeleteUrl() ?>", "imageUploadFileId": "getImageUploadFileId() ?>", "lazyMinItemsCount": "1000", + "customerGroups" : getCustomerGroups()) ?>, "translation": { "nodes" : "", "click" : "", @@ -70,7 +71,8 @@ $vueComponents = $block->getVueComponents(); "product" : "", "productId" : "", "imageAltText" : "", - "selectedItemId" : "" + "selectedItemId" : "", + "customerGroups" : "" } } } diff --git a/view/adminhtml/web/vue/app.vue b/view/adminhtml/web/vue/app.vue index 3e5494de..556a9968 100644 --- a/view/adminhtml/web/vue/app.vue +++ b/view/adminhtml/web/vue/app.vue @@ -134,7 +134,8 @@ node_template: null, submenu_template: null, columns: [], - is_active: 0 + is_active: 0, + customer_groups: [] }); }, handleDrop(data) { diff --git a/view/adminhtml/web/vue/menu-type.vue b/view/adminhtml/web/vue/menu-type.vue index 6479f277..58421eb5 100644 --- a/view/adminhtml/web/vue/menu-type.vue +++ b/view/adminhtml/web/vue/menu-type.vue @@ -65,6 +65,8 @@ type="text" /> + //customerGroups multiselect +

{{ templatesLabel }}

diff --git a/view/frontend/templates/menu.phtml b/view/frontend/templates/menu.phtml index 9481dd6c..0c651b6c 100755 --- a/view/frontend/templates/menu.phtml +++ b/view/frontend/templates/menu.phtml @@ -16,8 +16,14 @@ data-mage-init='{"snowdogMenu": {}}' >
    + getCustomerGroupId(); + ?> getNodes() as $node): ?> getCustomerGroups())) { + continue; + } $childrenLevel = $node->getLevel() + 1; $children = $block->getNodes($childrenLevel, $node); $node->setIsParent((bool) $children); From ca6c4741e0b47a551f05a8dd132c5842940e3620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wac=C5=82awczyk=20Adam?= Date: Tue, 17 Oct 2023 13:30:28 +0200 Subject: [PATCH 02/20] #94738 remove types from properties --- Block/Adminhtml/Edit/Tab/Nodes.php | 6 +++++- Block/Menu.php | 6 +++++- Block/NodeType/CmsPage.php | 7 ------- Model/CustomerGroupsProvider.php | 10 +++++++--- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/Block/Adminhtml/Edit/Tab/Nodes.php b/Block/Adminhtml/Edit/Tab/Nodes.php index 26fe3a2f..ee3f0742 100644 --- a/Block/Adminhtml/Edit/Tab/Nodes.php +++ b/Block/Adminhtml/Edit/Tab/Nodes.php @@ -42,7 +42,11 @@ class Nodes extends Template implements TabInterface * @var VueProvider */ private $vueProvider; - private CustomerGroupsProvider $customerGroupsProvider; + + /** + * @var CustomerGroupsProvider + */ + private $customerGroupsProvider; public function __construct( Template\Context $context, diff --git a/Block/Menu.php b/Block/Menu.php index e8a7b8cf..085b3145 100644 --- a/Block/Menu.php +++ b/Block/Menu.php @@ -84,7 +84,11 @@ class Menu extends Template implements DataObject\IdentityInterface * @var Escaper */ private $escaper; - private Session $customerSession; + + /** + * @var Session + */ + private $customerSession; /** * @SuppressWarnings(PHPMD.ExcessiveParameterList) diff --git a/Block/NodeType/CmsPage.php b/Block/NodeType/CmsPage.php index e2b71c44..4241e9a6 100644 --- a/Block/NodeType/CmsPage.php +++ b/Block/NodeType/CmsPage.php @@ -5,7 +5,6 @@ use Magento\Framework\View\Element\Template\Context; use Magento\Cms\Api\Data\PageInterface; use Magento\Store\Model\StoreManagerInterface; -use Snowdog\Menu\Model\CustomerGroupsProvider; use Snowdog\Menu\Model\TemplateResolver; use Snowdog\Menu\Model\NodeType\CmsPage as CmsPageModel; @@ -51,7 +50,6 @@ class CmsPage extends AbstractNode * @var StoreManagerInterface */ private $storesList; - private CustomerGroupsProvider $customerGroupsProvider; /** * CmsPage constructor. @@ -68,14 +66,12 @@ public function __construct( CmsPageModel $cmsPageModel, TemplateResolver $templateResolver, StoreManagerInterface $storeManager, - CustomerGroupsProvider $customerGroupsProvider, $data = [] ) { parent::__construct($context, $templateResolver, $data); $this->_cmsPageModel = $cmsPageModel; $this->page = $page; $this->storesList = $storeManager->getStores(); - $this->customerGroupsProvider = $customerGroupsProvider; } /** @@ -108,9 +104,6 @@ public function getJsonConfig() 'defaultTemplate' => 'sub_menu', 'options' => $this->templateResolver->getCustomTemplateOptions('sub_menu'), 'message' => __('Template not found'), - ], - 'snowMenuCustomerGroups' => [ - 'options' => $this->customerGroupsProvider->getAll() ] ]; } diff --git a/Model/CustomerGroupsProvider.php b/Model/CustomerGroupsProvider.php index 21ee81ff..29596f08 100644 --- a/Model/CustomerGroupsProvider.php +++ b/Model/CustomerGroupsProvider.php @@ -2,14 +2,18 @@ namespace Snowdog\Menu\Model; +use Magento\Customer\Model\Group; use Magento\Customer\Model\ResourceModel\Group\CollectionFactory as GroupCollectionFactory; class CustomerGroupsProvider { - private GroupCollectionFactory $groupCollectionFactory; + /** + * @var GroupCollectionFactory + */ + private $groupCollectionFactory; public function __construct( - GroupCollectionFactory $groupCollectionFactory, + GroupCollectionFactory $groupCollectionFactory ) { $this->groupCollectionFactory = $groupCollectionFactory; } @@ -22,7 +26,7 @@ public function getAll() 'value' => "" ]; - /** @var \Magento\Customer\Model\Group $customerGroup */ + /** @var Group $customerGroup */ foreach($this->groupCollectionFactory->create() as $customerGroup) { $customerGroups[] = [ 'label' => $customerGroup->getCode(), From 8d191120c6c4e2851a97380e0c3a16b2b6d35e89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wac=C5=82awczyk=20Adam?= Date: Tue, 17 Oct 2023 13:37:18 +0200 Subject: [PATCH 03/20] #94738 add fixes for github pipeline --- Model/Menu/Node.php | 28 +++++++++++++++++++++++++--- Setup/UpgradeSchema.php | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/Model/Menu/Node.php b/Model/Menu/Node.php index 71d13788..a60367d1 100644 --- a/Model/Menu/Node.php +++ b/Model/Menu/Node.php @@ -1,14 +1,36 @@ serializer = $serializer; + } + protected function _construct() { $this->_init(\Snowdog\Menu\Model\ResourceModel\Menu\Node::class); @@ -298,7 +320,7 @@ public function getCustomerGroups() { $customerGroups = $this->_getData(NodeInterface::CUSTOMER_GROUPS); if (!empty($customerGroups)) { - $customerGroups = unserialize($customerGroups); + $customerGroups = $this->serializer->unserialize($customerGroups); if (is_array($customerGroups) && !empty($customerGroups)) { return $customerGroups; } @@ -314,10 +336,10 @@ public function setCustomerGroups($customerGroups) return $this; } - if (is_string($customerGroups) && unserialize($customerGroups)) { + if (is_string($customerGroups) && $this->serializer->unserialize($customerGroups)) { return $this->setData(NodeInterface::CUSTOMER_GROUPS, $customerGroups); } - return $this->setData(NodeInterface::CUSTOMER_GROUPS, serialize($customerGroups)); + return $this->setData(NodeInterface::CUSTOMER_GROUPS, $this->serializer->serialize($customerGroups)); } } diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php index 70e3e0f1..a4349f97 100644 --- a/Setup/UpgradeSchema.php +++ b/Setup/UpgradeSchema.php @@ -21,6 +21,7 @@ class UpgradeSchema implements UpgradeSchemaInterface { /** * {@inheritdoc} + * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) */ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) From 8dc94683275e3fceaf31169ae4c0107b03eba212 Mon Sep 17 00:00:00 2001 From: Ola Date: Mon, 8 Jan 2024 12:28:45 +0100 Subject: [PATCH 04/20] #94738 - add customer groups multiselect --- view/adminhtml/templates/menu/nodes.phtml | 3 ++- view/adminhtml/web/vue/menu-type.vue | 27 +++++++++++++++++++++-- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/view/adminhtml/templates/menu/nodes.phtml b/view/adminhtml/templates/menu/nodes.phtml index b1beabe8..f7ad3af8 100644 --- a/view/adminhtml/templates/menu/nodes.phtml +++ b/view/adminhtml/templates/menu/nodes.phtml @@ -72,7 +72,8 @@ $vueComponents = $block->getVueComponents(); "productId" : "", "imageAltText" : "", "selectedItemId" : "", - "customerGroups" : "" + "customerGroups" : "", + "customerGroupsDescription" : "" } } } diff --git a/view/adminhtml/web/vue/menu-type.vue b/view/adminhtml/web/vue/menu-type.vue index 58421eb5..524fef95 100644 --- a/view/adminhtml/web/vue/menu-type.vue +++ b/view/adminhtml/web/vue/menu-type.vue @@ -51,6 +51,31 @@ type="text" /> +
    + + +
    + + + {{ config.translation.customerGroupsDescription }} + +
    +
    + - //customerGroups multiselect -

    {{ templatesLabel }}

    From c085557224002f76cd0da02b849adc29cb2de941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wac=C5=82awczyk=20Adam?= Date: Fri, 12 Jan 2024 14:27:53 +0100 Subject: [PATCH 05/20] #94738 add http context variable, system config for handling it --- Api/Data/NodeInterface.php | 8 ++++-- Block/Menu.php | 16 +++++++++++- Model/CustomerGroupsProvider.php | 7 +----- Model/Menu/Node.php | 16 ++++++++++++ Plugin/CustomerGroupCacheContext.php | 37 ++++++++++++++++++++++++++++ etc/adminhtml/system.xml | 21 ++++++++++++++++ etc/config.xml | 3 +++ etc/di.xml | 5 ++++ view/frontend/templates/menu.phtml | 6 ----- 9 files changed, 104 insertions(+), 15 deletions(-) create mode 100644 Plugin/CustomerGroupCacheContext.php create mode 100644 etc/adminhtml/system.xml diff --git a/Api/Data/NodeInterface.php b/Api/Data/NodeInterface.php index be4f22bc..68ee851c 100644 --- a/Api/Data/NodeInterface.php +++ b/Api/Data/NodeInterface.php @@ -279,13 +279,17 @@ public function setSelectedItemId($selectedItemId); /** * Get customer groups * - * @return int[] */ public function getCustomerGroups(); /** - * @param int[] $customerGroups * @return $this */ public function setCustomerGroups($customerGroups); + + /** + * @param int $customerGroupId + * @return bool + */ + public function isVisible($customerGroupId); } diff --git a/Block/Menu.php b/Block/Menu.php index 085b3145..bfd85818 100644 --- a/Block/Menu.php +++ b/Block/Menu.php @@ -6,10 +6,12 @@ use Magento\Framework\Api\Search\FilterGroupBuilder; use Magento\Framework\Api\Search\SearchCriteriaFactory; use Magento\Framework\App\Cache\Type\Block; +use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\DataObject; use Magento\Framework\View\Element\Template; use Magento\Framework\Event\Manager as EventManager; use Magento\Framework\Escaper; +use Snowdog\Menu\Api\Data\NodeInterface; use Snowdog\Menu\Api\MenuRepositoryInterface; use Snowdog\Menu\Api\NodeRepositoryInterface; use Snowdog\Menu\Model\Menu\Node\Image\File as ImageFile; @@ -90,6 +92,11 @@ class Menu extends Template implements DataObject\IdentityInterface */ private $customerSession; + /** + * @var ScopeConfigInterface + */ + private $scopeConfig; + /** * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -105,6 +112,7 @@ public function __construct( ImageFile $imageFile, Escaper $escaper, Session $customerSession, + ScopeConfigInterface $scopeConfig, array $data = [] ) { parent::__construct($context, $data); @@ -120,6 +128,7 @@ public function __construct( $this->setTemplate($this->getMenuTemplate($this->_template)); $this->submenuTemplate = $this->getSubmenuTemplate(); $this->customerSession = $customerSession; + $this->scopeConfig = $scopeConfig; } /** @@ -389,7 +398,7 @@ public function getMenuCssClass($defaultClass = '') } /** - * @param NodeRepositoryInterface $node + * @param NodeInterface $node * @return Template */ private function getMenuNodeBlock($node) @@ -447,12 +456,17 @@ private function getSubmenuBlock($nodes, $parentNode, $level = 0) private function fetchData() { $nodes = $this->nodeRepository->getByMenu($this->loadMenu()->getId()); + $currentCustomerGroup = $this->getCustomerGroupId(); + $customerGroupEnabled = $this->scopeConfig->getValue('snowmenu/general/customer_groups'); $result = []; $types = []; foreach ($nodes as $node) { if (!$node->getIsActive()) { continue; } + if ($customerGroupEnabled && !$node->isVisible($currentCustomerGroup)) { + continue; + } $level = $node->getLevel(); $parent = $node->getParentId() ?: 0; diff --git a/Model/CustomerGroupsProvider.php b/Model/CustomerGroupsProvider.php index 29596f08..ca5a9197 100644 --- a/Model/CustomerGroupsProvider.php +++ b/Model/CustomerGroupsProvider.php @@ -21,13 +21,9 @@ public function __construct( public function getAll() { $customerGroups = []; - $customerGroups[] = [ - 'label' => __('All Customer Groups'), - 'value' => "" - ]; /** @var Group $customerGroup */ - foreach($this->groupCollectionFactory->create() as $customerGroup) { + foreach ($this->groupCollectionFactory->create() as $customerGroup) { $customerGroups[] = [ 'label' => $customerGroup->getCode(), 'value' => $customerGroup->getId() @@ -36,5 +32,4 @@ public function getAll() return $customerGroups; } - } diff --git a/Model/Menu/Node.php b/Model/Menu/Node.php index a60367d1..9d3093b4 100644 --- a/Model/Menu/Node.php +++ b/Model/Menu/Node.php @@ -342,4 +342,20 @@ public function setCustomerGroups($customerGroups) return $this->setData(NodeInterface::CUSTOMER_GROUPS, $this->serializer->serialize($customerGroups)); } + + public function isVisible($customerGroupId) + { + $customerGroups = $this->getCustomerGroups(); + if (empty($customerGroups)) { + return true; + } + + foreach ($customerGroups as $customerGroup) { + if ((int) $customerGroup['value'] === (int) $customerGroupId) { + return true; + } + } + + return false; + } } diff --git a/Plugin/CustomerGroupCacheContext.php b/Plugin/CustomerGroupCacheContext.php new file mode 100644 index 00000000..92ea43be --- /dev/null +++ b/Plugin/CustomerGroupCacheContext.php @@ -0,0 +1,37 @@ +customerSession = $customerSession; + $this->scopeConfig = $scopeConfig; + } + + public function beforeGetVaryString(HttpContext $subject) + { + if (!$this->scopeConfig->getValue('snowmenu/general/customer_groups')) { + return []; + } + + $currentCustomerGroup = $this->customerSession->getCustomerGroupId(); + $subject->setValue('customer_group', $currentCustomerGroup, 0); + + return []; + } +} diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 00000000..0cd14336 --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,21 @@ + + + + + + +
    + Snowdog_Menu::settings + + snowdog + + + + + Controls serving different menus to different customer groups + Magento\Config\Model\Config\Source\Yesno + + +
    +
    +
    diff --git a/etc/config.xml b/etc/config.xml index b8246cd4..9ba186d7 100644 --- a/etc/config.xml +++ b/etc/config.xml @@ -11,6 +11,9 @@ + + 0 + 1 diff --git a/etc/di.xml b/etc/di.xml index bf2f437f..b96b6156 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -74,4 +74,9 @@ Snowdog\Menu\Model\ImportExport\Processor\Import\Node\Validator\Proxy + + + + diff --git a/view/frontend/templates/menu.phtml b/view/frontend/templates/menu.phtml index 0c651b6c..9481dd6c 100755 --- a/view/frontend/templates/menu.phtml +++ b/view/frontend/templates/menu.phtml @@ -16,14 +16,8 @@ data-mage-init='{"snowdogMenu": {}}' >
      - getCustomerGroupId(); - ?> getNodes() as $node): ?> getCustomerGroups())) { - continue; - } $childrenLevel = $node->getLevel() + 1; $children = $block->getNodes($childrenLevel, $node); $node->setIsParent((bool) $children); From fd00669575f3b506a959fcdfb77a21a4a465bbe2 Mon Sep 17 00:00:00 2001 From: Ola Date: Fri, 5 Apr 2024 11:36:21 +0200 Subject: [PATCH 06/20] #94738 - add id to input elements --- view/adminhtml/web/vue/menu-type.vue | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/view/adminhtml/web/vue/menu-type.vue b/view/adminhtml/web/vue/menu-type.vue index 8f046c65..d0d5d21c 100644 --- a/view/adminhtml/web/vue/menu-type.vue +++ b/view/adminhtml/web/vue/menu-type.vue @@ -17,6 +17,7 @@
      Date: Fri, 5 Apr 2024 11:47:38 +0200 Subject: [PATCH 07/20] #94738 - return only customer_group.value --- view/adminhtml/web/vue/menu-type.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/view/adminhtml/web/vue/menu-type.vue b/view/adminhtml/web/vue/menu-type.vue index d0d5d21c..f311141a 100644 --- a/view/adminhtml/web/vue/menu-type.vue +++ b/view/adminhtml/web/vue/menu-type.vue @@ -64,6 +64,7 @@ Date: Fri, 5 Jul 2024 12:27:40 +0200 Subject: [PATCH 08/20] #94738 - remove redundant set customer group in http context --- Plugin/CustomerGroupCacheContext.php | 37 ---------------------------- etc/di.xml | 5 ---- 2 files changed, 42 deletions(-) delete mode 100644 Plugin/CustomerGroupCacheContext.php diff --git a/Plugin/CustomerGroupCacheContext.php b/Plugin/CustomerGroupCacheContext.php deleted file mode 100644 index 92ea43be..00000000 --- a/Plugin/CustomerGroupCacheContext.php +++ /dev/null @@ -1,37 +0,0 @@ -customerSession = $customerSession; - $this->scopeConfig = $scopeConfig; - } - - public function beforeGetVaryString(HttpContext $subject) - { - if (!$this->scopeConfig->getValue('snowmenu/general/customer_groups')) { - return []; - } - - $currentCustomerGroup = $this->customerSession->getCustomerGroupId(); - $subject->setValue('customer_group', $currentCustomerGroup, 0); - - return []; - } -} diff --git a/etc/di.xml b/etc/di.xml index b96b6156..bf2f437f 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -74,9 +74,4 @@ Snowdog\Menu\Model\ImportExport\Processor\Import\Node\Validator\Proxy - - - - From 3e6c7d8efdd64142115264713a4057e586ed6a35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Fri, 5 Jul 2024 12:28:11 +0200 Subject: [PATCH 09/20] #94738 - add customer group id to menu cache key --- Block/Menu.php | 3 +++ Model/Menu/Node.php | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Block/Menu.php b/Block/Menu.php index 46d2a2fe..32365daa 100644 --- a/Block/Menu.php +++ b/Block/Menu.php @@ -194,6 +194,9 @@ public function getCacheKeyInfo() if ($nodeCacheKeyInfo) { $info = array_merge($info, $nodeCacheKeyInfo); } + if ($this->scopeConfig->isSetFlag('snowmenu/general/customer_groups')) { + $info[] = 'cust_group_' . $this->getCustomerGroupId(); + } return $info; } diff --git a/Model/Menu/Node.php b/Model/Menu/Node.php index 896deaa0..26d4f234 100644 --- a/Model/Menu/Node.php +++ b/Model/Menu/Node.php @@ -383,7 +383,7 @@ public function isVisible($customerGroupId) } foreach ($customerGroups as $customerGroup) { - if ((int) $customerGroup['value'] === (int) $customerGroupId) { + if ((int) $customerGroup === (int) $customerGroupId) { return true; } } From 057d545fec7c976a8c60b3533631e6b2cb8d7c6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Fri, 5 Jul 2024 12:48:31 +0200 Subject: [PATCH 10/20] #94738 generate declarative schema --- etc/db_schema.xml | 53 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 etc/db_schema.xml diff --git a/etc/db_schema.xml b/etc/db_schema.xml new file mode 100644 index 00000000..5a3b5f2b --- /dev/null +++ b/etc/db_schema.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + + + + +
      +
      From 523fe624a816dec002fc83fe98f0ff5bbbc772fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Fri, 5 Jul 2024 12:49:18 +0200 Subject: [PATCH 11/20] #94738 generate db_schema_whitelist.json --- etc/db_schema.xml | 4 +-- etc/db_schema_whitelist.json | 56 ++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 etc/db_schema_whitelist.json diff --git a/etc/db_schema.xml b/etc/db_schema.xml index 5a3b5f2b..37469e32 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -21,11 +21,11 @@ - + - + diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json new file mode 100644 index 00000000..83f74d3f --- /dev/null +++ b/etc/db_schema_whitelist.json @@ -0,0 +1,56 @@ +{ + "snowmenu_menu": { + "column": { + "menu_id": true, + "title": true, + "identifier": true, + "creation_time": true, + "update_time": true, + "is_active": true, + "css_class": true + }, + "constraint": { + "PRIMARY": true + } + }, + "snowmenu_node": { + "column": { + "node_id": true, + "menu_id": true, + "type": true, + "content": true, + "classes": true, + "parent_id": true, + "position": true, + "level": true, + "title": true, + "creation_time": true, + "update_time": true, + "is_active": true, + "target": true, + "submenu_template": true, + "node_template": true, + "image": true, + "image_alt_text": true, + "selected_item_id": true, + "image_width": true, + "image_heigth": true, + "customer_groups": true + }, + "constraint": { + "PRIMARY": true, + "SNOWMENU_NODE_MENU_ID_SNOWMENU_MENU_MENU_ID": true + } + }, + "snowmenu_store": { + "column": { + "menu_id": true, + "store_id": true + }, + "constraint": { + "PRIMARY": true, + "SNOWMENU_STORE_MENU_ID_SNOWMENU_MENU_MENU_ID": true, + "SNOWMENU_STORE_STORE_ID_STORE_STORE_ID": true + } + } +} \ No newline at end of file From c6867e423937862e5d81081014d107c7849c0260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Fri, 5 Jul 2024 12:51:40 +0200 Subject: [PATCH 12/20] #94738 remove unnecessary setup scripts --- Setup/InstallData.php | 16 -- Setup/InstallSchema.php | 160 ------------------ Setup/UpgradeSchema.php | 364 ---------------------------------------- 3 files changed, 540 deletions(-) delete mode 100644 Setup/InstallData.php delete mode 100644 Setup/InstallSchema.php delete mode 100644 Setup/UpgradeSchema.php diff --git a/Setup/InstallData.php b/Setup/InstallData.php deleted file mode 100644 index 57212099..00000000 --- a/Setup/InstallData.php +++ /dev/null @@ -1,16 +0,0 @@ -startSetup(); - - $table = $installer->getConnection()->newTable( - $installer->getTable('snowmenu_menu') - )->addColumn( - 'menu_id', - Table::TYPE_INTEGER, - null, - ['identity' => true, 'nullable' => false, 'primary' => true, 'unsigned' => true,], - 'Entity ID' - )->addColumn( - 'title', - Table::TYPE_TEXT, - 255, - ['nullable' => false,], - 'Demo Title' - )->addColumn( - 'identifier', - Table::TYPE_TEXT, - 255, - ['nullable' => false], - 'Menu identifier' - )->addColumn( - 'creation_time', - Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => Table::TIMESTAMP_INIT,], - 'Creation Time' - )->addColumn( - 'update_time', - Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE,], - 'Modification Time' - )->addColumn( - 'is_active', - Table::TYPE_SMALLINT, - null, - ['nullable' => false, 'default' => '1',], - 'Is Active' - ); - $installer->getConnection()->createTable($table); - - $table = $installer->getConnection()->newTable( - $installer->getTable('snowmenu_node') - )->addColumn( - 'node_id', - Table::TYPE_INTEGER, - null, - ['identity' => true, 'nullable' => false, 'primary' => true, 'unsigned' => true,], - 'Node ID' - )->addColumn( - 'menu_id', - Table::TYPE_INTEGER, - null, - ['nullable' => false], - 'Menu ID' - )->addColumn( - 'type', - Table::TYPE_TEXT, - 255, - ['nullable' => false], - 'Node Type' - )->addColumn( - 'content', - Table::TYPE_TEXT, - null, - [], - 'Node contents' - )->addColumn( - 'classes', - Table::TYPE_TEXT, - 255, - [], - 'CSS class name' - )->addColumn( - 'parent_id', - Table::TYPE_INTEGER, - null, - ['unsigned' => true], - 'Parent Node ID' - )->addColumn( - 'position', - Table::TYPE_INTEGER, - null, - ['nullable' => false, 'unsigned' => true], - 'Node position' - )->addColumn( - 'level', - Table::TYPE_INTEGER, - null, - ['nullable' => false, 'unsigned' => true], - 'Node level' - )->addColumn( - 'title', - Table::TYPE_TEXT, - 255, - ['nullable' => false,], - 'Demo Title' - )->addColumn( - 'creation_time', - Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => Table::TIMESTAMP_INIT,], - 'Creation Time' - )->addColumn( - 'update_time', - Table::TYPE_TIMESTAMP, - null, - ['nullable' => false, 'default' => Table::TIMESTAMP_INIT_UPDATE,], - 'Modification Time' - )->addColumn( - 'is_active', - Table::TYPE_SMALLINT, - null, - ['nullable' => false, 'default' => '1',], - 'Is Active' - ); - $installer->getConnection()->createTable($table); - - $table = $installer->getConnection()->newTable( - $installer->getTable('snowmenu_store') - )->addColumn( - 'menu_id', - Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true, 'unsigned' => true,], - 'Menu ID' - )->addColumn( - 'store_id', - Table::TYPE_INTEGER, - null, - ['nullable' => false, 'primary' => true, 'unsigned' => true,], - 'Store ID' - ); - $installer->getConnection()->createTable($table); - - $installer->endSetup(); - } -} diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php deleted file mode 100644 index 217ebcef..00000000 --- a/Setup/UpgradeSchema.php +++ /dev/null @@ -1,364 +0,0 @@ -. - * @category - * @package - * @copyright Copyright Snowdog (http://snow.dog) - */ - -namespace Snowdog\Menu\Setup; - -use Magento\Framework\DB\Ddl\Table; -use Magento\Framework\Setup\ModuleContextInterface; -use Magento\Framework\Setup\SchemaSetupInterface; -use Magento\Framework\Setup\UpgradeSchemaInterface; -use Snowdog\Menu\Api\Data\NodeInterface; - -// @codingStandardsIgnoreFile -class UpgradeSchema implements UpgradeSchemaInterface -{ - /** - * {@inheritdoc} - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - * @SuppressWarnings(PHPMD.NPathComplexity) - * @SuppressWarnings(PHPMD.CyclomaticComplexity) - */ - public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) - { - $setup->startSetup(); - - if (version_compare($context->getVersion(), '0.1.0', '<')) { - $this->changeTitleType($setup); - } - - if (version_compare($context->getVersion(), '0.2.0', '<')) { - $this->addMenuCssClassField($setup); - } - - if (version_compare($context->getVersion(), '0.2.1', '<')) { - $this->addTargetAttribute($setup); - } - - if (version_compare($context->getVersion(), '0.2.2', '<')) { - $this->updateTargetAttribute($setup); - } - - if (version_compare($context->getVersion(), '0.2.3', '<')) { - $this->addForeignKeys($setup); - } - - if (version_compare($context->getVersion(), '0.2.4', '<')) { - $this->addTemplateFields($setup); - } - - if (version_compare($context->getVersion(), '0.2.5', '<')) { - $this->addNodeImageFields($setup); - } - - if (version_compare($context->getVersion(), '0.2.6', '<')) { - $this->addNodeSelectedItemId($setup); - } - - if (version_compare($context->getVersion(), '0.2.7', '<')) { - $this->addNodeImageSizeFields($setup); - } - - if (version_compare($context->getVersion(), '0.2.8', '<')) { - $this->addNodeCustomerGroups($setup); - } - - $setup->endSetup(); - } - - /** - * @param SchemaSetupInterface $setup - * @return $this - */ - private function addMenuCssClassField(SchemaSetupInterface $setup) - { - $setup->getConnection()->addColumn( - $setup->getTable('snowmenu_menu'), - 'css_class', - [ - 'type' => Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'after' => 'identifier', - 'default' => 'menu', - 'comment' => 'CSS Class' - ] - ); - - return $this; - } - - private function changeTitleType(SchemaSetupInterface $setup) - { - $setup->getConnection()->modifyColumn( - $setup->getTable('snowmenu_node'), - 'title', - [ - 'type' => Table::TYPE_TEXT, - 'nullable' => false - ], - 'Demo Title' - ); - } - - private function addTargetAttribute(SchemaSetupInterface $setup) - { - $setup->getConnection()->addColumn( - $setup->getTable('snowmenu_node'), - 'target', - [ - 'type' => Table::TYPE_TEXT, - 'length' => 10, - 'nullable' => true, - 'after' => 'title', - 'default' => '_self', - 'comment' => 'Link target', - ] - ); - - return $this; - } - - private function updateTargetAttribute(SchemaSetupInterface $setup) - { - $table = $setup->getTable('snowmenu_node'); - $connection = $setup->getConnection(); - - $connection->update( - $table, - ['target' => 0], - "target = '_self'" - ); - $connection->update( - $table, - ['target' => 1], - "target = '_blank'" - ); - $connection->modifyColumn( - $table, - 'target', - [ - 'type' => Table::TYPE_BOOLEAN, - 'default' => 0, - ] - ); - } - - private function addForeignKeys(SchemaSetupInterface $setup) - { - $menuTable = $setup->getTable('snowmenu_menu'); - $nodeTable = $setup->getTable('snowmenu_node'); - $storeTable = $setup->getTable('snowmenu_store'); - $setup->getConnection()->modifyColumn( - $nodeTable, - 'menu_id', - [ - 'type' => Table::TYPE_INTEGER, - 'length' => 10, - 'nullable' => false, - 'unsigned' => true, - 'comment' => 'Menu ID' - ] - ); - - $setup->getConnection()->modifyColumn( - $storeTable, - 'store_id', - [ - 'type' => Table::TYPE_SMALLINT, - 'length' => 5, - 'nullable' => false, - 'primary' => true, - 'unsigned' => true, - 'comment' => 'Store ID' - ] - ); - - $setup->getConnection()->addForeignKey( - $setup->getFkName( - 'snowmenu_node', - 'menu_id', - 'snowmenu_menu', - 'menu_id' - ), - $nodeTable, - 'menu_id', - $menuTable, - 'menu_id', - Table::ACTION_CASCADE - ); - - $setup->getConnection()->addForeignKey( - $setup->getFkName( - 'snowmenu_store', - 'menu_id', - 'snowmenu_menu', - 'menu_id' - ), - $storeTable, - 'menu_id', - $menuTable, - 'menu_id', - Table::ACTION_CASCADE - ); - - $setup->getConnection()->addForeignKey( - $setup->getFkName( - 'snowmenu_store', - 'store_id', - 'store', - 'store_id' - ), - $storeTable, - 'store_id', - $setup->getTable('store'), - 'store_id', - Table::ACTION_CASCADE - ); - } - - /** - * @param SchemaSetupInterface $setup - * @return $this - */ - private function addTemplateFields(SchemaSetupInterface $setup) - { - $setup->getConnection()->addColumn( - $setup->getTable('snowmenu_node'), - 'submenu_template', - [ - 'type' => Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'after' => 'target', - 'comment' => 'Submenu Template', - ] - ); - - $setup->getConnection()->addColumn( - $setup->getTable('snowmenu_node'), - 'node_template', - [ - 'type' => Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'after' => 'target', - 'comment' => 'Node Template', - ] - ); - - return $this; - } - - /** - * @return $this - */ - private function addNodeImageFields(SchemaSetupInterface $setup) - { - $connection = $setup->getConnection(); - $table = $setup->getTable('snowmenu_node'); - - $connection->addColumn( - $table, - 'image', - [ - 'type' => Table::TYPE_TEXT, - 'nullable' => true, - 'after' => 'target', - 'comment' => 'Image' - ] - ); - - $connection->addColumn( - $table, - 'image_alt_text', - [ - 'type' => Table::TYPE_TEXT, - 'nullable' => true, - 'after' => 'image', - 'comment' => 'Image Alt Text' - ] - ); - - return $this; - } - - private function addNodeSelectedItemId(SchemaSetupInterface $setup) - { - $connection = $setup->getConnection(); - $table = $setup->getTable('snowmenu_node'); - - $connection->addColumn( - $table, - NodeInterface::SELECTED_ITEM_ID, - [ - 'type' => Table::TYPE_SMALLINT, - 'length' => 6, - 'unsigned' => true, - 'nullable' => true, - 'comment' => 'Selected Item Id' - ] - ); - - return $this; - } - - /** - * @return $this - */ - private function addNodeImageSizeFields(SchemaSetupInterface $setup) - { - $connection = $setup->getConnection(); - $table = $setup->getTable('snowmenu_node'); - - $connection->addColumn( - $table, - NodeInterface::IMAGE_WIDTH, - [ - 'type' => Table::TYPE_INTEGER, - 'nullable' => true, - 'after' => NodeInterface::IMAGE_ALT_TEXT, - 'comment' => 'Image Width' - ] - ); - - $connection->addColumn( - $table, - NodeInterface::IMAGE_HEIGHT, - [ - 'type' => Table::TYPE_INTEGER, - 'nullable' => true, - 'after' => NodeInterface::IMAGE_WIDTH, - 'comment' => 'Image Height' - ] - ); - - return $this; - } - - private function addNodeCustomerGroups(SchemaSetupInterface $setup) - { - $connection = $setup->getConnection(); - $table = $setup->getTable('snowmenu_node'); - - $connection->addColumn( - $table, - NodeInterface::CUSTOMER_GROUPS, - [ - 'type' => Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => true, - 'after' => NodeInterface::SELECTED_ITEM_ID, - 'comment' => "Customer Groups Serialized" - ] - ); - - return $this; - } -} From cd2db76e25ba0d149054690f2031204421f5c8d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Fri, 5 Jul 2024 14:17:42 +0200 Subject: [PATCH 13/20] #94738 wip adjust loading customer group assignments --- Model/Menu/Node.php | 4 +- Model/Menu/Node/Image/Node.php | 2 +- Model/Menu/NodeRepository.php | 1 + Model/ResourceModel/Menu/Node.php | 23 ++++ Model/ResourceModel/Menu/Node/Collection.php | 12 +++ etc/db_schema.xml | 104 ++++++++++--------- 6 files changed, 93 insertions(+), 53 deletions(-) diff --git a/Model/Menu/Node.php b/Model/Menu/Node.php index 26d4f234..6da4c34d 100644 --- a/Model/Menu/Node.php +++ b/Model/Menu/Node.php @@ -351,8 +351,8 @@ public function setSelectedItemId($selectedItemId) public function getCustomerGroups() { $customerGroups = $this->_getData(NodeInterface::CUSTOMER_GROUPS); - if (!empty($customerGroups)) { - $customerGroups = $this->serializer->unserialize($customerGroups); + if ($customerGroups !== null) { + $customerGroups = explode(',', $customerGroups); if (is_array($customerGroups) && !empty($customerGroups)) { return $customerGroups; } diff --git a/Model/Menu/Node/Image/Node.php b/Model/Menu/Node/Image/Node.php index 8eef98b0..1ac72231 100644 --- a/Model/Menu/Node/Image/Node.php +++ b/Model/Menu/Node/Image/Node.php @@ -67,7 +67,7 @@ public function updateNodeImage(int $nodeId, ?string $image): void public function getNodeListImages(array $nodeIds): array { $searchCriteria = $this->searchCriteriaBuilder - ->addFilter(NodeInterface::NODE_ID, $nodeIds, 'in') + ->addFilter('main_table.' . NodeInterface::NODE_ID, $nodeIds, 'in') ->addFilter(NodeInterface::IMAGE, true, 'notnull') ->addFilter(NodeInterface::IMAGE, '', 'neq') ->create(); diff --git a/Model/Menu/NodeRepository.php b/Model/Menu/NodeRepository.php index dc69be42..5ef0831f 100644 --- a/Model/Menu/NodeRepository.php +++ b/Model/Menu/NodeRepository.php @@ -15,6 +15,7 @@ use Snowdog\Menu\Model\Menu\NodeFactory; use Snowdog\Menu\Model\ResourceModel\Menu\Node\CollectionFactory; use Magento\Framework\Api\SortOrder; +use Magento\Framework\DB\Sql\Expression; class NodeRepository implements NodeRepositoryInterface { diff --git a/Model/ResourceModel/Menu/Node.php b/Model/ResourceModel/Menu/Node.php index 4f65adc5..cba5a813 100644 --- a/Model/ResourceModel/Menu/Node.php +++ b/Model/ResourceModel/Menu/Node.php @@ -13,6 +13,29 @@ protected function _construct() $this->_init('snowmenu_node', 'node_id'); } + protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) + { + $connection = $this->getConnection(); + $connection->delete('snowmenu_customer', ['node_id = ?' => $object->getNodeId()]); + $currentCustomerGroups = $object->getData('customer_groups'); + if ($currentCustomerGroups && is_string($currentCustomerGroups)) { + $currentCustomerGroups = json_decode($currentCustomerGroups); + } + $insertData = []; + foreach ($currentCustomerGroups as $customerGroup) { + $insertData[] = [ + 'node_id' => $object->getNodeId(), + 'group_id' => $customerGroup + ]; + } + if ($currentCustomerGroups) { + $connection->insertMultiple('snowmenu_customer', $insertData); + } + + return parent::_afterSave($object); // TODO: Change the autogenerated stub + + } + public function getFields(): array { return $this->getConnection()->describeTable($this->getMainTable()); diff --git a/Model/ResourceModel/Menu/Node/Collection.php b/Model/ResourceModel/Menu/Node/Collection.php index dc015074..5ee789f3 100644 --- a/Model/ResourceModel/Menu/Node/Collection.php +++ b/Model/ResourceModel/Menu/Node/Collection.php @@ -1,6 +1,7 @@ getSelect()->joinLeft( + ['customer' => 'snowmenu_customer'], + 'main_table.node_id = customer.node_id', + ['customer_groups' => new Expression('GROUP_CONCAT(group_id SEPARATOR \',\')')] + )->group('main_table.node_id'); +// die ((string) $collection->getSelect()); + } } diff --git a/etc/db_schema.xml b/etc/db_schema.xml index 37469e32..d7330b00 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -1,53 +1,57 @@ - - - - - - - - - - - -
      - - - - - - - - - - - - - - - - - - - - - - - - - - -
      - - - - - - - - - - -
      + + + + + + + + + + + +
      + + + + + + + + + + + + + + + + + + + + + + + + + +
      + + + + + + + + + + +
      + + + + +
      From a34f01fc6b058f4824a906afe09d1875dd9f529e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Mon, 8 Jul 2024 08:52:50 +0200 Subject: [PATCH 14/20] #94738 adjust Block/Menu --- Block/Menu.php | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/Block/Menu.php b/Block/Menu.php index 32365daa..2b8fe0ba 100644 --- a/Block/Menu.php +++ b/Block/Menu.php @@ -3,10 +3,7 @@ namespace Snowdog\Menu\Block; use Magento\Customer\Model\Session; -use Magento\Framework\Api\Search\FilterGroupBuilder; -use Magento\Framework\Api\Search\SearchCriteriaFactory; use Magento\Framework\App\Cache\Type\Block; -use Magento\Framework\App\Config\ScopeConfigInterface; use Magento\Framework\DataObject; use Magento\Framework\View\Element\Template; use Magento\Framework\Event\Manager as EventManager; @@ -21,9 +18,13 @@ /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + * @SuppressWarnings(PHPMD.CyclomaticComplexity) + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity) */ class Menu extends Template implements DataObject\IdentityInterface { + const XML_SNOWMENU_GENERAL_CUSTOMER_GROUPS = 'snowmenu/general/customer_groups'; + /** * @var MenuRepositoryInterface */ @@ -43,15 +44,6 @@ class Menu extends Template implements DataObject\IdentityInterface private $menu = null; - /** - * @var SearchCriteriaFactory - */ - private $searchCriteriaFactory; - - /** - * @var FilterGroupBuilder - */ - private $filterGroupBuilder; /** * @var EventManager */ @@ -92,11 +84,6 @@ class Menu extends Template implements DataObject\IdentityInterface */ private $customerSession; - /** - * @var ScopeConfigInterface - */ - private $scopeConfig; - /** * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -106,21 +93,16 @@ public function __construct( MenuRepositoryInterface $menuRepository, NodeRepositoryInterface $nodeRepository, NodeTypeProvider $nodeTypeProvider, - SearchCriteriaFactory $searchCriteriaFactory, - FilterGroupBuilder $filterGroupBuilder, TemplateResolver $templateResolver, ImageFile $imageFile, Escaper $escaper, Session $customerSession, - ScopeConfigInterface $scopeConfig, array $data = [] ) { parent::__construct($context, $data); $this->menuRepository = $menuRepository; $this->nodeRepository = $nodeRepository; $this->nodeTypeProvider = $nodeTypeProvider; - $this->searchCriteriaFactory = $searchCriteriaFactory; - $this->filterGroupBuilder = $filterGroupBuilder; $this->eventManager = $eventManager; $this->templateResolver = $templateResolver; $this->imageFile = $imageFile; @@ -128,7 +110,6 @@ public function __construct( $this->setTemplate($this->getMenuTemplate($this->_template)); $this->submenuTemplate = $this->getSubmenuTemplate(); $this->customerSession = $customerSession; - $this->scopeConfig = $scopeConfig; } /** @@ -194,7 +175,7 @@ public function getCacheKeyInfo() if ($nodeCacheKeyInfo) { $info = array_merge($info, $nodeCacheKeyInfo); } - if ($this->scopeConfig->isSetFlag('snowmenu/general/customer_groups')) { + if ($this->_scopeConfig->isSetFlag(self::XML_SNOWMENU_GENERAL_CUSTOMER_GROUPS)) { $info[] = 'cust_group_' . $this->getCustomerGroupId(); } @@ -463,7 +444,7 @@ private function fetchData() { $nodes = $this->nodeRepository->getByMenu($this->loadMenu()->getId()); $currentCustomerGroup = $this->getCustomerGroupId(); - $customerGroupEnabled = $this->scopeConfig->getValue('snowmenu/general/customer_groups'); + $customerGroupEnabled = $this->_scopeConfig->getValue(self::XML_SNOWMENU_GENERAL_CUSTOMER_GROUPS); $result = []; $types = []; foreach ($nodes as $node) { From b578a0c18848b5a7203ae5840d4a25676aa15597 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Mon, 8 Jul 2024 09:47:10 +0200 Subject: [PATCH 15/20] #94738 add node_id index --- Model/ResourceModel/Menu/Node/Collection.php | 36 ++++++++++++++++++-- etc/db_schema.xml | 6 ++++ 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/Model/ResourceModel/Menu/Node/Collection.php b/Model/ResourceModel/Menu/Node/Collection.php index 5ee789f3..5157fadc 100644 --- a/Model/ResourceModel/Menu/Node/Collection.php +++ b/Model/ResourceModel/Menu/Node/Collection.php @@ -1,11 +1,37 @@ scopeConfig = $scopeConfig; + } + protected function _construct() { $this->_init( @@ -16,12 +42,18 @@ protected function _construct() protected function _initSelect() { - parent::_initSelect(); // TODO: Change the autogenerated stub + parent::_initSelect(); + + if (!$this->scopeConfig->isSetFlag(Menu::XML_SNOWMENU_GENERAL_CUSTOMER_GROUPS)) { + return $this; + } + $this->getSelect()->joinLeft( ['customer' => 'snowmenu_customer'], 'main_table.node_id = customer.node_id', ['customer_groups' => new Expression('GROUP_CONCAT(group_id SEPARATOR \',\')')] )->group('main_table.node_id'); -// die ((string) $collection->getSelect()); + + return $this; } } diff --git a/etc/db_schema.xml b/etc/db_schema.xml index d7330b00..21d02c1d 100644 --- a/etc/db_schema.xml +++ b/etc/db_schema.xml @@ -37,6 +37,9 @@ + + + @@ -53,5 +56,8 @@ + + +
      From 4d6f87be6424566a33c446ea4f7cce9819cbe932 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Mon, 8 Jul 2024 09:53:11 +0200 Subject: [PATCH 16/20] #94738 cleanup Node.php --- Model/ResourceModel/Menu/Node.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Model/ResourceModel/Menu/Node.php b/Model/ResourceModel/Menu/Node.php index cba5a813..b5425c10 100644 --- a/Model/ResourceModel/Menu/Node.php +++ b/Model/ResourceModel/Menu/Node.php @@ -17,23 +17,23 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) { $connection = $this->getConnection(); $connection->delete('snowmenu_customer', ['node_id = ?' => $object->getNodeId()]); - $currentCustomerGroups = $object->getData('customer_groups'); - if ($currentCustomerGroups && is_string($currentCustomerGroups)) { - $currentCustomerGroups = json_decode($currentCustomerGroups); + + $nodeCustomerGroups = $object->getData('customer_groups'); + if ($nodeCustomerGroups && is_string($nodeCustomerGroups)) { + $nodeCustomerGroups = json_decode($nodeCustomerGroups); } $insertData = []; - foreach ($currentCustomerGroups as $customerGroup) { + foreach ($nodeCustomerGroups as $customerGroup) { $insertData[] = [ 'node_id' => $object->getNodeId(), 'group_id' => $customerGroup ]; } - if ($currentCustomerGroups) { + if ($nodeCustomerGroups) { $connection->insertMultiple('snowmenu_customer', $insertData); } - return parent::_afterSave($object); // TODO: Change the autogenerated stub - + return parent::_afterSave($object); } public function getFields(): array From d30d2ac7e6c38b9ff1d1651e3447d91bd1112c8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Mon, 8 Jul 2024 09:54:17 +0200 Subject: [PATCH 17/20] #94738 regenerate db_schema_whitelist.json --- etc/db_schema_whitelist.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/etc/db_schema_whitelist.json b/etc/db_schema_whitelist.json index 83f74d3f..94d4d708 100644 --- a/etc/db_schema_whitelist.json +++ b/etc/db_schema_whitelist.json @@ -40,6 +40,9 @@ "constraint": { "PRIMARY": true, "SNOWMENU_NODE_MENU_ID_SNOWMENU_MENU_MENU_ID": true + }, + "index": { + "SNOWMENU_NODE_NODE_ID": true } }, "snowmenu_store": { @@ -52,5 +55,17 @@ "SNOWMENU_STORE_MENU_ID_SNOWMENU_MENU_MENU_ID": true, "SNOWMENU_STORE_STORE_ID_STORE_STORE_ID": true } + }, + "snowmenu_customer": { + "column": { + "node_id": true, + "group_id": true + }, + "index": { + "SNOWMENU_CUSTOMER_NODE_ID": true + }, + "constraint": { + "SNOWMENU_CUSTOMER_NODE_ID_SNOWMENU_NODE_NODE_ID": true + } } } \ No newline at end of file From c89c3310b6a8041d8b2ee1e8f2e3d0641c140cad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Mon, 8 Jul 2024 10:11:31 +0200 Subject: [PATCH 18/20] #94738 fix errors --- Model/Menu/Node/Image/File.php | 6 +++++- Model/ResourceModel/Menu/Node.php | 2 +- Model/ResourceModel/Menu/Node/Collection.php | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/Model/Menu/Node/Image/File.php b/Model/Menu/Node/Image/File.php index 0115aaf3..4a1b81bf 100644 --- a/Model/Menu/Node/Image/File.php +++ b/Model/Menu/Node/Image/File.php @@ -123,7 +123,11 @@ public function getImageSize(string $file): array $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); $fileFullPath = $mediaDirectory->getAbsolutePath(self::PATH . $file); - return getimagesize($fileFullPath); + try { + return getimagesize($fileFullPath); + } catch (Exception $e) { + return []; + } } private function getAbsolutePath(): string diff --git a/Model/ResourceModel/Menu/Node.php b/Model/ResourceModel/Menu/Node.php index b5425c10..b8f481cb 100644 --- a/Model/ResourceModel/Menu/Node.php +++ b/Model/ResourceModel/Menu/Node.php @@ -23,7 +23,7 @@ protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) $nodeCustomerGroups = json_decode($nodeCustomerGroups); } $insertData = []; - foreach ($nodeCustomerGroups as $customerGroup) { + foreach ($nodeCustomerGroups ?? [] as $customerGroup) { $insertData[] = [ 'node_id' => $object->getNodeId(), 'group_id' => $customerGroup diff --git a/Model/ResourceModel/Menu/Node/Collection.php b/Model/ResourceModel/Menu/Node/Collection.php index 5157fadc..3076fecc 100644 --- a/Model/ResourceModel/Menu/Node/Collection.php +++ b/Model/ResourceModel/Menu/Node/Collection.php @@ -28,8 +28,8 @@ public function __construct( AdapterInterface $connection = null, AbstractDb $resource = null ) { - parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); $this->scopeConfig = $scopeConfig; + parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource); } protected function _construct() From 2bf3811820d7a0d63ccd40da3304c157f31fd040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Mon, 8 Jul 2024 10:26:19 +0200 Subject: [PATCH 19/20] #94738 use HttpContext to obtain customer group id --- Block/Menu.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Block/Menu.php b/Block/Menu.php index 2b8fe0ba..dd076269 100644 --- a/Block/Menu.php +++ b/Block/Menu.php @@ -2,8 +2,8 @@ namespace Snowdog\Menu\Block; -use Magento\Customer\Model\Session; use Magento\Framework\App\Cache\Type\Block; +use Magento\Framework\App\Http\Context; use Magento\Framework\DataObject; use Magento\Framework\View\Element\Template; use Magento\Framework\Event\Manager as EventManager; @@ -80,9 +80,9 @@ class Menu extends Template implements DataObject\IdentityInterface private $escaper; /** - * @var Session + * @var Context */ - private $customerSession; + private $httpContext; /** * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -96,7 +96,7 @@ public function __construct( TemplateResolver $templateResolver, ImageFile $imageFile, Escaper $escaper, - Session $customerSession, + Context $httpContext, array $data = [] ) { parent::__construct($context, $data); @@ -109,7 +109,7 @@ public function __construct( $this->escaper = $escaper; $this->setTemplate($this->getMenuTemplate($this->_template)); $this->submenuTemplate = $this->getSubmenuTemplate(); - $this->customerSession = $customerSession; + $this->httpContext = $httpContext; } /** @@ -511,6 +511,6 @@ private function getSubmenuTemplate() public function getCustomerGroupId() { - return $this->customerSession->getCustomerGroupId(); + return $this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP); } } From 9463f366d6ec46e1ba92f9332bafa4ff8403dbf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Wac=C5=82awczyk?= Date: Tue, 9 Jul 2024 12:46:06 +0200 Subject: [PATCH 20/20] #94738 use serializer, catch thrown exception when image is missing --- Model/Menu/Node.php | 11 ++++++----- Model/Menu/Node/Image/File.php | 6 +----- Model/ResourceModel/Menu/Node.php | 18 ++++++++++++++++-- Service/Menu/SaveRequestProcessor.php | 6 +++++- 4 files changed, 28 insertions(+), 13 deletions(-) diff --git a/Model/Menu/Node.php b/Model/Menu/Node.php index 6da4c34d..4291d991 100644 --- a/Model/Menu/Node.php +++ b/Model/Menu/Node.php @@ -351,11 +351,12 @@ public function setSelectedItemId($selectedItemId) public function getCustomerGroups() { $customerGroups = $this->_getData(NodeInterface::CUSTOMER_GROUPS); - if ($customerGroups !== null) { - $customerGroups = explode(',', $customerGroups); - if (is_array($customerGroups) && !empty($customerGroups)) { - return $customerGroups; - } + if ($customerGroups == null) { + return []; + } + $customerGroups = explode(',', $customerGroups); + if (is_array($customerGroups) && !empty($customerGroups)) { + return $customerGroups; } return []; diff --git a/Model/Menu/Node/Image/File.php b/Model/Menu/Node/Image/File.php index 4a1b81bf..0115aaf3 100644 --- a/Model/Menu/Node/Image/File.php +++ b/Model/Menu/Node/Image/File.php @@ -123,11 +123,7 @@ public function getImageSize(string $file): array $mediaDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA); $fileFullPath = $mediaDirectory->getAbsolutePath(self::PATH . $file); - try { - return getimagesize($fileFullPath); - } catch (Exception $e) { - return []; - } + return getimagesize($fileFullPath); } private function getAbsolutePath(): string diff --git a/Model/ResourceModel/Menu/Node.php b/Model/ResourceModel/Menu/Node.php index b8f481cb..8f0609fd 100644 --- a/Model/ResourceModel/Menu/Node.php +++ b/Model/ResourceModel/Menu/Node.php @@ -4,23 +4,37 @@ namespace Snowdog\Menu\Model\ResourceModel\Menu; +use Magento\Framework\Model\AbstractModel; use Magento\Framework\Model\ResourceModel\Db\AbstractDb; +use Magento\Framework\Model\ResourceModel\Db\Context; +use Magento\Framework\Serialize\SerializerInterface; class Node extends AbstractDb { + protected $serializer; + + public function __construct( + Context $context, + SerializerInterface $serializer, + $connectionName = null + ) { + $this->serializer = $serializer; + parent::__construct($context, $connectionName); + } + protected function _construct() { $this->_init('snowmenu_node', 'node_id'); } - protected function _afterSave(\Magento\Framework\Model\AbstractModel $object) + protected function _afterSave(AbstractModel $object) { $connection = $this->getConnection(); $connection->delete('snowmenu_customer', ['node_id = ?' => $object->getNodeId()]); $nodeCustomerGroups = $object->getData('customer_groups'); if ($nodeCustomerGroups && is_string($nodeCustomerGroups)) { - $nodeCustomerGroups = json_decode($nodeCustomerGroups); + $nodeCustomerGroups = $this->serializer->unserialize($nodeCustomerGroups); } $insertData = []; foreach ($nodeCustomerGroups ?? [] as $customerGroup) { diff --git a/Service/Menu/SaveRequestProcessor.php b/Service/Menu/SaveRequestProcessor.php index 5ac76126..00bf894f 100644 --- a/Service/Menu/SaveRequestProcessor.php +++ b/Service/Menu/SaveRequestProcessor.php @@ -226,7 +226,11 @@ private function processImageParameters(array $nodeData, NodeInterface &$nodeObj if (empty($nodeData[NodeInterface::IMAGE_WIDTH]) || empty($nodeData[NodeInterface::IMAGE_HEIGHT]) ) { - $imageSize = $this->nodeImageFile->getImageSize($nodeData[NodeInterface::IMAGE]); + try { + $imageSize = $this->nodeImageFile->getImageSize($nodeData[NodeInterface::IMAGE]); + } catch (\Exception $e) { + $imageSize = null; + } if (!empty($imageSize)) { $nodeObject