Wednesday 21 March 2012

How to import custom options through CSV file

http://www.magentocommerce.com/boards/viewthread/67259/

Follow the instructions in the above link page, download the import.zip folder and place the files in the respective magento folders.

Create a new profile in system->import/export->Dataflow-Advanced Profiles, copy and paste the xml in the new profile.

Create a csv file var->import as options.csv.

Example csv format is

“sku”,"option_title”,"input_type”,"required”,"sort_order”,"row_title”,"row_price”,"row_price_type”,"row_sku”,"row_sort_order"
“AAA”,"A”,"drop_down”,0,0,"A1”,10,"Fixed",12343,1
“AAA”,"A”,"drop_down”,0,0,"A2”,10,"Fixed",12343,1
“AAA”,"A”,"drop_down”,0,0,"A3”,10,"Fixed",12343,1
“BBB”,"C”,"drop_down”,0,50,"B1”,10,"Fixed",12343,1
“AAA”,"B”,"drop_down”,1,10,"A4”,1,"Fixed",98765,2
“CCC”,"D”,"drop_down”,0,25,"C5”,50,"percent",1232123,5

How to import Up sell and Cros sell Products through CSV file in magento

Go to the below link and download the module through magento connect manager

http://www.magentocommerce.com/magento-connect/itib-mass-import-product-relations-upsell-and-cross-sell.html


Follow the instructions in the page

xml file for the given module is

<action type="dataflow/convert_adapter_io" method="load">
<var 
name="type">file</var>
<var 
name="path">var/import</var>
<var 
name="filename"><![CDATA[product_relations.csv]]></var>
<var 
name="format"><![CDATA[csv]]></var>
</
action>

<
action type="dataflow/convert_parser_csv" method="parse">
<var 
name="delimiter"><![CDATA[,]]></var>
<var 
name="enclose"><![CDATA["]]></var>
<var name="
fieldnames">true</var>
<var name="
store"><![CDATA[0]]></var>
<var name="
number_of_records">1</var>
<var name="
decimal_separator"><![CDATA[.]]></var>
<var name="
adapter">Itib_MassImportProductRelations/Convert_Adapter_Productimport</var>
<var name="
method">parse</var>
</action>
 
 
Sample csv format is 
 
link function,sku1,sku2,link type
assign,A,D,related  

Tuesday 20 March 2012

How to download image from a source

<?php
$file 
'monkey.gif';

if (
file_exists($file)) {
    
header('Content-Description: File Transfer');
    
header('Content-Type: application/octet-stream');
    
header('Content-Disposition: attachment; filename='.basename($file));
    
header('Content-Transfer-Encoding: binary');
    
header('Expires: 0');
    
header('Cache-Control: must-revalidate');
    
header('Pragma: public');
    
header('Content-Length: ' filesize($file));
    
ob_clean();
    
flush();
    
readfile($file);
    exit;
}
?>
Create a php file and place the image in the same directory.

Monday 19 March 2012

Simple way to Overcome IE 9 problem in magento

<meta http-equiv="X-UA-Compatible" content="IE=8" />
<meta http-equiv="X-UA-Compatible" content="IE=7" /> 
 
 
Getting this tag into your document’s <head/> element is the quickest way 
to solve any problems you have with IE9.

Wednesday 14 March 2012

simple way to upload magento product in csv file via coding

<?php
ini_set("max_execution_time",0);
ini_set('memory_limit', '2048M');
include_once("app/Mage.php");
Mage::app();
umask(0);
echo "<table>\n";
$row = 0;
$handle = fopen("1.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) {

       

        //print_r($data);


//        echo "<pre>";
//print_r($data);
//exit;


    if(count($data) == 0){
            //maill
           
    }else{
           
            $newproduct = Mage::getModel('catalog/product');
            $productId = $newproduct -> getIdBySku($data[0]);       
            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->setCarat($data[3]);
        $newproduct->setColor($data[4]);
        $newproduct->setCalarity($data[5]);
        $newproduct->setCut_grade($data[6]);
        $newproduct->setCertificate($data[9]);
        $newproduct->setDepth($data[10]);
        $newproduct->setTable($data[11]);
        $newproduct->setWeight($data[8]);
        $newproduct->setGirdle($data[12]);
        $newproduct->setCulet($data[13]);
        $newproduct->setPolish($data[14]);
        $newproduct->setSymmetry($data[15]);
        $newproduct->setFlour($data[16]);
        $newproduct->setMeasurement($data[17]);
        $newproduct->setCert($data[20]);
        $newproduct->setCountry($data[26]);
        $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 '.' (' .$data[3]. ''.'- CARAT '.') '.$data[2]. ' - shape'. '  diamonds');
        $newproduct->setCategoryIds(array(2,48)); // array of categories it will relate to
        $newproduct->setDescription('ATLANTA DIAMOND');
        $newproduct->setShortDescription('ATLANTA DIAMOND');
        $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());
    }
/*//re-index the index management via coding
$process = Mage::getModel('index/process')->load($i);
    $process->reindexAll();*/

}


}}
else{ echo "PLEASE INSERT CSV FILE"; }
fclose($handle);
echo "</tbody>\n</table>";

