Skip to content

Instantly share code, notes, and snippets.

@magefast
Created November 29, 2022 10:56
Show Gist options
  • Save magefast/17e161c28e59195ac7b1f4c2d6b80366 to your computer and use it in GitHub Desktop.
Save magefast/17e161c28e59195ac7b1f4c2d6b80366 to your computer and use it in GitHub Desktop.

Revisions

  1. magefast created this gist Nov 29, 2022.
    41 changes: 41 additions & 0 deletions export-csv-product-data.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,41 @@
    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    ini_set('max_execution_time', 1000);
    require_once dirname(__FILE__) . './../app/Mage.php';

    Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

    $productsCollection = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('sku')
    ->addAttributeToSelect('name')
    ->addAttributeToSelect('shtrikh_kod')
    ->addAttributeToSelect('price');

    $array = [];

    foreach ($productsCollection as $product) {
    $array[] = [
    'sku' => $product->getData('sku'),
    'name' => $product->getData('name'),
    'shtrikh_kod' => $product->getData('shtrikh_kod'),
    'price' => $product->getData('price')
    ];
    }
    unset($productsCollection);

    addToCsv($array);

    die('done');


    function addToCsv($array)
    {
    $class = new Varien_File_Csv();
    $newCsvData = array();
    foreach ($array as $a) {
    $newCsvData[] = $a;
    }
    $class->saveData(Mage::getBaseDir() . DS . 'var' . DS . 'report.csv', $newCsvData);
    unset($class);
    }