|
15 | 15 | use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
|
16 | 16 | use Magento\Framework\Api\FilterBuilder;
|
17 | 17 | use Magento\Framework\Api\SearchCriteriaBuilder;
|
| 18 | +use Magento\Store\Model\Store; |
18 | 19 |
|
19 | 20 | /**
|
20 | 21 | * Add data to category entity and populate with default values
|
@@ -68,31 +69,34 @@ public function __construct(
|
68 | 69 | */
|
69 | 70 | public function execute(CategoryInterface $category, array $existingData): void
|
70 | 71 | {
|
71 |
| - $storeId = $existingData['store_id']; |
72 |
| - $overriddenValues = array_filter( |
73 |
| - $category->getData(), |
74 |
| - function ($key) use ($category, $storeId) { |
75 |
| - /** @var Category $category */ |
76 |
| - return $this->scopeOverriddenValue->containsValue( |
77 |
| - CategoryInterface::class, |
78 |
| - $category, |
79 |
| - $key, |
80 |
| - $storeId |
81 |
| - ); |
82 |
| - }, |
83 |
| - ARRAY_FILTER_USE_KEY |
84 |
| - ); |
85 |
| - $defaultValues = array_diff_key($category->getData(), $overriddenValues); |
86 |
| - array_walk( |
87 |
| - $defaultValues, |
88 |
| - function (&$value, $key) { |
89 |
| - $attributes = $this->getAttributes(); |
90 |
| - if (isset($attributes[$key]) && !$attributes[$key]->isStatic()) { |
91 |
| - $value = null; |
| 72 | + $storeId = $existingData['store_id'] ?? Store::DEFAULT_STORE_ID; |
| 73 | + if ((int)$storeId !== Store::DEFAULT_STORE_ID) { |
| 74 | + $overriddenValues = array_filter( |
| 75 | + $category->getData(), |
| 76 | + function ($key) use ($category, $storeId) { |
| 77 | + /** @var Category $category */ |
| 78 | + return $this->scopeOverriddenValue->containsValue( |
| 79 | + CategoryInterface::class, |
| 80 | + $category, |
| 81 | + $key, |
| 82 | + $storeId |
| 83 | + ); |
| 84 | + }, |
| 85 | + ARRAY_FILTER_USE_KEY |
| 86 | + ); |
| 87 | + $defaultValues = array_diff_key($category->getData(), $overriddenValues); |
| 88 | + array_walk( |
| 89 | + $defaultValues, |
| 90 | + function (&$value, $key) { |
| 91 | + $attributes = $this->getAttributes(); |
| 92 | + if (isset($attributes[$key]) && !$attributes[$key]->isStatic()) { |
| 93 | + $value = null; |
| 94 | + } |
92 | 95 | }
|
93 |
| - } |
94 |
| - ); |
95 |
| - $category->addData($defaultValues); |
| 96 | + ); |
| 97 | + $category->addData($defaultValues); |
| 98 | + } |
| 99 | + |
96 | 100 | $category->addData($existingData);
|
97 | 101 | $useDefaultAttributes = array_filter(
|
98 | 102 | $category->getData(),
|
|
0 commit comments