?>

Sunday 4 March 2012

Insert csv file in phpmyadmin

<?php

// Connecting To database

mysql_connect("localhost", "root", "root");
$result = mysql_select_db("sales_diamond");




// Readiong CSV File
$row=1;
$arrResult = array();
$handle = fopen("5-usa.csv", "r");  // CSV FILE
if( $handle ) {
while (($data = fgetcsv($handle,1000, ",",'"')) !== FALSE) { // terminated by ;
   
$arrResult[] = $data;


}


$query='CREATE TABLE IF NOT EXISTS `product_info` (
  `id` int(5) NOT NULL AUTO_INCREMENT,
  `'.$arrResult[0][0].'` varchar(50),
  `'.$arrResult[0][2].'` varchar(50),
  `'.$arrResult[0][3].'` varchar(50),
  `'.$arrResult[0][4].'` varchar(50),
  `'.$arrResult[0][5].'` varchar(50),
  `'.$arrResult[0][6].'` varchar(50),
  `'.$arrResult[0][7].'` varchar(50),
  `'.$arrResult[0][9].'` varchar(50),
  `'.$arrResult[0][10].'` varchar(50),
  `'.$arrResult[0][11].'` varchar(50),
  `'.$arrResult[0][12].'`  varchar(50),
  `'.$arrResult[0][13].'` varchar(50),
  `'.$arrResult[0][14].'` varchar(50),
  `'.$arrResult[0][15].'` varchar(50),
  `'.$arrResult[0][16].'` varchar(50),
  `'.$arrResult[0][17].'` varchar(50),
  `'.$arrResult[0][20].'` varchar(50),
  `'.$arrResult[0][21].'` varchar(50),
  `'.$arrResult[0][24].'` varchar(50),
`'.$arrResult[0][25].'` varchar(50),
`'.$arrResult[0][26].'` varchar(50),
`'.$arrResult[0][27].'` varchar(50),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
';

$res=mysql_query($query);


if($res)
{

$insQuery='';

for($r=1;$r<count($arrResult);$r++)
{
   
    $insQuery ='INSERT INTO `product_info`(`id`,`Lot #`,`Shape`,`Carat`,`Color`, `Clarity`,`Cut Grade`,`Price`,`Cert`,`Depth`,`Table`,`Girdle`,`Culet`,`Polish`, `Sym`,`Fluor`, `Meas`,`Cert #`, `Stock #`,`City`,`State`,`Country`, `Image`) VALUES
              (NULL,"'.$arrResult[$r][0].'","'.$arrResult[$r][2].'",
              "'.$arrResult[$r][3].'","'.$arrResult[$r][4].'","'.$arrResult[$r][5].'",
              "'.$arrResult[$r][6].'","'.$arrResult[$r][7].'","'.$arrResult[$r][9].'",
              "'.$arrResult[$r][10].'","'.$arrResult[$r][11].'","'.$arrResult[$r][12].'","'.$arrResult[$r][13].'","'.$arrResult[$r][14].'","'.$arrResult[$r][15].'","'.$arrResult[$r][16].'","'.$arrResult[$r][17].'","'.$arrResult[$r][20].'","'.$arrResult[$r][21].'","'.$arrResult[$r][24].'","'.$arrResult[$r][25].'","'.$arrResult[$r][26].'","'.$arrResult[$r][27].'")';
  
    


mysql_query($insQuery) or die(mysql_error());
 

echo "Record Added".$r."<br>";     
}

}




echo "Record Added";

//print_r($arrResult);







fclose($handle);
}



