Skip to content

Commit 7496778

Browse files
committed
ACP2E-4348: Manage Shopping Cart store scope issues
1 parent 5d8a453 commit 7496778

File tree

5 files changed

+89
-43
lines changed

5 files changed

+89
-43
lines changed

app/code/Magento/Catalog/Test/Fixture/Attribute.php

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
/**
2424
* Product attribute fixture
2525
*
26+
* Usage examples:
27+
*
2628
* 1. Create an attribute with default data
2729
* <pre>
2830
* #[
@@ -35,19 +37,6 @@
3537
* DataFixture(AttributeFixture::class, ['is_filterable' => true], 'attribute')
3638
* ]
3739
* </pre>
38-
* 3. Update an existing attribute
39-
* <pre>
40-
* #[
41-
* DataFixture(
42-
* AttributeFixture::class,
43-
* [
44-
* 'attribute_code' => 'price',
45-
* 'scope' => 'website',
46-
* '_update' => true
47-
* ]
48-
* )
49-
* ]
50-
* </pre>
5140
*/
5241
class Attribute implements RevertibleDataFixtureInterface
5342
{
@@ -124,7 +113,6 @@ public function __construct(
124113
* @param array $data Parameters. Same format as Attribute::DEFAULT_DATA.
125114
*
126115
* Additional fields:
127-
* - `_update`: boolean - whether to update attribute instead of creating a new one
128116
* - `_set_id`: int - attribute set ID to assign the attribute to
129117
* - `_group_id`: int - attribute group ID to assign the attribute to
130118
* - `_sort_order`: int - sort order within the attribute group
@@ -137,13 +125,9 @@ public function apply(array $data = []): ?DataObject
137125
$attributeSetData = $this->prepareAttributeSetData(
138126
array_intersect_key($data, self::DEFAULT_ATTRIBUTE_SET_DATA)
139127
);
140-
if (!empty($data['_update'])) {
141-
$attribute = $this->productAttributeRepository->get($data['attribute_code']);
142-
unset($attributeData['_update'], $attributeData['attribute_code']);
143-
} else {
144-
$attribute = $this->attributeFactory->create();
145-
$attributeData = $this->prepareData($attributeData);
146-
}
128+
129+
$attribute = $this->attributeFactory->create();
130+
$attributeData = $this->prepareData($attributeData);
147131

148132
$this->dataObjectHelper->populateWithArray(
149133
$attribute,
@@ -157,15 +141,12 @@ public function apply(array $data = []): ?DataObject
157141
}
158142
$attribute = $this->productAttributeRepository->save($attribute);
159143

160-
// Do not assign attribute if both set_id and group_id are not provided during update
161-
if (empty($data['_update']) || isset($data['_set_id'], $data['_group_id'])) {
162-
$this->productAttributeManagement->assign(
163-
$attributeSetData['_set_id'],
164-
$attributeSetData['_group_id'],
165-
$attribute->getAttributeCode(),
166-
$attributeSetData['_sort_order']
167-
);
168-
}
144+
$this->productAttributeManagement->assign(
145+
$attributeSetData['_set_id'],
146+
$attributeSetData['_group_id'],
147+
$attribute->getAttributeCode(),
148+
$attributeSetData['_sort_order']
149+
);
169150

170151
return $attribute;
171152
}
@@ -175,9 +156,6 @@ public function apply(array $data = []): ?DataObject
175156
*/
176157
public function revert(DataObject $data): void
177158
{
178-
if (!$data->getIsUserDefined()) {
179-
return;
180-
}
181159
$service = $this->serviceFactory->create(ProductAttributeRepositoryInterface::class, 'deleteById');
182160
$service->execute(
183161
[
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\Catalog\Test\Fixture;
10+
11+
use Magento\Catalog\Api\Data\ProductAttributeInterface;
12+
use Magento\Catalog\Api\ProductAttributeRepositoryInterface;
13+
use Magento\Framework\Api\SearchCriteriaBuilder;
14+
use Magento\Framework\DataObject;
15+
use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface;
16+
17+
/**
18+
* Fixture to change price attribute scope
19+
*
20+
* Usage examples:
21+
*
22+
* 1. Change price scope to website
23+
* <pre>
24+
* #[
25+
* DataFixture(PriceScope::class, ['scope' => ProductAttributeInterface::SCOPE_WEBSITE_TEXT])
26+
* ]
27+
* </pre>
28+
*/
29+
class PriceScope implements RevertibleDataFixtureInterface
30+
{
31+
/**
32+
* @param ProductAttributeRepositoryInterface $productAttributeRepository
33+
* @param SearchCriteriaBuilder $searchCriteriaBuilder
34+
*/
35+
public function __construct(
36+
private readonly ProductAttributeRepositoryInterface $productAttributeRepository,
37+
private readonly SearchCriteriaBuilder $searchCriteriaBuilder
38+
) {
39+
}
40+
41+
/**
42+
* @inheritDoc
43+
*/
44+
public function apply(array $data = []): ?DataObject
45+
{
46+
$this->change($data['scope']);
47+
return null;
48+
}
49+
50+
/**
51+
* @inheritDoc
52+
*/
53+
public function revert(DataObject $data): void
54+
{
55+
$this->change(ProductAttributeInterface::SCOPE_GLOBAL_TEXT);
56+
}
57+
58+
/**
59+
* Change price attributes scope
60+
*
61+
* @param string $scope
62+
* @return void
63+
*/
64+
private function change(string $scope): void
65+
{
66+
$this->searchCriteriaBuilder->addFilter('frontend_input', 'price');
67+
$criteria = $this->searchCriteriaBuilder->create();
68+
foreach ($this->productAttributeRepository->getList($criteria)->getItems() as $priceAttribute) {
69+
$priceAttribute->setScope($scope);
70+
$this->productAttributeRepository->save($priceAttribute);
71+
}
72+
}
73+
}

app/code/Magento/Catalog/Test/Fixture/Product.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
/**
3030
* Product fixture
3131
*
32+
* Usage examples:
33+
*
3234
* 1. Create a product with default data
3335
* <pre>
3436
* #[

app/code/Magento/ConfigurableProduct/Model/Product/Type/Configurable.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ public function getProductByAttributes($attributesInfo, $product)
842842
* @param array $attributesInfo
843843
* @return void
844844
*/
845-
private function addAttributesToFilter($collection, array $attributesInfo): void
845+
private function addAttributesToFilter(Collection $collection, array $attributesInfo): void
846846
{
847847
foreach ($attributesInfo as $attributeId => $attributeValue) {
848848
$collection->addAttributeToFilter($attributeId, $attributeValue);

dev/tests/integration/testsuite/Magento/ConfigurableProduct/Block/Adminhtml/Product/Composite/Fieldset/ConfigurableTest.php

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111
use Magento\Catalog\Api\ProductRepositoryInterface;
12+
use Magento\Catalog\Test\Fixture\PriceScope as PriceScopeFixture;
1213
use Magento\Catalog\Test\Fixture\Product as ProductFixture;
13-
use Magento\Catalog\Test\Fixture\Attribute as AttributeFixture;
1414
use Magento\ConfigurableProduct\Test\Fixture\Attribute as ConfigurableAttributeFixture;
1515
use Magento\ConfigurableProduct\Test\Fixture\Product as ConfigurableProductFixture;
1616
use Magento\Directory\Model\Currency;
@@ -120,14 +120,7 @@ public function testGetJsonConfig(): void
120120
['store_group_id' => '$store_2.id$', 'code' => 'store_view_2_euro'],
121121
as: 'store_view_2'
122122
),
123-
DataFixture(
124-
AttributeFixture::class,
125-
[
126-
'attribute_code' => 'price',
127-
'scope' => 'website',
128-
'_update' => true
129-
]
130-
),
123+
DataFixture(PriceScopeFixture::class, ['scope' => 'website']),
131124
DataFixture(
132125
ProductFixture::class,
133126
[

0 commit comments

Comments
 (0)