In this blog, I will explain how can you get if a product attribute value is overridden for a store view. Here for example I am checking for Product Name (name) attribute and store view with id=1.
public function __construct(
.....
\Magento\Catalog\Model\Attribute\ScopeOverriddenValue $scopeOverriddenValue
\Magento\Catalog\Api\ProductRepositoryInterface $productRepository
) {
.....
$this->scopeOverriddenValue = $scopeOverriddenValue;
$this->productRepository = $productRepository;
}
public function execute()
{
.....
$product = $this->productRepository->get('Test Product');
$isOverriden = $this->scopeOverriddenValue->containsValue(
\Magento\Catalog\Api\Data\ProductInterface::class,
$product, //Product object
'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 issues.
Be the first to comment.