Skip to content

Instantly share code, notes, and snippets.

@ktopouzi
Last active August 26, 2019 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktopouzi/f5dd15eee92ae7687bae0b4a2919d9fc to your computer and use it in GitHub Desktop.
Save ktopouzi/f5dd15eee92ae7687bae0b4a2919d9fc to your computer and use it in GitHub Desktop.
Magento 1 restore default values to product attributes
<?php
/*
* Custom script to reset default value to product atributes.
* Author: Kimon Topouzidis
* Email: kimon.topouzidis@gmail.com
*/
//Grab the Magento instance and get the Admin store.
require_once "app/Mage.php";
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
set_time_limit(0);
//Hardcode for testing
// $product_id = 20667;
// $store_id = 3;
try {
//initialize the collection with the attributes you want to default.
$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect('visibility')
->addAttributeToSelect('status')
->addAttributeToSelect('instagrampro_source')
->addAttributeToSelect('ebizmarts_mark_visited')
->addAttributeToSelect('searchindex_weight')
->addAttributeToSelect('am_shipping_type')
->addAttributeToSelect('tax_class_id')
->addAttributeToSelect('product')
->addAttributeToSelect('stone_details')
->addAttributeToSelect('dimensions')
->addAttributeToSelect('details')
->addAttributeToSelect('country_of_manufacture')
->addAttributeToSelect('inventory_manage_stock')
->addAttributeToSelect('inventory_min_qty')
->addAttributeToSelect('inventory_min_sale_qty')
->addAttributeToSelect('inventory_max_sale_qty')
->addAttributeToSelect('inventory_backorders')
->addAttributeToSelect('inventory_notify_stock_qty')
->addAttributeToSelect('inventory_enable_qty_increments')
->addAttributeToSelect('meta_title')
->addAttributeToSelect('meta_keyword')
->addAttributeToSelect('meta_description');
//create the transaction for performance issues.
$transaction = Mage::getModel('core/resource_transaction');
//loop through the collection
foreach ($collection as $product) {
//Could be getStores -> $stores = Mage::app()->getStores();
//I decided to hardcode it.
for($i = 1; $i < 4; $i++)
{
//load the product, set the data.
$product = Mage::getModel('catalog/product')
->load($product->getID())
->setStoreId($i)
->setData('visibility', false)
->setData('status', false)
->setData('instagrampro_source', false)
->setData('ebizmarts_mark_visited', false)
->setData('searchindex_weight', false)
->setData('am_shipping_type', false)
->setData('tax_class_id', false)
->setData('product', false)
->setData('stone_details', false)
->setData('dimensions', false)
->setData('details', false)
->setData('country_of_manufacture', false)
->setData('inventory_manage_stock', false)
->setData('inventory_min_qty', false)
->setData('inventory_min_sale_qty', false)
->setData('inventory_max_sale_qty', false)
->setData('inventory_backorders', false)
->setData('inventory_notify_stock_qty', false)
->setData('inventory_enable_qty_increments', false)
->setData('meta_title', false)
->setData('meta_keyword', false)
->setData('meta_description', false);
$transaction->addObject($product);
}
echo "Updating " .$product->getName(). " attributes <br>";
$transaction->save();
}
} catch (Exception $ex) {
echo $ex;
}
echo 'Done';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment