I have Magento2 with 2 stores in that i need to deselect use default
for all products specific stores.
can anyone help me?
USE DEFAULT
price checkbox became unselected in case product has overwritten price for specific website.
You can overwrite price only in case Price has Website scope
Stores > Configuration > Catalog > Catalog > Price > Catalog Price Scope = Website
Method 1. To overwrite prices for all products for specific website you can use Mass Attribute Update on product grid page. BUT in this case you can specify only one price for all selected products.
Method 2. Use SQL query to copy default prices to selected website. It works for me.
CHANGE WEBSITE CODE FIRST! code = 'website_2'
INSERT INTO `catalog_product_entity_decimal`(attribute_id, store_id, entity_id, `value`)
SELECT attribute_id, store.store_id, entity_id, `value`
FROM catalog_product_entity_decimal pt
LEFT JOIN store ON website_id = ( SELECT store_website.website_id FROM store_website WHERE `code` = 'website_2')
WHERE attribute_id IN (
SELECT attribute_id FROM eav_attribute WHERE attribute_code IN ('price')
)
AND pt.store_id = 0 AND pt.entity_id IN ( SELECT product_id FROM catalog_product_website WHERE catalog_product_website.website_id = store.website_id)
ON DUPLICATE KEY UPDATE attribute_id = pt.attribute_id, store_id = store.store_id, entity_id = pt.entity_id, value=pt.`value`;
BE CAREFUL WITH SQL. TEST IT FIRST ON DEVELOP INSTANCE.
I got It through test.php I was done
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->setStoreId(2)->load(2041);
$product->setData('name', "WSH12-31-Red bottom");
$product->save();