1

I create a product custom attribute programatically. The scope was WEBSITE. But now I just realised that this attribute must have the scope as STORE, because I need different values according to the store view.

I changed the scope in backend, clean the cache, and when I went to edit the product, the scope was correct [STORE]. Then I change store, view so I can insert the value for the store view and the scope changed to [WEBSITE].

I went back and the scope was wrong again [WEBSITE].

I went again to the attribute (Stores > Attributes > Product), choose my attribute, and the attribute had the right scope. I didn't change anything, only save the attribute again and clean the cache. Then I edit the product and the scope was correct [STORE], then I change store view and the scope was wrong again [WEBSITE].

I check database and the attribute is ok.

Did this happening to anyone? Anyone has a clue about this?

Thank you

3 Answers 3

2

You've probably solved your problem, but here is solution for people coming here from google as me. I've managed it by editing it straight in database.

It's not recommended to do such things - the safest way is to delete this attribute and add it again, but sometimes you have no choice. This is e.g. how to change attribute scope to GLOBAL.

UPDATE catalog_eav_attribute SET is_global = 1, apply_to = 'simple,virtual,configurable' WHERE attribute_id = YOUR_ATTRIBUTE_ID;

And then refresh cache.

0

Try to run this command:

bin/magento indexer:reindex

bin/magento setup:static-content:deploy
1
  • I did this already and didn't solve the issue. thank you Commented Dec 14, 2017 at 12:23
0

You can save scope of custom category attribute like this using upgrade schema:

<?php

namespace Vendor\Custom\Setup;

use Magento\Catalog\Model\Category;
use Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface;
use Magento\Framework\DB\Adapter\AdapterInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Eav\Setup\EavSetup;

class UpgradeSchema implements UpgradeSchemaInterface
{
    /**
     * @var EavSetup
     */
    private $eavSetupFactory;

    /**
     * UpgradeSchema constructor.
     * @param EavSetup $eavSetupFactory
     */
    public function __construct(
        EavSetup $eavSetupFactory
    ) {
        $this->eavSetupFactory = $eavSetupFactory;
    }

    public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
    {
        if (version_compare($context->getVersion(), '2.0.5', '<')) {
            $setup->startSetup();
            $this->eavSetupFactory->updateAttribute(
                Category::ENTITY,
                'custom_attribute',
                'is_global',
                ScopedAttributeInterface::SCOPE_STORE,
                null
            );
            $setup->endSetup();
        }
    }
}

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.