0

I'm using magento EE 1.14.2.1.I have about 50k products in databases.I just want some useful advice about updating products.

As I mentioned in title , in everyday I have about 5k product need to be update stock and price.So,should I do it in midnight then reindex them all in one time or turn on the enterprise refresh index cron and update product in many times in a day ( about 100 product per times ).The most important thing which I concerted is the website performance and avoiding MySQL deadlock.

1 Answers1

0

Here's an option for you. I have an import.php script that I use to import or update large numbers of products and their attributes. It will let you either update or create a product based on SKU. You would have to check the constants to see if they match your Magento.

This is a script for Community Edition so you would have to test for Enterprise.

<?php
include_once("app/Mage.php");
Mage::app();
umask(0);
Mage::app()->setCurrentStore(Mage::getModel('core/store')->load(Mage_Core_Model_App::ADMIN_STORE_ID));

$counter = 0;

function GetProduct($sku)
{
    global $counter;
    echo $sku;
    $p = Mage::getModel('catalog/product');
    $productId = $p -> getIdBySku($sku);       
    if($productId)
    {
        echo "!";
        $p -> load( $productId );
    }
    else
    {
        $p->setTypeId('simple');
        $p->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH); 
        $p->setStatus(1);
        $p->setTaxClassId(7);
        $p->setWebsiteIDs(array(1)); 
        $p->setStoreIDs(array(1)); 
        $p->setAttributeSetId(4);
        $p->setSku($sku);
    }
    echo "...";
    $counter++;
    echo " ".$counter;
    return $p;
}

function SaveProduct($p)
{
    try
    {
        if (is_array($errors = $p->validate()))
        {
            $strErrors = array();
            foreach($errors as $code=>$error)
            {
                $strErrors[] = ($error === true)? Mage::helper('catalog')->__('Attribute "%s" is invalid.', $code) : $error;
                echo $strErrors[0];
            }
            $this->_fault('data_invalid', implode("\n", $strErrors));
        }
        $p->save();
        echo "\n";
    }
    catch (Mage_Core_Exception $e)
    {
        $this->_fault('data_invalid', $e->getMessage());
    }
}


$product = GetProduct('SKU01'); $product->setData('upc', '013051388461'); SaveProduct($product); unset($product);
$product = GetProduct('SKU02'); $product->setData('special_price', null); $product->setData('special_from_date', null); SaveProduct($product); unset($product);
$product = GetProduct('SKU03'); $product->setData('cardboard_height_cm', 28.5); $product->setData('cardboard_width_cm', 37); SaveProduct($product); unset($product);


?>

I often get Excel to create the lines like $product = GetProduct('SKU03'); $product->setData('cardboard_height_cm', 28.5); $product->setData('cardboard_width_cm', 37); SaveProduct($product); unset($product); and then just copy and paste into the script. I can edit before running.

This is much faster than importing a CSV and it calls all of the correct observers.

Just run this from a SSH shell.

Enigmativity
  • 113,464
  • 11
  • 89
  • 172