Skip to content

Commit 95aa1ac

Browse files
authored
Merge pull request #840 from magento-commerce/unable-to-apply-data-patch
Fixed attribute data patch issue
2 parents 910e300 + 90ce4ba commit 95aa1ac

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

app/code/Meta/Catalog/Setup/MetaCatalogAttributes.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ public function getProductAttributes(): array
2020
{
2121
return [
2222
'google_product_category' => [
23-
'group' => 'General',
2423
'type' => 'varchar',
2524
'label' => 'Google Product Category',
2625
'input' => 'select',
@@ -36,7 +35,6 @@ public function getProductAttributes(): array
3635
'visible_on_front' => false
3736
],
3837
'send_to_facebook' => [
39-
'group' => 'General',
4038
'type' => 'int',
4139
'label' => 'Sync to Meta',
4240
'default' => 1,

app/code/Meta/Catalog/Setup/Patch/Data/AddProductAttributes.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
namespace Meta\Catalog\Setup\Patch\Data;
66

77
use Magento\Catalog\Model\Product;
8+
use Magento\Eav\Setup\EavSetup;
89
use Magento\Eav\Setup\EavSetupFactory;
10+
use Magento\Framework\Exception\LocalizedException;
911
use Magento\Framework\Setup\ModuleDataSetupInterface;
1012
use Magento\Framework\Setup\Patch\DataPatchInterface;
1113
use Magento\Framework\Setup\Patch\PatchRevertableInterface;
14+
use Magento\Framework\Validator\ValidateException;
1215
use Meta\Catalog\Setup\MetaCatalogAttributes;
1316

1417
class AddProductAttributes implements DataPatchInterface, PatchRevertableInterface
@@ -68,6 +71,8 @@ public function getAliases(): array
6871
* Create product attributes
6972
*
7073
* @return void
74+
* @throws LocalizedException
75+
* @throws ValidateException
7176
*/
7277
public function apply(): void
7378
{
@@ -78,17 +83,18 @@ public function apply(): void
7883

7984
$entityTypeId = $eavSetup->getEntityTypeId(Product::ENTITY);
8085
$attributeSetId = $eavSetup->getDefaultAttributeSetId($entityTypeId);
86+
$attributeGroupId = $eavSetup->getDefaultAttributeGroupId(Product::ENTITY, $attributeSetId);
8187

8288
foreach ($productAttributes as $attributeCode => $attributeData) {
8389

8490
if (!$eavSetup->getAttributeId(Product::ENTITY, $attributeCode)) {
8591
$eavSetup->addAttribute(Product::ENTITY, $attributeCode, $attributeData);
8692
}
87-
// Assign attributes to default attribute set
93+
// Assign attributes to default attribute set and group
8894
$eavSetup->addAttributeToGroup(
8995
$entityTypeId,
9096
$attributeSetId,
91-
$attributeData['group'],
97+
$attributeGroupId,
9298
$attributeCode
9399
);
94100
}
@@ -108,6 +114,7 @@ public function revert(): void
108114

109115
foreach (array_keys($productAttributes) as $attributeCode) {
110116
$eavSetup->removeAttribute(Product::ENTITY, $attributeCode);
117+
echo 'Removed attribute ' . $attributeCode . PHP_EOL;
111118
}
112119
//delete the patch entry from patch_list table
113120
$this->moduleDataSetup->deleteTableRow('patch_list', 'patch_name', __CLASS__);

0 commit comments

Comments
 (0)