Skip to content

Use current sore id for category runtime cache #36394

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

Merged
merged 15 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 4 additions & 5 deletions app/code/Magento/Catalog/Model/CategoryRepository.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2014 Adobe
* All Rights Reserved.
*/

namespace Magento\Catalog\Model;
Expand Down Expand Up @@ -149,7 +148,7 @@ public function save(CategoryInterface $category)
*/
public function get($categoryId, $storeId = null)
{
$cacheKey = $storeId ?? 'all';
$cacheKey = $storeId ?? $this->storeManager->getStore()->getId();
if (!isset($this->instances[$categoryId][$cacheKey])) {
/** @var Category $category */
$category = $this->categoryFactory->create();
Expand Down Expand Up @@ -231,7 +230,7 @@ protected function validateCategory(Category $category)
* Lazy loader for the converter.
*
* @return ExtensibleDataObjectConverter
*
* phpcs:disable Magento2.Annotation.MethodAnnotationStructure
* @deprecated 101.0.0
* @see we don't recommend this approach anymore
*/
Expand Down
12 changes: 3 additions & 9 deletions app/code/Magento/Catalog/Model/ResourceModel/Category.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2011 Adobe
* All Rights Reserved.
*/

/**
Expand Down Expand Up @@ -37,8 +37,6 @@ class Category extends AbstractResource implements ResetAfterRequestInterface
protected $_tree;

/**
* Catalog products table name
*
* @var string
*/
protected $_categoryProductTable;
Expand All @@ -49,15 +47,11 @@ class Category extends AbstractResource implements ResetAfterRequestInterface
private $entitiesWhereAttributesIs;

/**
* Id of 'is_active' category attribute
*
* @var int
*/
protected $_isActiveAttributeId = null;

/**
* Id of store
*
* @var int
*/
protected $_storeId = null;
Expand Down Expand Up @@ -455,7 +449,7 @@ protected function _saveCategoryProducts($category)
'position' => (int)$position,
];
}
$connection->insertMultiple($this->getCategoryProductTable(), $data);
$connection->insertOnDuplicate($this->getCategoryProductTable(), $data, ['position']);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2020 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -48,10 +48,9 @@ protected function setUp(): void
public function testUpdateCategoryForDefaultStoreView(array $postData): void
{
$storeId = (int)$this->storeManager->getStore('default')->getId();
$postData = array_merge($postData, ['store_id' => $storeId]);
$responseData = $this->performSaveCategoryRequest($postData);
$this->assertRequestIsSuccessfullyPerformed($responseData);
$category = $this->categoryRepository->get($postData['entity_id'], $postData['store_id']);
$category = $this->categoryRepository->get($postData['entity_id'], $storeId);
unset($postData['use_default']);
unset($postData['use_config']);
foreach ($postData as $key => $value) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2012 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -153,7 +153,6 @@ public function testDefaultValueForCategoryUrlPath(): void
$categoryId = 3;
$category = $this->categoryRepository->get($categoryId);
$newUrlPath = 'test_url_path';
$defaultUrlPath = $category->getData('url_path');

// update url_path and check it
$category->setStoreId(1);
Expand All @@ -178,7 +177,7 @@ public function testDefaultValueForCategoryUrlPath(): void
MessageInterface::TYPE_SUCCESS
);
$category = $this->categoryRepository->get($categoryId);
$this->assertEquals($defaultUrlPath, $category->getData('url_key'));
$this->assertEquals($newUrlPath, $category->getData('url_key'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function testChildrenUrlPathContainsParentCustomScopeUrlKey()
[
'parent_id' => $category1->getId(),
'name' => 'Category 2',
'url_key' => null,
'url_key' => 'category-2',
'is_active' => true
]
);
Expand All @@ -114,7 +114,7 @@ public function testChildrenUrlPathContainsParentCustomScopeUrlKey()
$this->storeManager->setCurrentStore($secondStore);

$category2 = $this->categoryRepository->get($category2->getId());
$category2->setUrlKey(null);
$category2->setUrlKey('category-2');
$this->categoryRepository->save($category2);

$this->storeManager->setCurrentStore(StoreModel::DEFAULT_STORE_ID);
Expand Down