Skip to content

Instantly share code, notes, and snippets.

@kayintveen
Created November 17, 2015 09:31
Show Gist options
  • Save kayintveen/809a2152dd55423aa53f to your computer and use it in GitHub Desktop.
Save kayintveen/809a2152dd55423aa53f to your computer and use it in GitHub Desktop.
Magento scripts that resets all products "use default values" setting of the admin store view. This script was created for a site that had thousands of products with deselected "Use Default Values" checkboxes in differente store-views
<?php
// Author: @kayintveen
// Credits: Microdesign B.V
// Created November 2015
//=====================================
// Enable Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Init Magento pointing to the Mage.app file
require_once 'app/Mage.php';
// Choose which storeview to select.
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
//Prevent time-outs
set_time_limit(0);
// Function to set values
function useDefaultValueCallback($args){
// change to the ID of your french store view
$specificStoreViewId = 1;
$product = Mage::getModel('catalog/product');
var_dump($args['row']);
$product->setData($args['row']);
$product->setStoreId($specificStoreViewId);
// change according to your needs
$product->setData('url_key', false);
$product->setData('status', false);
$product->setData('visibility', false);
$product->setData('description', false);
$product->setData('short_description', false);
$product->setData('eancode', false);
$product->setData('name', false);
$product->save();
}
// Selecting the products and executing function
$products = Mage::getModel('catalog/product')->getCollection()->addFieldToFilter('entity_id', array('gt' => 1));
Mage::getSingleton('core/resource_iterator')->walk($products->getSelect(), array('useDefaultValueCallback'));
// Done, Cheers!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment