I have added a product multiselect attribute with option group values programatically as follows
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'print_and_locations',
[
'group' => 'Custom Configurations',
'type' => 'varchar',
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'frontend' => '',
'label' => 'Print options',
'input' => 'multiselect',
'note' => 'Print options',
'class' => '',
'source' => 'Custom\Attribute\Model\Config\Source\Options',
'global' => 0,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => null,
'searchable' => false,
'filterable' => false,
'comparable' => false,
'visible_on_front' => true,
'used_in_product_listing' => false,
'apply_to' => 'configurable',
'unique' => false,
'option' => [
'values' => [],
]
]
);
This attribute options values contains the option values of two simple dropdown product attribute (ie. print and location ) values.
I am using following code to get the options
<?php
/**
* Copyright © Blackbeard, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Custom\Attribute\Model\Config\Source;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\OptionFactory;
use Magento\Framework\DB\Ddl\Table;
class Options extends \Magento\Eav\Model\Entity\Attribute\Source\AbstractSource
{
/**
* instance of eav attribute config.
* @var \Magento\Eav\Model\Config
*/
public $eavConfig;
public function __construct(
\Magento\Eav\Model\Config $eavConfig
) {
$this->eavConfig = $eavConfig;
}
/**
* Get all options based on print method an locations product attributes
*
* @return array
*/
public function getAllOptions()
{
$finalOption = [];
// get print attribute values
$print_attribute = $this->eavConfig->getAttribute('catalog_product', 'print');
$printOptions = $print_attribute->getSource()->getAllOptions(false);
// get logo location options values
$location_attribute = $this->eavConfig->getAttribute('catalog_product', 'location');
$locationOptions = $location_attribute->getSource()->getAllOptions(false);
if (!empty($printOptions)) {
foreach ($printOptions as $key => $print) {
$locationvalues=[];
if (!empty($locationOptions)) {
foreach ($locationOptions as $key => $location) {
$locationvalues[] = [
'label'=>$location['label'],
'value'=>$print['value'].'|'.$location['value']
];
}
}
$finalOption[] = [
'label'=>$print['label'],
'value'=>$locationvalues
];
}
}
return $finalOption;
}
}
This is working fine.
I am working on prouct import. I am unable to import this attribute ie. print_and_locations attribute. I am adding attribute value in following format
print_and_locations=Group 1/Left Chest|Group 1/Left Sleeve|Group 1/Right Chest|Group 1/Right Sleeve|Group 2/Left Chest|Group 2/Left Sleeve|Group 2/Right Chest|Group 2/Right Sleeve|Group 3/Left Chest|Group 3/Left Sleeve|Group 3/Right Chest|Group 3/Right Sleeve
but during import it shows error like mention below.
PS : row no 38 is configurable product row.
Any help would be appreciated.
Thanks.


