Skip to content

Commit

Permalink
SMM-5 add hide_if_empty node field
Browse files Browse the repository at this point in the history
  • Loading branch information
adamwaclawczyk committed Jan 7, 2025
1 parent efd01fd commit 0483d03
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 5 deletions.
13 changes: 13 additions & 0 deletions Api/Data/NodeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface NodeInterface
const ADDITIONAL_DATA = 'additional_data';
const SELECTED_ITEM_ID = 'selected_item_id';
const CUSTOMER_GROUPS = 'customer_groups';
const HIDE_IF_EMPTY = 'hide_if_empty';

/**
* Get node id
Expand Down Expand Up @@ -316,4 +317,16 @@ public function setCustomerGroups($customerGroups);
* @return bool
*/
public function isVisible($customerGroupId);


/**
* @return bool
*/
public function getHideIfEmpty();

/**
* @param bool $hideIfEmpty
* @return $this
*/
public function setHideIfEmpty($hideIfEmpty);
}
2 changes: 1 addition & 1 deletion Block/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ private function fetchData()
foreach ($types['category'] as $nodes) {
$categoryProvider = $this->nodeTypeProvider->getProvider('category');
$productCount = $categoryProvider->getCategoryProductCount($nodes['node']->getNodeId());
if (empty($productCount)) {
if (empty($productCount) && $nodes['node']->getHideIfEmpty()) {
[$level, $parent, $idx] = $nodes['path'];
unset($this->nodes[$level][$parent][$idx]);
}
Expand Down
3 changes: 2 additions & 1 deletion Model/GraphQl/Resolver/DataProvider/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ private function convertData(NodeInterface $node): array
NodeInterface::UPDATE_TIME => $node->getUpdateTime(),
NodeInterface::ADDITIONAL_DATA => $node->getAdditionalData(),
NodeInterface::SELECTED_ITEM_ID => $node->getSelectedItemId(),
NodeInterface::CUSTOMER_GROUPS => $node->getCustomerGroups()
NodeInterface::CUSTOMER_GROUPS => $node->getCustomerGroups(),
NodeInterface::HIDE_IF_EMPTY => $node->getHideIfEmpty(),
];
}

Expand Down
10 changes: 10 additions & 0 deletions Model/Menu/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,14 @@ public function isVisible($customerGroupId)

return false;
}

public function getHideIfEmpty()
{
return (bool) $this->_getData(NodeInterface::HIDE_IF_EMPTY);
}

public function setHideIfEmpty($hideIfEmpty)
{
return $this->setData(NodeInterface::HIDE_IF_EMPTY, (bool) $hideIfEmpty);
}
}
1 change: 1 addition & 0 deletions etc/db_schema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<column xsi:type="smallint" name="selected_item_id" padding="5" unsigned="true" nullable="true" identity="false" comment="Selected Item Id"/>
<column xsi:type="int" name="image_width" padding="11" unsigned="false" nullable="true" identity="false" comment="Image Width"/>
<column xsi:type="int" name="image_heigth" padding="11" unsigned="false" nullable="true" identity="false" comment="Image Height"/>
<column xsi:type="smallint" name="hide_if_empty" padding="6" unsigned="false" nullable="false" identity="false" default="0" comment="Hide If Empty"/>
<constraint xsi:type="primary" referenceId="PRIMARY">
<column name="node_id"/>
</constraint>
Expand Down
3 changes: 2 additions & 1 deletion etc/db_schema_whitelist.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
"selected_item_id": true,
"image_width": true,
"image_heigth": true,
"customer_groups": true
"customer_groups": true,
"hide_if_empty": true
},
"constraint": {
"PRIMARY": true,
Expand Down
4 changes: 3 additions & 1 deletion view/adminhtml/templates/menu/nodes.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ $vueComponents = $block->getVueComponents();
"imageHeight" : "<?= __('Image Height') ?>",
"selectedItemId" : "<?= __('Selected Item Id') ?>",
"customerGroups" : "<?= __('Customer Groups') ?>",
"customerGroupsDescription" : "<?= __('If no customer group is selected, the node will be visible to all customers.') ?>"
"customerGroupsDescription" : "<?= __('If no customer group is selected, the node will be visible to all customers.') ?>",
"hideIfEmpty" : "<?= __("Hide node if empty") ?>",
"hideIfEmptyDescription" : "<?= __("(e.g. no product in categories)") ?>"
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion view/adminhtml/web/vue/app.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@
submenu_template: null,
columns: [],
is_active: 0,
customer_groups: []
customer_groups: [],
hide_if_empty: 0
});
},
setUniqueIds(node) {
Expand Down

0 comments on commit 0483d03

Please sign in to comment.