Quantcast
Channel: Webkul Blog
Viewing all articles
Browse latest Browse all 5488

How to check if “Use Default Value” checked for a product attribute value in magento 2

$
0
0

In this blog, I will explain how can you get if an product attribute value is overridden for a store view. Here for example I am checking for Product Name (product_name) attribute and store view with id=1.

public function __construct(
    .....
    \Magento\Catalog\Model\Attribute\ScopeOverriddenValue $scopeOverriddenValue
) {
    .....
    $this->scopeOverriddenValue = $scopeOverriddenValue;
}
 
public function execute()
{
    .....
    $isOverriden = $this->scopeOverriddenValue->containsValue(
        \Magento\Catalog\Api\Data\ProductInterface::class,
        $product,           //Product object
        'product_name',     //Attribute Name
        1                   //Store view Id
    );
}

 

It will result True if the “Use Default Value” is unchecked. So for below it will result,

 

Otherwise it will return False, like below,

 

Feel free to comment if you find any issue.


Viewing all articles
Browse latest Browse all 5488

Trending Articles