-
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
base: 2.4-develop
Are you sure you want to change the base?
Changes from 19 commits
44d1ebf
3403f39
660b0fb
1f6f3ff
bc28211
88c8aaa
5202a5b
c974fe5
37a60cb
be1b08c
fa6a920
b939410
e6f93dd
5f9c440
afc18a2
18e46f2
43d26e7
749ea9a
ffb4cee
a92024f
9f9470d
5800b49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -176,6 +176,8 @@ public function getStoreId() | |
* @param boolean $toLoad | ||
* @param boolean $onlyActive | ||
* @return $this | ||
* @deprecated This method is not intended for usage in child classes | ||
* @see addCollectionDataParams($collection, $sorted, $exclude, $toLoad, $onlyActive, $onlyIncludeInMenu) | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
* @SuppressWarnings(PHPMD.NPathComplexity) | ||
*/ | ||
|
@@ -236,6 +238,81 @@ public function addCollectionData( | |
return $this; | ||
} | ||
|
||
/** | ||
* Add data params to collection | ||
* | ||
* @param Collection|null $collection | ||
* @param boolean $sorted | ||
* @param array $exclude | ||
* @param boolean $toLoad | ||
* @param boolean $onlyActive | ||
* @param boolean $onlyIncludeInMenu | ||
* @return $this | ||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) | ||
* @SuppressWarnings(PHPMD.NPathComplexity) | ||
*/ | ||
public function addCollectionDataParams( | ||
$collection = null, | ||
$sorted = false, | ||
$exclude = [], | ||
$toLoad = true, | ||
$onlyActive = false, | ||
$onlyIncludeInMenu = false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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); | ||
} else { | ||
$this->setCollection($collection); | ||
} | ||
|
||
if (!is_array($exclude)) { | ||
$exclude = [$exclude]; | ||
} | ||
|
||
$nodeIds = []; | ||
foreach ($this->getNodes() as $node) { | ||
if (!in_array($node->getId(), $exclude)) { | ||
$nodeIds[] = $node->getId(); | ||
} | ||
} | ||
$collection->addIdFilter($nodeIds); | ||
|
||
if ($onlyActive) { | ||
$disabledIds = $this->_getDisabledIds($collection, $nodeIds); | ||
if ($disabledIds) { | ||
$collection->addFieldToFilter('entity_id', ['nin' => $disabledIds]); | ||
} | ||
$collection->addAttributeToFilter('is_active', 1); | ||
if ($onlyIncludeInMenu) { | ||
$collection->addAttributeToFilter('include_in_menu', 1); | ||
} | ||
} | ||
|
||
if ($this->_joinUrlRewriteIntoCollection) { | ||
$collection->joinUrlRewrite(); | ||
$this->_joinUrlRewriteIntoCollection = false; | ||
} | ||
|
||
if ($toLoad) { | ||
$collection->load(); | ||
|
||
foreach ($collection as $category) { | ||
$node = $this->getNodeById($category->getId()); | ||
if ($node) { | ||
$node->addData($category->getData()); | ||
} | ||
} | ||
|
||
foreach ($this->getNodes() as $node) { | ||
if ($node->getParent() && !$collection->getItemById($node->getId())) { | ||
$this->removeNode($node); | ||
} | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Add inactive categories ids | ||
* | ||
|
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\Catalog\Api\Data\CategoryInterfaceFactory; | ||
use Magento\Catalog\Model\Category; | ||
use Magento\TestFramework\Helper\Bootstrap; | ||
|
||
$objectManager = Bootstrap::getObjectManager(); | ||
$categoryFactory = $objectManager->get(CategoryInterfaceFactory::class); | ||
|
||
/** @var $category Category */ | ||
$category = $categoryFactory->create(); | ||
$category->isObjectNew(true); | ||
$category->setId(3) | ||
->setName('Category 123') | ||
->setParentId(2) | ||
->setPath('1/2/3') | ||
->setLevel(2) | ||
->setAvailableSortBy('name') | ||
->setDefaultSortBy('name') | ||
->setIncludeInMenu(false) | ||
->setIsActive(true) | ||
->setPosition(1) | ||
->save(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
use Magento\TestFramework\Workaround\Override\Fixture\Resolver; | ||
|
||
Resolver::getInstance()->requireDataFixture('Magento/Catalog/_files/categories_rollback.php'); |
Uh oh!
There was an error while loading. Please reload this page.