<?php
include_once("app/Mage.php");
Mage::app();
umask(0);
echo "<table>\n";
$row = 0;
$handle = fopen("no_id.csv", "r");
if($handle!=0){
$data = fgetcsv($handle, 1000, ",");
for($i=0; $i < count($data); $i++) {
$column[$i] = $data[$i];
}
$count = 0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if($count = 0){
//maill
echo "hai";
exit;
}else{
echo "<pre>";
$newproduct = Mage::getModel('catalog/product');
$productId = $newproduct -> getIdBySku( $data[39] );
if($productId) {
$newproduct -> load( $productId );
}
$newproduct->setTypeId('simple');
$newproduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$newproduct->setStatus(1);
$newproduct->setSku($data[0]);
$newproduct->setShape($data[2]);
$newproduct->setSeller($data[1]);
$newproduct->setWeight($data[3]);
$newproduct->setColor($data[4]);
$newproduct->setTaxClassId(0);
$newproduct->setWebsiteIDs(array(1));
$newproduct->setStoreIDs(array(1));
$newproduct->setStockData(array(
'is_in_stock' => 1,
'qty' =>$data[21] ,
'manage_stock' => 1
));
$newproduct->setAttributeSetId(4);
$newproduct->setName('ATLANTA DIAMOND');
$newproduct->setCategoryIds(array(2,3)); // array of categories it will relate to
$newproduct->setDescription('producLongDescription');
$newproduct->setShortDescription('producescription');
$newproduct->setPrice($data[7]);
try {
if (is_array($errors = $newproduct->validate())) {
$strErrors = array();
foreach($errors as $code=>$error) {
$strErrors[] = ($error === true)? Mage::helper('catalog')->__('Attribute "%s" is invalid.', $code) : $error;
}
$this->_fault('data_invalid', implode("\n", $strErrors));
}
$newproduct->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('data_invalid', $e->getMessage());
}
}
}}
else{ echo "PLEASE INSERT CSV FILE"; }
fclose($handle);
echo "</tbody>\n</table>";
?>
include_once("app/Mage.php");
Mage::app();
umask(0);
echo "<table>\n";
$row = 0;
$handle = fopen("no_id.csv", "r");
if($handle!=0){
$data = fgetcsv($handle, 1000, ",");
for($i=0; $i < count($data); $i++) {
$column[$i] = $data[$i];
}
$count = 0;
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
if($count = 0){
//maill
echo "hai";
exit;
}else{
echo "<pre>";
$newproduct = Mage::getModel('catalog/product');
$productId = $newproduct -> getIdBySku( $data[39] );
if($productId) {
$newproduct -> load( $productId );
}
$newproduct->setTypeId('simple');
$newproduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
$newproduct->setStatus(1);
$newproduct->setSku($data[0]);
$newproduct->setShape($data[2]);
$newproduct->setSeller($data[1]);
$newproduct->setWeight($data[3]);
$newproduct->setColor($data[4]);
$newproduct->setTaxClassId(0);
$newproduct->setWebsiteIDs(array(1));
$newproduct->setStoreIDs(array(1));
$newproduct->setStockData(array(
'is_in_stock' => 1,
'qty' =>$data[21] ,
'manage_stock' => 1
));
$newproduct->setAttributeSetId(4);
$newproduct->setName('ATLANTA DIAMOND');
$newproduct->setCategoryIds(array(2,3)); // array of categories it will relate to
$newproduct->setDescription('producLongDescription');
$newproduct->setShortDescription('producescription');
$newproduct->setPrice($data[7]);
try {
if (is_array($errors = $newproduct->validate())) {
$strErrors = array();
foreach($errors as $code=>$error) {
$strErrors[] = ($error === true)? Mage::helper('catalog')->__('Attribute "%s" is invalid.', $code) : $error;
}
$this->_fault('data_invalid', implode("\n", $strErrors));
}
$newproduct->save();
} catch (Mage_Core_Exception $e) {
$this->_fault('data_invalid', $e->getMessage());
}
}
}}
else{ echo "PLEASE INSERT CSV FILE"; }
fclose($handle);
echo "</tbody>\n</table>";
?>
No comments:
Post a Comment