?>

Magento products insert via php file

1. copy the following coding  and save in new file stored in magento-> product_import_manually.php
2.and run in 127.0.0.1/magento/product_import_manually.php


<?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>";

?>

 

Thursday 1 March 2012

INSERT PRODUCT MANUALLY IN MAGENTO


 1. copy the following coding and insert  the coding any module page and run the module page the product inserted manually .




$attributeSetId = 4;

    //$newproduct = Mage::getModel('catalog/product');
    $newproduct = new Mage_Catalog_Model_Product();

    $newproduct->setTypeId('simple');
    $newproduct->setWeight(100);      
    $newproduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
    $newproduct->setStatus(1);
    $newproduct->setSku('123456');
    $newproduct->setShape(0.12);
    $newproduct->setSeller('jaga2');
    $newproduct->setCalarity('10');
    $newproduct->setCutgrade('10');
    $newproduct->setPolish('10');
    $newproduct->setSymmetry('10');
    $newproduct->setFluorescence('10');
    $newproduct->setMeasurements('10');
    $newproduct->setLab('0');
    $newproduct->setFluorescence('10');
    $newproduct->setFluorescence('10');
measurements

    $newproduct->setColor('Red');
    $newproduct->setTaxClassId(0);
    $newproduct->setWebsiteIDs(array(1));
    $newproduct->setStoreIDs(array(1));
    $newproduct->setStockData(array(
        'is_in_stock' => 1,
        'qty' => 1000000000000,
        'manage_stock' => 1
    ));

    $newproduct->setAttributeSetId(4);
    $newproduct->setName('Test_4_');
    $newproduct->setCategoryIds(array(2,3)); // array of categories it will relate to

    $newproduct->setDescription('producLongDescription');
    $newproduct->setShortDescription('producescription');
    $newproduct->setPrice(10000000000000000);

    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());
    }



           

Add new page in magento for insert csv file (insert product)

<?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>";

?>


TRUNCATE all products in magento

