<?php
require_once('../app/Mage.php');
umask(0);
Mage::app('admin');
echo 'Bulk Import Imgaes script runing at '.date("Y-m-d h:i:sa").' <br/>';
try{
$csv = new Varien_File_Csv();
$csvfilepath = '../../../../tmp/importimage.csv';
$imagepath = '../../../../tmp/import/';
$cssfile = fopen($csvfilepath,"r");
$data = $csv->getData($csvfilepath);
//Mage::log('CSV file exsist', null, 'bulkimagesimport.log');
echo 'CSV file exsist <br/>';
$rows = count($data);
for ($j = 1; $j<= $rows; $j++) {
$productSKU = $data[$j][0];
if(!empty($productSKU)){
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$productSKU);
if (!$product){
//Mage::log($productSKU.' SKU doesn`t exsist', null, 'bulkimagesimport.log');
echo $productSKU.' SKU doesn`t exsist <br/>';
}else{
//Mage::log($productSKU.' SKU product loaded', null, 'bulkimagesimport.log');
echo $productSKU.' SKU product loaded <br/>';
$imagesArray = explode('|', $data[$j][1]);
$count = 0;
$mediaAttribute = array (
'image',
'small_image',
'thumbnail',
'reference_image',
'faceimage'
);
foreach ($imagesArray as $image){
$imagefile = $imagepath.trim($image);
if (file_exists($imagefile)) {
if ($count == 0){
$product->addImageToMediaGallery( $imagefile , $mediaAttribute, false, false );
}else{
$product->addImageToMediaGallery( $imagefile , null, false, false );
}
$product->setStoreId(0);
//Mage::log($imagefile.' Image uploaded', null, 'bulkimagesimport.log');
echo $image.' Image uploaded <br/>';
} else {
//Mage::log($imagefile.' Image not found', null, 'bulkimagesimport.log');
echo $image.' Image not found <br/>';
}
$count++;
}
$product->save();
//Mage::log($productSKU.' SKU uploaded successfully', null, 'bulkimagesimport.log');
echo $productSKU.' SKU uploaded successfully <br/>';
}
}
}
fclose($cssfile);
echo 'Uploaded Successfully at '.date("Y-m-d h:i:sa").' <br/>';
} catch (Exception $e){
//Mage::log($e->getMessage(), null, 'bulkimagesimport.log');
echo $e->getMessage();
}
require_once('../app/Mage.php');
umask(0);
Mage::app('admin');
echo 'Bulk Import Imgaes script runing at '.date("Y-m-d h:i:sa").' <br/>';
try{
$csv = new Varien_File_Csv();
$csvfilepath = '../../../../tmp/importimage.csv';
$imagepath = '../../../../tmp/import/';
$cssfile = fopen($csvfilepath,"r");
$data = $csv->getData($csvfilepath);
//Mage::log('CSV file exsist', null, 'bulkimagesimport.log');
echo 'CSV file exsist <br/>';
$rows = count($data);
for ($j = 1; $j<= $rows; $j++) {
$productSKU = $data[$j][0];
if(!empty($productSKU)){
$product = Mage::getModel('catalog/product')->loadByAttribute('sku',$productSKU);
if (!$product){
//Mage::log($productSKU.' SKU doesn`t exsist', null, 'bulkimagesimport.log');
echo $productSKU.' SKU doesn`t exsist <br/>';
}else{
//Mage::log($productSKU.' SKU product loaded', null, 'bulkimagesimport.log');
echo $productSKU.' SKU product loaded <br/>';
$imagesArray = explode('|', $data[$j][1]);
$count = 0;
$mediaAttribute = array (
'image',
'small_image',
'thumbnail',
'reference_image',
'faceimage'
);
foreach ($imagesArray as $image){
$imagefile = $imagepath.trim($image);
if (file_exists($imagefile)) {
if ($count == 0){
$product->addImageToMediaGallery( $imagefile , $mediaAttribute, false, false );
}else{
$product->addImageToMediaGallery( $imagefile , null, false, false );
}
$product->setStoreId(0);
//Mage::log($imagefile.' Image uploaded', null, 'bulkimagesimport.log');
echo $image.' Image uploaded <br/>';
} else {
//Mage::log($imagefile.' Image not found', null, 'bulkimagesimport.log');
echo $image.' Image not found <br/>';
}
$count++;
}
$product->save();
//Mage::log($productSKU.' SKU uploaded successfully', null, 'bulkimagesimport.log');
echo $productSKU.' SKU uploaded successfully <br/>';
}
}
}
fclose($cssfile);
echo 'Uploaded Successfully at '.date("Y-m-d h:i:sa").' <br/>';
} catch (Exception $e){
//Mage::log($e->getMessage(), null, 'bulkimagesimport.log');
echo $e->getMessage();
}
No comments:
Post a Comment