I have created a custom 'Forme' product attribute select type based on option value

class FormeOptions extends AbstractSource
     * Get all options
     * @return array
    public function getAllOptions()
        if (null === $this->_options) {
                ['label' => __('-- Non renseigné --'), 'value' => 0],
                ['label' => __('Coeur 65 à 75g'), 'value' => 1],
                ['label' => __('Grand Galet 75 à 79g'), 'value' => 2],
                ['label' => __('Galet 50g environ'), 'value' => 3],
                ['label' => __('Boule 45 à 55g environ'), 'value' => 4],
                ['label' => __('Boule de 100g environ'), 'value' => 5],
                ['label' => __('Boule de 100g environ'), 'value' => 6],
        return $this->_options;

Created like below

                    'type' => 'varchar',
                    'label' => 'Forme',
                    'input' => 'select',
                    'required' => false,
                    'source' => 'Cpy\Import\Model\Config\FormeOptions',
                    'global' => ScopedAttributeInterface::SCOPE_GLOBAL,
                    'searchable' => false,
                    'filterable' => false,
                    'comparable' => false,
                    'used_in_product_listing' => true,
                    'visible_on_front' => true,
                    'is_used_in_grid' => true,
                    'sort_order' => 52,

In my catalog_product_entity_varchar

The attribute value is properly registered (stored during a custom import)

108417,173,0,5487,Coeur 65 à 75g

But on the product form admin page...it's still shows the field first value and if i go to see in the listing grid the value is empty.



Any idea on what I am missing there ?

EDIT : If i'm submitting from the product admin page, the value is saved and shown properly.

The problem seems to occured only when I try to do this on my import :

            $productChild = $this->productRepository->getById($childProductId);
            switch ($attribute['name']){
                case 'forme':
                    $value = $attribute['value'];
                    var_dump("Written forme :".$productChild->getForme());
                case 'poids':
                    $value = $attribute['value'];
                    var_dump("Written Poids :".$productChild->getPoids());
                default :

1 Answer 1


@claims as I understood you have not saved value for all the products, so whenever you edit any product it will show the first value as '-- Non renseigné --' . And in the grid it will display blank values.

Forex: If you have saved B product value as 'Galet 50g environ' from the import/catalog edit page then it will show 'Galet 50g environ' value for B product in the grid.

The solution is I would suggest set the default value '-- Non renseigné --' for all the products by catalog import and it will display the same for all the products in the grid if you don't want to display the blank value.

Please let me know if this will not help.

  • Thanks for your reply, Please check my edit. In fact, it's working from the edit page...the issue seems to occur only from my custom import script when I set myself the attribute.
    – Claims
    Commented Nov 24, 2021 at 15:56
  • 1
    How do you import the value for this attribute mean are you using 'title' or 'value' (0,1,2,3,4,5)
    – Nits
    Commented Nov 24, 2021 at 16:00
  • On my piece of code the dump from product->getForme return me the expected value of the forme attribute right after the set. It's during the save in the repository that a step might miss...but I can't tell why
    – Claims
    Commented Nov 24, 2021 at 16:02
  • Oh you were right from my admin it stores the index and not the value !
    – Claims
    Commented Nov 24, 2021 at 16:12
  • 1
    Thanks @Claims ....
    – Nits
    Commented Nov 25, 2021 at 4:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.