TRUNCATE all products in magento


  1. TRUNCATE TABLE `catalog_product_bundle_option`;
  2. TRUNCATE TABLE `catalog_product_bundle_option_value`;
  3. TRUNCATE TABLE `catalog_product_bundle_selection`;
  4. TRUNCATE TABLE `catalog_product_entity_datetime`;
  5. TRUNCATE TABLE `catalog_product_entity_decimal`;
  6. TRUNCATE TABLE `catalog_product_entity_gallery`;
  7. TRUNCATE TABLE `catalog_product_entity_int`;
  8. TRUNCATE TABLE `catalog_product_entity_media_gallery`;
  9. TRUNCATE TABLE `catalog_product_entity_media_gallery_value`;
  10. TRUNCATE TABLE `catalog_product_entity_text`;
  11. TRUNCATE TABLE `catalog_product_entity_tier_price`;
  12. TRUNCATE TABLE `catalog_product_entity_varchar`;
  13. TRUNCATE TABLE `catalog_product_link`;
  14. TRUNCATE TABLE `catalog_product_link_attribute`;
  15. TRUNCATE TABLE `catalog_product_link_attribute_decimal`;
  16. TRUNCATE TABLE `catalog_product_link_attribute_int`;
  17. TRUNCATE TABLE `catalog_product_link_attribute_varchar`;
  18. TRUNCATE TABLE `catalog_product_link_type`;
  19. TRUNCATE TABLE `catalog_product_option`;
  20. TRUNCATE TABLE `catalog_product_option_price`;
  21. TRUNCATE TABLE `catalog_product_option_title`;
  22. TRUNCATE TABLE `catalog_product_option_type_price`;
  23. TRUNCATE TABLE `catalog_product_option_type_title`;
  24. TRUNCATE TABLE `catalog_product_option_type_value`;
  25. TRUNCATE TABLE `catalog_product_super_attribute`;
  26. TRUNCATE TABLE `catalog_product_super_attribute_label`;
  27. TRUNCATE TABLE `catalog_product_super_attribute_pricing`;
  28. TRUNCATE TABLE `catalog_product_super_link`;
  29. TRUNCATE TABLE `catalog_product_enabled_index`;
  30. TRUNCATE TABLE `catalog_product_website`;
  31. TRUNCATE TABLE `catalog_product_entity`;
  32.  
  33. TRUNCATE TABLE `cataloginventory_stock`;
  34. TRUNCATE TABLE `cataloginventory_stock_item`;
  35. TRUNCATE TABLE `cataloginventory_stock_status`;
  36.  
  37. INSERT  INTO `catalog_product_link_type`(`link_type_id`,`code`) VALUES (1,'relation'),(2,'bundle'),(3,'super'),(4,'up_sell'),(5,'cross_sell');
  38. INSERT  INTO `catalog_product_link_attribute`(`product_link_attribute_id`,`link_type_id`,`product_link_attribute_code`,`data_type`) VALUES (1,2,'qty','decimal'),(2,1,'position','int'),(3,4,'position','int'),(4,5,'position','int'),(6,1,'qty','decimal'),(7,3,'position','int'),(8,3,'qty','decimal');
  39. INSERT  INTO `cataloginventory_stock`(`stock_id`,`stock_name`) VALUES (1,'Default');
     
     ---------------------------------------------------------------------------------------------------------------------------------------
     
     TRUNCATE all categories in magneto
     
     
    1. TRUNCATE TABLE `catalog_category_entity`;
    2. TRUNCATE TABLE `catalog_category_entity_datetime`;
    3. TRUNCATE TABLE `catalog_category_entity_decimal`;
    4. TRUNCATE TABLE `catalog_category_entity_int`;
    5. TRUNCATE TABLE `catalog_category_entity_text`;
    6. TRUNCATE TABLE `catalog_category_entity_varchar`;
    7. TRUNCATE TABLE `catalog_category_product`;
    8. TRUNCATE TABLE `catalog_category_product_index`;
    9.  
    10. INSERT  INTO `catalog_category_entity`(`entity_id`,`entity_type_id`,`attribute_set_id`,`parent_id`,`created_at`,`updated_at`,`path`,`POSITION`,`level`,`children_count`) VALUES (1,3,0,0,'0000-00-00 00:00:00','2009-02-20 00:25:34','1',1,0,1),(2,3,3,0,'2009-02-20 00:25:34','2009-02-20 00:25:34','1/2',1,1,0);
    11. INSERT  INTO `catalog_category_entity_int`(`value_id`,`entity_type_id`,`attribute_id`,`store_id`,`entity_id`,`value`) VALUES (1,3,32,0,2,1),(2,3,32,1,2,1);
    12. INSERT  INTO `catalog_category_entity_varchar`(`value_id`,`entity_type_id`,`attribute_id`
     
     
     
    -------------------------------------------------------------------------------------------------------------------------------------------------------
     
     TRUNCATE all customers in magento


    1. TRUNCATE TABLE `customer_address_entity`;
    2. TRUNCATE TABLE `customer_address_entity_datetime`;
    3. TRUNCATE TABLE `customer_address_entity_decimal`;
    4. TRUNCATE TABLE `customer_address_entity_int`;
    5. TRUNCATE TABLE `customer_address_entity_text`;
    6. TRUNCATE TABLE `customer_address_entity_varchar`;
    7. TRUNCATE TABLE `customer_entity`;
    8. TRUNCATE TABLE `customer_entity_datetime`;
    9. TRUNCATE TABLE `customer_entity_decimal`;
    10. TRUNCATE TABLE `customer_entity_int`;
    11. TRUNCATE TABLE `customer_entity_text`;
    12. TRUNCATE TABLE `customer_entity_varchar`;