AnswerBun.com

Magento 2: Keep use default value when Updating product attribute programmatically in store view level

I have a dropdown product attribute in store view level that i need to update programmatically for specific store:

I tried to update the product attribute programmatically like this:

// MagentoCatalogModelProductAction $_productAction
$storeId = 3;
$productId = 35;
$this->productAction->updateAttributes(array(
            $productId
        ) , array('test_id'=>30), $storeId);

The product attribute value is updated successfully.

The problem is when i checked the product attribute value to use default value like below:

enter image description here

it will be unchecked if I run those code, even though i set the product attribute value same as the default value

enter image description here

How can i avoid or prevent this and keep value checked, even if i update the value same as the default product attribute value ?

Magento Asked by Tiny Dancer on January 2, 2021

1 Answers

One Answer

This is the expected behavior as you are passing the $storeId=3 so it will save your value on store-level no matter value is the same as the default value. If you don't want that then pass $storeId=0.

Hope this information will help you.

Answered by Rakesh Varma on January 2, 2021

Add your own answers!

Related Questions

How to access other UI components

2  Asked on December 2, 2021

   

Confusion around Salable Quantity

1  Asked on December 2, 2021 by climbah

     

$block->getViewModel() returning NULL

3  Asked on November 30, 2021 by daniel_12

       

Not all errors are displayed in var/log

1  Asked on November 30, 2021 by tarek-fellah

       

Magento2 Installation Error help

1  Asked on November 30, 2021

       

Ask a Question

Get help from others!

© 2022 AnswerBun.com. All rights reserved.