Skip to content

magento/magento2#28358: URL rewrites are not generated for categorie with 'Include in Menu=No' when creating a store view #30427

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: 2.4-develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/code/Magento/Catalog/Model/ResourceModel/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public function __construct(
$data = [],
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
MetadataPool $metadataPool = null
) {
){
parent::__construct(
$context,
$storeManager,
Expand All @@ -137,7 +137,7 @@ public function __construct(
$this->_categoryTreeFactory = $categoryTreeFactory;
$this->_categoryCollectionFactory = $categoryCollectionFactory;
$this->_eventManager = $eventManager;
$this->connectionName = 'catalog';
$this->connectionName = 'catalog';
$this->indexerProcessor = $indexerProcessor;
$this->serializer = $serializer ?: ObjectManager::getInstance()
->get(\Magento\Framework\Serialize\Serializer\Json::class);
Expand Down Expand Up @@ -289,7 +289,7 @@ protected function _beforeSave(\Magento\Framework\DataObject $object)
$object->setPosition($this->_getMaxPosition($object->getPath()) + 1);
}
$path = explode('/', (string)$object->getPath());
$level = count($path) - ($object->getId() ? 1 : 0);
$level = count($path) - ($object->getId() ? 1 : 0);
$toUpdateChild = array_diff($path, [$object->getId()]);

if (!$object->hasPosition()) {
Expand Down Expand Up @@ -696,7 +696,7 @@ public function getProductCount($category)
$bind = ['category_id' => (int)$category->getId()];
$counts = $this->getConnection()->fetchOne($select, $bind);

return (int) $counts;
return (int)$counts;
}

/**
Expand All @@ -715,7 +715,7 @@ public function getCategories($parent, $recursionLevel = 0, $sorted = false, $as
/* @var $tree \Magento\Catalog\Model\ResourceModel\Category\Tree */
$nodes = $tree->loadNode($parent)->loadChildren($recursionLevel)->getChildren();

$tree->addCollectionData(null, $sorted, $parent, $toLoad, true);
$tree->addCollectionData(null, $sorted, $parent, $toLoad, true, false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of change, this getCategories method wouldn't make more sense to look at the CatalogUrlRewrite plugins and use CategoryRepository there to fetch the required categories?


if ($asCollection) {
return $tree->getCollection();
Expand Down Expand Up @@ -949,7 +949,7 @@ public function changeParent(
\Magento\Catalog\Model\Category $category,
\Magento\Catalog\Model\Category $newParent,
$afterCategoryId = null
) {
){
$childrenCount = $this->getChildrenCount($category->getId()) + 1;
$table = $this->getEntityTable();
$connection = $this->getConnection();
Expand Down Expand Up @@ -1112,7 +1112,7 @@ public function delete($object)
/**
* Save entity's attributes into the object's resource
*
* @param \Magento\Framework\Model\AbstractModel $object
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Exception
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public function getStoreId()
* @param array $exclude
* @param boolean $toLoad
* @param boolean $onlyActive
* @param boolean $onlyIncludeInMenu
* @return $this
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
Expand All @@ -179,7 +180,8 @@ public function addCollectionData(
$sorted = false,
$exclude = [],
$toLoad = true,
$onlyActive = false
$onlyActive = false,
$onlyIncludeInMenu = false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing an @api public method is BIC, please have a look at https://devdocs.magento.com/contributor-guide/backward-compatible-development/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @gabrieldagama i have added code as BIC . Please review this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sodhisarab please, extract logic to the separate class

) {
if ($collection === null) {
$collection = $this->getCollection($sorted);
Expand All @@ -204,7 +206,10 @@ public function addCollectionData(
$collection->addFieldToFilter('entity_id', ['nin' => $disabledIds]);
}
$collection->addAttributeToFilter('is_active', 1);
$collection->addAttributeToFilter('include_in_menu', 1);
if($onlyIncludeInMenu){
$collection->addAttributeToFilter('include_in_menu', 1);
}

}

if ($this->_joinUrlRewriteIntoCollection) {
Expand Down