I have 20 product attributes. I need to change those attributes' saving scope to "Global".

How can I achieve this?

5 Answers 5


The quick and easiest way to update the scope is with MySQL query (given below).

UPDATE `catalog_eav_attribute` SET `is_global`= 1 WHERE `attribute_id` IN (45,46,47);

Where 45, 46 and 47 is the attribute ids.

You can run below script to update the attributes scope programmaticaly.


use Magento\Framework\App\Bootstrap;
use Magento\Sales\Model\Order;

require __DIR__ . '/app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);

$objectManager = $bootstrap->getObjectManager();

$state = $objectManager->get('Magento\Framework\App\State');

$resource = $objectManager->get('Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection();
$tableName = $resource->getTableName('catalog_eav_attribute');

$value = 1;
$attributeIds = 45,46,47;
$sql = "UPDATE " . $tableName . " SET is_global = ". $value ." WHERE attribute_id IN (". $attributeIds .");

Hope it helps!!!

  • Hi @summit, Thanks for your immediate response. But I need this only for my custom attributes
    – Jaisa
    Apr 28, 2020 at 4:05
  • @Jaisa OK, you can add attribute ids in WHERE condition in the above SQL query to update only the attributes you want. I've updated my code with example.
    – Sumit
    Apr 28, 2020 at 4:12

You can update the product attribute using the UpgradeData script.



namespace VendorName\ModuleName\Setup;

use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

class UpgradeData implements UpgradeDataInterface
    public function __construct(
        EavSetupFactory $eavSetupFactory
        $this->eavSetupFactory = $eavSetupFactory;

    public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
        $eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);

        /* Compate you module version */
        if (version_compare($context->getVersion(), '0.1.1', '<')) {
            $updateAttributes = array('attribute_code_1','attribute_code_2','attribute_code_3','attribute_code_4','attribute_code_5','attribute_code_6');

            foreach ($updateAttributes as $attribute) {
                $eavSetup->updateAttribute(\Magento\Catalog\Model\Product::ENTITY, $attribute, 'is_global', \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL);

Hope this helps!


You can update it using below SQL query :

UPDATE `catalog_eav_attribute` SET `is_global`= 1 WHERE `attribute_id`=45;

For multiple :

UPDATE `catalog_eav_attribute` SET `is_global`= 1 WHERE `attribute_id` IN (45,46,47);

You can set your attribute_id which you want to update.

After execute this commad :

php bin/magento ind:rei
php bin/magento c:c

You can save custom product attributes like this:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();

$product = $objectManager->create('Magento\Catalog\Api\ProductRepositoryInterface;')->load($product_id);



$product->getResource()->saveAttribute($product, $attributeCode);

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


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', '<')) {

Change category_form.xml to include store view to display that in admin interface

         <rule name="required-entry" xsi:type="boolean">false</rule>
    <label translate="true">Exclude from Sitemap</label>
    <scopeLabel>[STORE VIEW]</scopeLabel>

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.