Skip to content

Commit 54b5f2f

Browse files
committed
Merge remote-tracking branch 'mainline/2.4-develop' into PR_7_JAN_2023
2 parents 3317c61 + d48a739 commit 54b5f2f

File tree

24 files changed

+1200
-446
lines changed

24 files changed

+1200
-446
lines changed

app/code/Magento/Catalog/Model/ResourceModel/Attribute/ConditionBuilder.php

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88

99
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1010
use Magento\Framework\EntityManager\EntityMetadataInterface;
11+
use Magento\Framework\Exception\NoSuchEntityException;
1112
use Magento\Store\Api\Data\StoreInterface;
1213
use Magento\Store\Model\Store;
1314
use Magento\Store\Model\StoreManagerInterface;
14-
use Magento\Catalog\Model\ResourceModel\Eav\Attribute as CatalogEavAttribute;
1515
use Magento\Store\Model\Website;
1616
use Magento\Framework\Model\Entity\ScopeInterface;
1717

1818
/**
1919
* Builds scope-related conditions for catalog attributes
2020
*
2121
* Class ConditionBuilder
22-
* @package Magento\Catalog\Model\ResourceModel\Attribute
2322
*/
2423
class ConditionBuilder
2524
{
@@ -45,6 +44,7 @@ public function __construct(StoreManagerInterface $storeManager)
4544
* @param ScopeInterface[] $scopes
4645
* @param string $linkFieldValue
4746
* @return array
47+
* @throws NoSuchEntityException
4848
*/
4949
public function buildExistingAttributeWebsiteScope(
5050
AbstractAttribute $attribute,
@@ -56,7 +56,7 @@ public function buildExistingAttributeWebsiteScope(
5656
if (!$website) {
5757
return [];
5858
}
59-
$storeIds = $website->getStoreIds();
59+
$storeIds = $this->getStoreIds($website);
6060

6161
$condition = [
6262
$metadata->getLinkField() . ' = ?' => $linkFieldValue,
@@ -81,6 +81,7 @@ public function buildExistingAttributeWebsiteScope(
8181
* @param ScopeInterface[] $scopes
8282
* @param string $linkFieldValue
8383
* @return array
84+
* @throws NoSuchEntityException
8485
*/
8586
public function buildNewAttributesWebsiteScope(
8687
AbstractAttribute $attribute,
@@ -92,7 +93,7 @@ public function buildNewAttributesWebsiteScope(
9293
if (!$website) {
9394
return [];
9495
}
95-
$storeIds = $website->getStoreIds();
96+
$storeIds = $this->getStoreIds($website);
9697

9798
$condition = [
9899
$metadata->getLinkField() => $linkFieldValue,
@@ -109,8 +110,11 @@ public function buildNewAttributesWebsiteScope(
109110
}
110111

111112
/**
113+
* Get website for website scope
114+
*
112115
* @param array $scopes
113116
* @return null|Website
117+
* @throws NoSuchEntityException
114118
*/
115119
private function getWebsiteForWebsiteScope(array $scopes)
116120
{
@@ -119,8 +123,11 @@ private function getWebsiteForWebsiteScope(array $scopes)
119123
}
120124

121125
/**
126+
* Get store from scopes
127+
*
122128
* @param ScopeInterface[] $scopes
123129
* @return StoreInterface|null
130+
* @throws NoSuchEntityException
124131
*/
125132
private function getStoreFromScopes(array $scopes)
126133
{
@@ -132,4 +139,20 @@ private function getStoreFromScopes(array $scopes)
132139

133140
return null;
134141
}
142+
143+
/**
144+
* Get storeIds from the website
145+
*
146+
* @param Website $website
147+
* @return array
148+
*/
149+
private function getStoreIds(Website $website): array
150+
{
151+
$storeIds = $website->getStoreIds();
152+
153+
if (empty($storeIds) && $website->getCode() === Website::ADMIN_CODE) {
154+
$storeIds[] = Store::DEFAULT_STORE_ID;
155+
}
156+
return $storeIds;
157+
}
135158
}
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Catalog\Model\System\Config\Backend\Rss;
9+
10+
use Magento\Catalog\Api\Data\ProductInterface;
11+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
12+
use Magento\Framework\App\Cache\TypeListInterface;
13+
use Magento\Framework\App\Config\ScopeConfigInterface;
14+
use Magento\Framework\App\Config\Value as ConfigValue;
15+
use Magento\Framework\App\ObjectManager;
16+
use Magento\Framework\Data\Collection\AbstractDb;
17+
use Magento\Framework\Model\Context;
18+
use Magento\Framework\Model\ResourceModel\AbstractResource;
19+
use Magento\Framework\Registry;
20+
21+
class Category extends ConfigValue
22+
{
23+
/**
24+
* @var ProductAttributeRepositoryInterface
25+
*/
26+
private $productAttributeRepository;
27+
28+
/**
29+
* @param Context $context
30+
* @param Registry $registry
31+
* @param ScopeConfigInterface $config
32+
* @param TypeListInterface $cacheTypeList
33+
* @param AbstractResource|null $resource
34+
* @param AbstractDb|null $resourceCollection
35+
* @param array $data
36+
* @param ProductAttributeRepositoryInterface|null $productAttributeRepository
37+
*/
38+
public function __construct(
39+
Context $context,
40+
Registry $registry,
41+
ScopeConfigInterface $config,
42+
TypeListInterface $cacheTypeList,
43+
AbstractResource $resource = null,
44+
AbstractDb $resourceCollection = null,
45+
array $data = [],
46+
ProductAttributeRepositoryInterface $productAttributeRepository = null
47+
) {
48+
parent::__construct($context, $registry, $config, $cacheTypeList, $resource, $resourceCollection, $data);
49+
50+
$this->productAttributeRepository = $productAttributeRepository ??
51+
ObjectManager::getInstance()->get(ProductAttributeRepositoryInterface::class);
52+
}
53+
54+
/**
55+
* @inheritdoc
56+
*/
57+
public function afterSave()
58+
{
59+
if ($this->isValueChanged() && $this->getValue()) {
60+
$updatedAtAttr = $this->productAttributeRepository->get(ProductInterface::UPDATED_AT);
61+
if (!$updatedAtAttr->getUsedForSortBy()) {
62+
$updatedAtAttr->setUsedForSortBy(true);
63+
$this->productAttributeRepository->save($updatedAtAttr);
64+
}
65+
}
66+
67+
return parent::afterSave();
68+
}
69+
}

0 commit comments

Comments
 (0)