Read magento data products.csv file

This tutorial explains how to read magento data from the CSV file.The following data read the CSV file in an array.

Please also the refer tutorial which explains how to mass import magento products and import tier prices using install script.

/**
 * Get product info from products.csv
 */
function getProducts()
{
    $arrResult = array();
    $file = 'csv/products.csv';
    $handle = fopen($file, "r");
    $headers_products = false;
    if (empty($handle) === false) {
        while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
            if (!$headers_products) {
                $headers_products[] = $data;
            } else {
                $arrResult[] = $data;
            }
        }
        fclose($handle);
    }
    return $arrResult;
}

Share this Tutorial