Skip to content

Commit 8158fb6

Browse files
committed
Merge branch '2.4-develop' of https://github.com/magento-l3/magento2ce into ACP2E-1999
2 parents 5619b82 + 2abc466 commit 8158fb6

File tree

104 files changed

+6114
-365
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+6114
-365
lines changed

app/code/Magento/Catalog/Model/Product/Attribute/Source/Countryofmanufacture.php

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,62 @@
1111
*/
1212
namespace Magento\Catalog\Model\Product\Attribute\Source;
1313

14+
use Magento\Directory\Model\CountryFactory;
1415
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
16+
use Magento\Framework\App\Cache\Type\Config;
1517
use Magento\Framework\Data\OptionSourceInterface;
18+
use Magento\Framework\Locale\ResolverInterface;
19+
use Magento\Framework\Serialize\SerializerInterface;
20+
use Magento\Store\Model\StoreManagerInterface;
1621

1722
class Countryofmanufacture extends AbstractSource implements OptionSourceInterface
1823
{
1924
/**
20-
* @var \Magento\Framework\App\Cache\Type\Config
25+
* @var Config
2126
*/
2227
protected $_configCacheType;
2328

2429
/**
25-
* Store manager
26-
*
27-
* @var \Magento\Store\Model\StoreManagerInterface
30+
* @var StoreManagerInterface
2831
*/
2932
protected $_storeManager;
3033

3134
/**
32-
* Country factory
33-
*
34-
* @var \Magento\Directory\Model\CountryFactory
35+
* @var CountryFactory
3536
*/
3637
protected $_countryFactory;
3738

3839
/**
39-
* @var \Magento\Framework\Serialize\SerializerInterface
40+
* @var SerializerInterface
4041
*/
4142
private $serializer;
4243

44+
/**
45+
* @var ResolverInterface
46+
*/
47+
private $localeResolver;
48+
4349
/**
4450
* Construct
4551
*
46-
* @param \Magento\Directory\Model\CountryFactory $countryFactory
47-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
48-
* @param \Magento\Framework\App\Cache\Type\Config $configCacheType
52+
* @param CountryFactory $countryFactory
53+
* @param StoreManagerInterface $storeManager
54+
* @param Config $configCacheType
55+
* @param ResolverInterface $localeResolver
56+
* @param SerializerInterface $serializer
4957
*/
5058
public function __construct(
51-
\Magento\Directory\Model\CountryFactory $countryFactory,
52-
\Magento\Store\Model\StoreManagerInterface $storeManager,
53-
\Magento\Framework\App\Cache\Type\Config $configCacheType
59+
CountryFactory $countryFactory,
60+
StoreManagerInterface $storeManager,
61+
Config $configCacheType,
62+
ResolverInterface $localeResolver,
63+
SerializerInterface $serializer
5464
) {
5565
$this->_countryFactory = $countryFactory;
5666
$this->_storeManager = $storeManager;
5767
$this->_configCacheType = $configCacheType;
68+
$this->localeResolver = $localeResolver;
69+
$this->serializer = $serializer;
5870
}
5971

6072
/**
@@ -64,32 +76,20 @@ public function __construct(
6476
*/
6577
public function getAllOptions()
6678
{
67-
$cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $this->_storeManager->getStore()->getCode();
79+
$storeCode = $this->_storeManager->getStore()->getCode();
80+
$locale = $this->localeResolver->getLocale();
81+
82+
$cacheKey = 'COUNTRYOFMANUFACTURE_SELECT_STORE_' . $storeCode . '_LOCALE_' . $locale;
6883
if ($cache = $this->_configCacheType->load($cacheKey)) {
69-
$options = $this->getSerializer()->unserialize($cache);
84+
$options = $this->serializer->unserialize($cache);
7085
} else {
7186
/** @var \Magento\Directory\Model\Country $country */
7287
$country = $this->_countryFactory->create();
7388
/** @var \Magento\Directory\Model\ResourceModel\Country\Collection $collection */
7489
$collection = $country->getResourceCollection();
7590
$options = $collection->load()->toOptionArray();
76-
$this->_configCacheType->save($this->getSerializer()->serialize($options), $cacheKey);
91+
$this->_configCacheType->save($this->serializer->serialize($options), $cacheKey);
7792
}
7893
return $options;
7994
}
80-
81-
/**
82-
* Get serializer
83-
*
84-
* @return \Magento\Framework\Serialize\SerializerInterface
85-
* @deprecated 102.0.0
86-
*/
87-
private function getSerializer()
88-
{
89-
if ($this->serializer === null) {
90-
$this->serializer = \Magento\Framework\App\ObjectManager::getInstance()
91-
->get(\Magento\Framework\Serialize\SerializerInterface::class);
92-
}
93-
return $this->serializer;
94-
}
9595
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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\Test\Fixture;
9+
10+
use Magento\Catalog\Model\Category\Attribute;
11+
use Magento\Eav\Api\AttributeRepositoryInterface;
12+
use Magento\Eav\Model\AttributeFactory;
13+
use Magento\Eav\Model\ResourceModel\Entity\Attribute as ResourceModelAttribute;
14+
use Magento\Framework\DataObject;
15+
use Magento\TestFramework\Fixture\Api\DataMerger;
16+
use Magento\TestFramework\Fixture\Data\ProcessorInterface;
17+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
18+
19+
class CategoryAttribute implements RevertibleDataFixtureInterface
20+
{
21+
private const DEFAULT_DATA = [
22+
'is_wysiwyg_enabled' => false,
23+
'is_html_allowed_on_front' => true,
24+
'used_for_sort_by' => false,
25+
'is_filterable' => false,
26+
'is_filterable_in_search' => false,
27+
'is_used_in_grid' => true,
28+
'is_visible_in_grid' => true,
29+
'is_filterable_in_grid' => true,
30+
'position' => 0,
31+
'is_searchable' => '0',
32+
'is_visible_in_advanced_search' => '0',
33+
'is_comparable' => '0',
34+
'is_used_for_promo_rules' => '0',
35+
'is_visible_on_front' => '0',
36+
'used_in_product_listing' => '0',
37+
'is_visible' => true,
38+
'scope' => 'store',
39+
'attribute_code' => 'category_attribute%uniqid%',
40+
'frontend_input' => 'text',
41+
'entity_type_id' => '3',
42+
'is_required' => false,
43+
'is_user_defined' => true,
44+
'default_frontend_label' => 'Category Attribute%uniqid%',
45+
'backend_type' => 'varchar',
46+
'is_unique' => '0',
47+
'apply_to' => [],
48+
];
49+
50+
/**
51+
* @var DataMerger
52+
*/
53+
private DataMerger $dataMerger;
54+
55+
/**
56+
* @var ProcessorInterface
57+
*/
58+
private ProcessorInterface $processor;
59+
60+
/**
61+
* @var AttributeFactory
62+
*/
63+
private AttributeFactory $attributeFactory;
64+
65+
/**
66+
* @var ResourceModelAttribute
67+
*/
68+
private ResourceModelAttribute $resourceModelAttribute;
69+
70+
/**
71+
* @var AttributeRepositoryInterface
72+
*/
73+
private AttributeRepositoryInterface $attributeRepository;
74+
75+
/**
76+
* @param DataMerger $dataMerger
77+
* @param ProcessorInterface $processor
78+
* @param AttributeRepositoryInterface $attributeRepository
79+
* @param AttributeFactory $attributeFactory
80+
* @param ResourceModelAttribute $resourceModelAttribute
81+
*/
82+
public function __construct(
83+
DataMerger $dataMerger,
84+
ProcessorInterface $processor,
85+
AttributeRepositoryInterface $attributeRepository,
86+
AttributeFactory $attributeFactory,
87+
ResourceModelAttribute $resourceModelAttribute
88+
) {
89+
$this->dataMerger = $dataMerger;
90+
$this->processor = $processor;
91+
$this->attributeFactory = $attributeFactory;
92+
$this->resourceModelAttribute = $resourceModelAttribute;
93+
$this->attributeRepository = $attributeRepository;
94+
}
95+
96+
/**
97+
* @inheritdoc
98+
*/
99+
public function apply(array $data = []): ?DataObject
100+
{
101+
/** @var Attribute $attr */
102+
$attr = $this->attributeFactory->createAttribute(Attribute::class, self::DEFAULT_DATA);
103+
$mergedData = $this->processor->process($this, $this->dataMerger->merge(self::DEFAULT_DATA, $data));
104+
$attr->setData($mergedData);
105+
$this->resourceModelAttribute->save($attr);
106+
return $attr;
107+
}
108+
109+
/**
110+
* @inheritdoc
111+
*/
112+
public function revert(DataObject $data): void
113+
{
114+
$this->attributeRepository->deleteById($data['attribute_id']);
115+
}
116+
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Source/CountryofmanufactureTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
use Magento\Catalog\Model\Product\Attribute\Source\Countryofmanufacture;
1111
use Magento\Framework\App\Cache\Type\Config;
12+
use Magento\Framework\Locale\ResolverInterface;
1213
use Magento\Framework\Serialize\SerializerInterface;
1314
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1415
use Magento\Store\Model\Store;
@@ -46,17 +47,24 @@ class CountryofmanufactureTest extends TestCase
4647
*/
4748
private $serializerMock;
4849

50+
/**
51+
* @var ResolverInterface
52+
*/
53+
private $localeResolverMock;
54+
4955
protected function setUp(): void
5056
{
5157
$this->storeManagerMock = $this->getMockForAbstractClass(StoreManagerInterface::class);
5258
$this->storeMock = $this->createMock(Store::class);
5359
$this->cacheConfig = $this->createMock(Config::class);
60+
$this->localeResolverMock = $this->getMockForAbstractClass(ResolverInterface::class);
5461
$this->objectManagerHelper = new ObjectManager($this);
5562
$this->countryOfManufacture = $this->objectManagerHelper->getObject(
5663
Countryofmanufacture::class,
5764
[
5865
'storeManager' => $this->storeManagerMock,
5966
'configCacheType' => $this->cacheConfig,
67+
'localeResolver' => $this->localeResolverMock,
6068
]
6169
);
6270

@@ -80,9 +88,10 @@ public function testGetAllOptions($cachedDataSrl, $cachedDataUnsrl)
8088
{
8189
$this->storeMock->expects($this->once())->method('getCode')->willReturn('store_code');
8290
$this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($this->storeMock);
91+
$this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn('en_US');
8392
$this->cacheConfig->expects($this->once())
8493
->method('load')
85-
->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code'))
94+
->with($this->equalTo('COUNTRYOFMANUFACTURE_SELECT_STORE_store_code_LOCALE_en_US'))
8695
->willReturn($cachedDataSrl);
8796
$this->serializerMock->expects($this->once())
8897
->method('unserialize')
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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\CatalogGraphQl\Model\Output;
9+
10+
use Magento\Catalog\Model\Entity\Attribute;
11+
use Magento\Eav\Api\Data\AttributeInterface;
12+
use Magento\EavGraphQl\Model\Output\GetAttributeDataInterface;
13+
use Magento\Framework\Exception\LocalizedException;
14+
use Magento\Framework\Exception\NoSuchEntityException;
15+
16+
/**
17+
* Format attributes metadata for GraphQL output
18+
*/
19+
class AttributeMetadata implements GetAttributeDataInterface
20+
{
21+
/**
22+
* @var string
23+
*/
24+
private string $entityType;
25+
26+
/**
27+
* @param string $entityType
28+
*/
29+
public function __construct(string $entityType)
30+
{
31+
$this->entityType = $entityType;
32+
}
33+
34+
/**
35+
* Retrieve formatted attribute data
36+
*
37+
* @param Attribute $attribute
38+
* @param string $entityType
39+
* @param int $storeId
40+
* @return array
41+
* @throws LocalizedException
42+
* @throws NoSuchEntityException
43+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
44+
*/
45+
public function execute(
46+
AttributeInterface $attribute,
47+
string $entityType,
48+
int $storeId
49+
): array {
50+
if ($entityType !== $this->entityType) {
51+
return [];
52+
}
53+
54+
$metadata = [
55+
'is_searchable' => $attribute->getIsSearchable() === "1",
56+
'is_filterable' => $attribute->getIsFilterable() === "1",
57+
'is_comparable' => $attribute->getIsComparable() === "1",
58+
'is_html_allowed_on_front' => $attribute->getIsHtmlAllowedOnFront() === "1",
59+
'is_used_for_price_rules' => $attribute->getIsUsedForPriceRules() === "1",
60+
'is_filterable_in_search' => $attribute->getIsFilterableInSearch() === "1",
61+
'used_in_product_listing' => $attribute->getUsedInProductListing() === "1",
62+
'is_wysiwyg_enabled' => $attribute->getIsWysiwygEnabled() === "1",
63+
'is_used_for_promo_rules' => $attribute->getIsUsedForPromoRules() === "1",
64+
'apply_to' => null,
65+
];
66+
67+
if (!empty($attribute->getApplyTo())) {
68+
$metadata['apply_to'] = array_map('strtoupper', $attribute->getApplyTo());
69+
}
70+
71+
return $metadata;
72+
}
73+
}

0 commit comments

Comments
 (0)