Skip to content

Product Attributes

Code Slicer edited this page Sep 12, 2022 · 13 revisions

Allows managing the eav attributes related to products. Import it as follows:

private Migration\Facade\ProductAttribute $productAttribute;

public function __construct(
    Migration\Context $context,
    Migration\Facade\ProductAttribute $productAttribute
) {
    parent::__construct($context);
    $this->productAttribute = $productAttribute;
}

Inherit Methods

💡 Tip: The same as Category Attributes applies here, alongside the product exclusive ones listed below.

createDropdown($code, $label, $values, $config = [])

Create a new dropdown attribute. Eg.:

$this->productAttribute->createDropdown('sizes', "Clothes Size", ['P', 'M', 'G']);

assignToAttributeSet($code, $options = [])

Well, it's pretty much what the name implies. Assign to default if no option is supplied. Eg.:

$this->productAttribute->assignToAttributeSet('my_new_attribute', [
    'attribute_set_id' => 1,
    'group_id' => 'General',
    'sort_order' => 30,
]);
Clone this wiki locally