-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
sodhisarab
wants to merge
22
commits into
magento:2.4-develop
Choose a base branch
from
sodhisarab:fix-for-28358-categroy-url-issue
base: 2.4-develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
44d1ebf
magento/magento2#28358: URL rewrites are not generated for categories…
SarabjeetSodhi 3403f39
Update Category.php
sodhisarab 660b0fb
Update Category.php
sodhisarab 1f6f3ff
Update Category.php
sodhisarab bc28211
Update Category.php
sodhisarab 88c8aaa
Update Tree.php
sodhisarab 5202a5b
Update Category.php
sodhisarab c974fe5
Update Tree.php
sodhisarab 37a60cb
Update TreeTest.php
sodhisarab be1b08c
Update Tree.php
sodhisarab fa6a920
Update Category.php
sodhisarab b939410
Update Tree.php
sodhisarab e6f93dd
Merge branch '2.4-develop' into fix-for-28358-categroy-url-issue
engcom-Charlie 5f9c440
revert old method behavior, refactor
engcom-Charlie afc18a2
Merge branch '2.4-develop' into fix-for-28358-categroy-url-issue
engcom-Charlie 18e46f2
fix generate URL rewrites for category with 'Include in Menu=No' afte…
engcom-Charlie 43d26e7
add integration test
engcom-Charlie 749ea9a
Merge branch '2.4-develop' into fix-for-28358-categroy-url-issue
engcom-Charlie ffb4cee
fix unit tests
engcom-Charlie a92024f
Merge branch '2.4-develop' into fix-for-28358-categroy-url-issue
engcom-Charlie 9f9470d
move new method to separate class
engcom-Charlie 5800b49
fix unit
engcom-Charlie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
app/code/Magento/Catalog/Model/Category/GetCategoriesCollection.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Magento\Catalog\Model\Category; | ||
|
||
use Magento\Catalog\Model\ResourceModel\Category\Collection; | ||
use Magento\Catalog\Model\ResourceModel\Category\TreeFactory; | ||
use Magento\Framework\Data\Tree\Node\Collection as NodeCollection; | ||
|
||
/** | ||
* Returns categories collection | ||
*/ | ||
class GetCategoriesCollection | ||
{ | ||
/** | ||
* @var TreeFactory | ||
*/ | ||
private $categoryTreeFactory; | ||
|
||
/** | ||
* @param TreeFactory $categoryTreeFactory | ||
*/ | ||
public function __construct(TreeFactory $categoryTreeFactory) | ||
{ | ||
$this->categoryTreeFactory = $categoryTreeFactory; | ||
} | ||
|
||
/** | ||
* Returns collection | ||
* | ||
* @param int $parent | ||
* @param int|null $recursionLevel | ||
* @param bool|null $sorted | ||
* @param bool|null $asCollection | ||
* @param bool|null $toLoad | ||
* @param bool|null $onlyActive | ||
* @param bool|null $onlyIncludeInMenu | ||
* @return NodeCollection|Collection | ||
*/ | ||
public function execute( | ||
int $parent, | ||
?int $recursionLevel = 0, | ||
?bool $sorted = false, | ||
?bool $asCollection = false, | ||
?bool $toLoad = true, | ||
?bool $onlyActive = true, | ||
?bool $onlyIncludeInMenu = true | ||
) { | ||
$tree = $this->categoryTreeFactory->create(); | ||
$nodes = $tree->loadNode($parent) | ||
->loadChildren($recursionLevel) | ||
->getChildren(); | ||
|
||
$tree->addCollectionDataParams(null, $sorted, $parent, $toLoad, $onlyActive, $onlyIncludeInMenu); | ||
|
||
return $asCollection ? $tree->getCollection() : $nodes; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
.../integration/testsuite/Magento/CatalogUrlRewrite/Model/Category/Plugin/Store/ViewTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogUrlRewrite\Model\Category\Plugin\Store; | ||
|
||
use Magento\Framework\ObjectManagerInterface; | ||
use Magento\Store\Model\StoreFactory; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollectionFactory; | ||
use Magento\UrlRewrite\Service\V1\Data\UrlRewrite; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Verify generate url rewrites after creating store view. | ||
*/ | ||
class ViewTest extends TestCase | ||
{ | ||
/** | ||
* @var ObjectManagerInterface | ||
*/ | ||
private $objectManager; | ||
|
||
/** | ||
* @var StoreFactory | ||
*/ | ||
private $storeFactory; | ||
|
||
/** | ||
* @var UrlRewriteCollectionFactory | ||
*/ | ||
private $urlRewriteCollectionFactory; | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
$this->objectManager = Bootstrap::getObjectManager(); | ||
$this->storeFactory = $this->objectManager->create(StoreFactory::class); | ||
$this->urlRewriteCollectionFactory = $this->objectManager->get(UrlRewriteCollectionFactory::class); | ||
} | ||
|
||
/** | ||
* Verify that url will be generated for category which excluded for menu after creating store view | ||
* | ||
* @magentoAppArea adminhtml | ||
* @magentoDataFixture Magento/CatalogUrlRewrite/_files/category_excluded_from_menu.php | ||
* | ||
* @return void | ||
*/ | ||
public function testAfterSaveVerifyCategoryExcludedForMenuUrlRewrite(): void | ||
{ | ||
$website = $this->objectManager->get(StoreManagerInterface::class) | ||
->getWebsite(); | ||
|
||
$store = $this->storeFactory->create(); | ||
$store->setCode('custom_store_777') | ||
->setWebsiteId($website->getId()) | ||
->setGroupId($website->getDefaultGroupId()) | ||
->setName('Custom Test Store') | ||
->setSortOrder(10) | ||
->setIsActive(1) | ||
->save(); | ||
|
||
$urlRewriteCollection = $this->urlRewriteCollectionFactory->create(); | ||
$urlRewriteCollection->addFieldToFilter(UrlRewrite::STORE_ID, $store->getId()) | ||
->addFieldToFilter(UrlRewrite::TARGET_PATH, 'catalog/category/view/id/' . 3); | ||
|
||
$this->assertCount(1, $urlRewriteCollection); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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/
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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