Jump to content

[SCRIPT]Export Catalog Product to MSExcel


Recommended Posts

<?php
include(dirname(__FILE__).'/config/config.inc.php');
include(dirname(__FILE__).'/init.php');



//define date for title: EDIT this to create the time-format you need
$now_date = date('m-d-Y H:i');
//define title for .doc or .xls file: EDIT this if you want
$title = "Data Katalog xxxxxx tanggal $now_date";

$file_type = "vnd.ms-excel";
$file_ending = "xls";

//header info for browser: determines file type ('.doc' or '.xls')
header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=katalog.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");

echo ("$title\n");
echo ("ID\tNama Barang\tVarian\tHarga\tBerat\tReference\tEAN13\tJumlah Stok\n");

$rq = Product::getProducts($cookie->id_lang, 0, 0, 'id_product', 'ASC', false, true);

if (is_array($rq))
{
   foreach($rq AS $j => $product){

       $sep = "\t";
       /* Build attributes combinaisons */
       $prod = new Product($product['id_product'], $full = false, $cookie->id_lang);
       $combinaisons = $prod->getAttributeCombinaisons($cookie->id_lang);

       $groups = array();
       if (!$combinaisons){

           $schema_insert = "";
           $schema_insert .= $product['id_product'].$sep;
           $schema_insert .= $product['name'].$sep;
           $schema_insert .= $sep;
           $schema_insert .= ($currency->format == 1 ? $currency->sign.' ' : '').Product::getPriceStatic($product['id_product'], $usetax = true, $combinaison['id_product_attribute'], $decimals = 2, $divisor = NULL, $only_reduc = false, $usereduc = true, $quantity = 1, $forceAssociatedTax = true).($currency->format == 2 ? ' '.$currency->sign : '').$sep;
           $schema_insert .= $product['weight'].Configuration::get('PS_WEIGHT_UNIT').$sep;
           $schema_insert .= $sep;
           $schema_insert .= $sep;
           $schema_insert .= $product['quantity'].$sep;
           $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
           print(trim($schema_insert));
           print "\n";    
       }
       if (is_array($combinaisons))
       {
           $combArray = array();    
           foreach ($combinaisons AS $k => $combinaison)
           {
               $combArray[$combinaison['id_product_attribute']]['wholesale_price'] = $combinaison['wholesale_price'];
               $combArray[$combinaison['id_product_attribute']]['price'] = Product::getPriceStatic($product['id_product'], $usetax = true, $combinaison['id_product_attribute'], $decimals = 2, $divisor = NULL, $only_reduc = false, $usereduc = true, $quantity = 1, $forceAssociatedTax = true);//$combinaison['price'];
               $combArray[$combinaison['id_product_attribute']]['weight'] = $combinaison['weight'];
               $combArray[$combinaison['id_product_attribute']]['reference'] = $combinaison['reference'];
               $combArray[$combinaison['id_product_attribute']]['supplier_reference'] = $combinaison['supplier_reference'];
               $combArray[$combinaison['id_product_attribute']]['ean13'] = $combinaison['ean13'];
               $combArray[$combinaison['id_product_attribute']]['location'] = $combinaison['location'];
               $combArray[$combinaison['id_product_attribute']]['quantity'] = $combinaison['quantity'];
               $combArray[$combinaison['id_product_attribute']]['default_on'] = $combinaison['default_on'];
               $combArray[$combinaison['id_product_attribute']]['ecotax'] = $combinaison['ecotax'];
               $combArray[$combinaison['id_product_attribute']]['attributes'][] = array($combinaison['group_name'], $combinaison['attribute_name'], $combinaison['id_attribute']);
               if ($combinaison['is_color_group'])
                   $groups[$combinaison['id_attribute_group']] = $combinaison['group_name'];
           }
       }

       $irow = 0;
       if (isset($combArray)){
           foreach ($combArray AS $id_product_attribute => $product_attribute)
           {
               $schema_insert = "";
               $list = '';
               $jsList = '';
               foreach ($product_attribute['attributes'] AS $attribute)
               {
                   $list .= addslashes(htmlspecialchars($attribute[0])).' - '.addslashes(htmlspecialchars($attribute[1])).', ';
                   $jsList .= '\''.addslashes(htmlspecialchars($attribute[0])).' : '.addslashes(htmlspecialchars($attribute[1])).'\', \''.$attribute[2].'\', ';
               }
               $list = rtrim($list, ', ');
               $jsList = rtrim($jsList, ', ');


               $schema_insert .= $product['id_product'].$sep;
               $schema_insert .= $product['name'].$sep;
               $schema_insert .= stripslashes($list).$sep;
               $schema_insert .= ($currency->format == 1 ? $currency->sign.' ' : '').$product_attribute['price'].($currency->format == 2 ? ' '.$currency->sign : '').$sep;
               $schema_insert .= $product_attribute['weight'].Configuration::get('PS_WEIGHT_UNIT').$sep;
               $schema_insert .= $product_attribute['reference'].$sep;
               $schema_insert .= $product_attribute['ean13'].$sep;
               $schema_insert .= $product_attribute['quantity'].$sep;
               $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
               print(trim($schema_insert));
               print "\n";
           }
       }

   }
}

Link to comment
Share on other sites

Ada beberapa orang yg lebih nyaman liat2 katalog secara offline daripada ngeklik2 di prestashop kita, jadi sy buat script yg export catalog product prestashop ke file excel. Sementara ini gambar product gk bisa dimasukin ke file excelnya, sy baru mau buat export catalog product yg bisa muncul gambarnya tapi ke file PDF, yg sudah ada librarynya di prestashop, krn klo export gambar ke file excel keknya hrus nambah library di prestashopny.
Save script php di atas di /public_html, kemudian buat link ke file tsb
Selamat mencoba :lol:

Link to comment
Share on other sites

You just have to make a new .php file with this code, upload on your site and call it with yourshop.com/exportfile.php, a xls file will be generated.

I have a problem with french caracters in xls file : Capacité - 16Go, Couleur - Bleu

Another problem

I have no reference for products with no combinaisons

Link to comment
Share on other sites

  • 1 month later...

Hi,
this is almost the export function what I'm looking for a long time now!!!!

BUT, I also need the utf8 version and e characteres.

And I have problems with the content of the "Reference" column...
Before the export the product reference is "02-0001"
After the export the product reference is "01.02.01" ? why?

What do I need to add to this code to get also the following values for each product?

- the product-URL
- the product-Image

Please somebody help!
This is a great export function and the best thing is - even product variants are included..

Thanks a lot
Rgds
dmsman

Link to comment
Share on other sites

  • 4 weeks later...

Is somebody working on the integration of:

- the PRODUCT URL
- the PRODUCT IMAGE
- the PRODUCT Short Description
- the PRODUCT Long Description
This would be great then the export function is in my opinion complete...

Thanks a lot

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...
  • 1 month later...

Hi,

I wanted to add the friendly url. it is called url rewrited on the import page under tools but in the database it looks like the field is called link_rewrited

I tried adding this line to the bottom section of the php but it didn't add the url to the xls file:

$schema_insert .= $product['link_rewrite'].$sep;



I put it right below this line:

$schema_insert .= $product['name'].$sep;



this LOOKED like the right place. the section up above involves products with attributes which I don't have/use.

any help would be appreciated. thank you for this module.

Link to comment
Share on other sites

  • 3 months later...
  • 3 weeks later...
  • 10 months later...
×
×
  • Create New...