Magento 2 – How to get all options of specific attribute type?

In Magento 2 we can get all options of specific EAV entity types attribute. In Magento 2 There are many native EAV Entity Types are available.

You can get all options of specific attribute, Let’s we take a catalog_product Entity Type.
We take Color attribute from Catalog_Product Eav Entity Types. Fetch all the options of color attribute.
Create Block file,

<?php
namespace Rbj\AttributeOption\Block

class Option extends \Magento\Framework\View\Element\Template
{
    public function __construct(
        \Magento\Backend\Block\Template\Context $context,
        \Magento\Eav\Model\Config $eavConfig,
        array $data = []
    ) {
        $this->eavConfig = $eavConfig;
        parent::__construct($context, $data);
    }

    /**
     * Entity Type Catalog
     * Attribute code color
     * @return array
     */
    public function getOptionList()
    {
        $attribute = $this->eavConfig->getAttribute('catalog_product', 'color');
        return $attribute->getSource()->getAllOptions();
    }
}

Call Function From Template file,

$result = $block->getOptionList();
foreach($result as $option) {
    echo $option['value']. '=>' .$option['label'];echo "<br />";
}
echo "<pre>";print_r($result);

The result looks like,

Array
(
    [0] => Array
        (
            [label] =>
            [value] =>
        )

    [1] => Array
        (
            [value] => 49
            [label] => Black
        )

    [2] => Array
        (
            [value] => 50
            [label] => Blue
        )

    [3] => Array
        (
            [value] => 51
            [label] => Brown
        )

    [4] => Array
        (
            [value] => 52
            [label] => Gray
        )
        ....

 

A Complete List of all events in Magento 2

Magento 2 Complete guide to the list of available events that will be used in daily routine as a Magento developer to trigger event-specific tasks at a time of Development.

You can use any required events from the Core module to accomplish your requirements. Define events in the events.xml file, Create an observer.php file to do specific actions for an event.

You can also create your own custom event to accomplish your task by link, Create Custom Events. Continue reading “A Complete List of all events in Magento 2”

How to import configurable product in magento 2 using CSV?

You can import configurable products in Magento 2 by CSV from the admin panel.

Select CSV from the backend,
Go To System -> Data Transfer -> Import
From Entity Type Select Products.
Select Add/Update from Import Behavior settings.

For Import Configurable product using csv, first verify its simple product exist or not in catalog, If child product is not available in catalog, You must create first its child product or Assigned all the child product in CSV before configurable product row.

You are familiar with simple product import. if you don’t know how to import simple product please refer link. How to import simple products in Magento 2?

From simple product to configurable product main difference in column are configurable_variations and configurable_variation_labels
Both column is must required to import configurable product.

configurable_variation_labels => size=Size,color=Color
Super attribute code if the configurable product made with multiple attributes keep value with comma-separated.
Example, where size, color(lowercase) is attributed code and Size and Color(attribute label)

configurable_variations => It contains the pair of all the child product SKU, super attribute value separated with PIPE(|) operator.

Example,
sku=Test_Sku,size=S,color=Red|sku=Test Simple 2,size=M,color=Blue|sku=Test Simple 3,size=L,color=White|sku=Test Simple 4,size=XL,color=Yellow

Where sku=Test_Sku, size=S, color=Red (Test_Sku is the sku and color and size value) for second product we must use pipe(|) operator and set value of second simple product and so on.

Don’t forget to run  indexer command,
php bin/magento indexer:reindex

Download the Configurable Product Import Sheet.

Check Import Additional Attributes Value Using CSV.