PHP Classes

How to Update Magento Products Using the Package Useful Magento Scripts: Run product operations in Magento e-commerce sites

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2025-06-12 (1 hour ago) RSS 2.0 feedNot yet rated by the usersTotal: Not yet counted Not yet ranked
Version License PHP version Categories
useful_magento_scrip 1.0BSD License5PHP 5, E-Commerce, Global
Description 

Author

This package can run product operations in Magento e-commerce sites.

It provides several scripts that can perform several types of operations with products managed by Magento.

Currently, it provides scripts that can:

- Alter prices and quantities of products from a list read from a CSV file

- Update the status of orders marked as shipped

- Assign customers to orders

- Assign products to specific categories

- Disable products by SKU

- Get the available payment methods and codes

- Set the attributes of products

- Set the quantities of products by SKUs

- Update products by SKU

- Update order status

- Assign properties of Websites

Picture of Victor Andeloci
Name: Victor Andeloci <contact>
Classes: 9 packages by
Country: Brazil Brazil
Age: 26
All time rank: 4363353 in Brazil Brazil
Week rank: 195 Up14 in Brazil Brazil Up
Innovation award
Innovation award
Nominee: 6x

Instructions

Please read this document to learn how to update Magento products in an e-commerce site.

Example

<?php

try {
   
$file = __DIR__ . '/products.csv';

   
/** @var Varien_File_Csv $products */
   
$products = new Varien_File_Csv();
   
$products->setDelimiter(';');
   
$productsRows = $products->getData($file);

   
/** @var Mage_Catalog_Model_Product $productModel */
   
$productModel = Mage::getModel('catalog/product');
   
array_shift($productsRows);

   
$errors = [];

    foreach (
$productsRows as $product) {
        try {
           
$id = $productModel->getIdBySku(trim($product[0]));
           
$productModel->load($id);
            if (
$productModel->getId()) {
               
$productModel->setPrice(round(str_replace(',', '.', str_replace('.', '', $product[2])), 4));
               
$productModel->save();
            }
           
$productModel->clearInstance();
        } catch (
Exception $e) {
           
$errors[] = [
               
'message' => $e->getMessage(),
               
'product' => $product
           
];
        }
    }
} catch (
Exception $e) {
   
$this->log($e);
}

if (!empty(
$errors)) {
   
$this->log($errors);
}


Details

useful_magento_scripts

Useful scripts to import/export/assign things in Magento

About

I've used and tested this in Magento 1.9. Take care.

I've not created all of this just by myself. These scripts were created based on old scripts provided by rafaldimas and questions, like following: * https://stackoverflow.com/questions/28350783/how-to-replace-the-sku-number-for-5000-products-in-magento

Usage

Alter order status with comment

  1. Put your order ids in the respective array:
$ordersIds = array(
    '1',
    '2',
);

  1. Then, add the status slug and comment:
$order->addStatusToHistory('complete_shipped', 'Status comment');

  1. Access YOUR_SITE.XYZ/alter-status-add-comment.php

Update SKU (Old SKU to new SKU) by import

  1. Use the <code>sku2sku.csv</code> model. * First column for your old SKUs * Second column for your new SKUs
  2. Upload the .csv file to <code>/var/export</code> directory
  3. Upload the script file <code>updateskus.php</code> to your root directory
  4. Access YOUR_SITE.XYZ/updateskus.php

Assign category ids to product mass

  1. Use the <code>category_assign.csv</code> model. * First column for your SKUs
  2. Upload the .csv file to <code>/var/export</code> directory
  3. Upload the script file <code>category_assign.php</code> to your root directory
  4. Put the category ids in the respective array in <code>category_assign.php</code>:
$categories = array(2, 136, 470);

  1. Access YOUR_SITE.XYZ/category_assign.php

Assign Websites ids to product mass

  1. Use the <code>website_assign.csv</code> model. * First column for your SKUs
  2. Upload the .csv file to <code>/var/export</code> directory
  3. Upload the script file <code>website_assign.php</code> to your root directory
  4. Put the website ids in the respective array in <code>website_assign.php</code>:
$websites = array(1, 2);

  1. Access YOUR_SITE.XYZ/website_assign.php

Get payment methods codes from store

  1. Change the $storeId in <code>get_payment_methods_codes.php</code> tou YOUR store id:
$storeId = 1;

  1. Upload the script file <code>get_payment_methods_codes.php</code> to your root directory
  2. Access YOUR_SITE.XYZ/get_payment_methods_codes.php

Disable products by SKU in ALL store views

  1. Use the <code>disable_products_by_sku.csv</code> model. * First column for your SKUs
  2. Upload the .csv file to <code>/var/export</code> directory
  3. Upload the script file <code>disable_products_by_sku.php</code> to your root directory
  4. Access YOUR_SITE.XYZ/disable_products_by_sku.php

Set attribute value by attributte name for ALL PRODUCTS

  1. Use the <code>set_attributes.csv</code> model. * First column for your attribute names * Second column form their values
  2. Upload the .csv file to <code>/var/export</code> directory
  3. Upload the script file <code>set_attributes.php</code> to your root directory
  4. Access YOUR_SITE.XYZ/set_attributes.php

Change status of orders between dates

  1. Upload the script file <code>update_orders_status.php</code> to your root directory
  2. Set your date interval:
    $from = new DateTime('2020-01-01 00:00:00');
    $from = $from->format('Y-m-d H:i:s');
    
    

$to = new DateTime('2020-12-22 23:59:9'); $to = $to->format('Y-m-d H:i:s');


3. Define your current order status for search:

->addFieldToFilter('status', 'complete_shipped')


4. Define the final status:

$order->addStatusToHistory('complete', 'Status manually updated on ' . date("d - m - Y") . '.');


5. Access YOUR_SITE.XYZ/update_orders_status.php

  Files folder image Files (19)  
File Role Description
Accessible without login Plain text file alter-price-products.php Example Example script
Accessible without login Plain text file alter-qty-products.php Example Example script
Accessible without login Plain text file alter-status-add-comment.php Example Example script
Accessible without login Plain text file assing-customer-to-order.php Example Example script
Accessible without login Plain text file category_assign.csv Data Auxiliary data
Accessible without login Plain text file category_assign.php Example Example script
Accessible without login Plain text file disable_products_by_sku.csv Data Auxiliary data
Accessible without login Plain text file disable_products_by_sku.php Example Example script
Accessible without login Plain text file get_payment_methods_codes.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file set_attributes.csv Data Auxiliary data
Accessible without login Plain text file set_attributes.php Example Example script
Accessible without login Plain text file set_qtd_by_sku.csv Data Auxiliary data
Accessible without login Plain text file set_qtd_by_sku.php Example Example script
Accessible without login Plain text file sku2sku.csv Data Auxiliary data
Accessible without login Plain text file updateskus.php Example Example script
Accessible without login Plain text file update_orders_status.php Example Example script
Accessible without login Plain text file website_assign.csv Data Auxiliary data
Accessible without login Plain text file website_assign.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads  
 100%
Total:0
This week:0