I'm writing cron module to import products (Magento 2). In this module I'm adding attribute, attribute value and assign this new attribute value to product. It sounds easy but new added attributes and it's values are not visible. For example when I add attribute option
$attribute = $this->_eavConfig->getAttribute('catalog_product', $code);
$attributeId = $attribute->getAttributeId();
$option = array();
$option['attribute_id'] = $attributeId;
$option['value'][$attr->value][0] = 'value';
$option['value'][$attr->value][1] = 'value';
$this->_eavSetup->addAttributeOption($option);
and then try to find new added option
$options = $attribute->getSource()->getAllOptions(true);
foreach ($options as $option)
{
if ($option['label'] == 'value') ...//new value missing
}
there is not new option value in $options table. I can get new option id directly from tables eav_attribute_option and eav_attribute_option_value. But It doesn't solve the problem because setting this option id to product wont work. "Product" also doesn't see this new attribute/option value. How can I force my script to refresh new attributes so they can be visible?
$attr->value
be in your code? In the snippet you pasted that is not defined