Menu Close
    Hire Us Request Quote Reading List Switch to Dark Mode

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

    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.

    . . .

    Comment

    Add Your Comment

    Be the first to comment.

    Back to Top
    css.php
    Hire Us!
    Brief us about your requirements and we'll get back to you.
    Woo! Hooy!
    We have just recieved your project brief and our expert will contact you shortly.
    Send Again
    Close