Jump to content

Some problems with product export xml php script


Recommended Posts

Hello everyone!

Ok, here i have a script thats exports prestashop products in xml file:

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

$tags = array(
 'name' => 'name',
 'link' => 'link',
 'price_inc' => 'price',
 'imageUrl' => 'image',
 'ean' => 'ean',
 'categoryName' => 'category_full',
 'subCategoryName' => 'subCategory',
);

function my_strip_tags($t)
{
 $t = preg_replace('/</',' <',$t);
 $t = preg_replace('/>/','> ',$t);
 $t = preg_replace('/[\n\r\t]/',' ',$t);
 $t = preg_replace('/  /',' ',$t);
 return strip_tags($t);
}

function print_field($k, $v)
{
 global $tags;
 if (isset($tags[$k])) {
   $k = $tags[$k];
   $v = htmlspecialchars($v, ENT_NOQUOTES, "UTF-8");
   print "    <$k>$v</$k>\n";
 }
}

header("Content-Type:text/xml; charset=utf-8");
print '<?xml version="1.0" encoding="UTF-8"?>';
print "<root>\n";
$configuration = Configuration::getMultiple(array(
 'PS_LANG_DEFAULT',
 'PS_SHIPPING_FREE_PRICE',
 'PS_SHIPPING_HANDLING',
 'PS_SHIPPING_METHOD',
 'PS_SHIPPING_FREE_WEIGHT',
 'PS_CARRIER_DEFAULT'));
$id_lang = intval($configuration['PS_LANG_DEFAULT']);
$id_zone = intval($defaultCountry->id_zone);
$link = new Link();
$id_carrier = $configuration['PS_CARRIER_DEFAULT'];
$carrier = new Carrier(intval($id_carrier));
$carrierTax = 0;
if ($carrier->id_tax) {
 $tax = new Tax(intval($carrier->id_tax));
 if (Validate::isLoadedObject($tax) AND Tax::zoneHasTax(intval($tax->id), intval($id_zone)) AND !Tax::excludeTaxeOption())
   $carrierTax = $tax->rate;
}
$passwd = Tools::getValue('passwd');
$categories = Category::getCategories($id_lang, true, false);
$manufacturers = Manufacturer::getManufacturers(false, $id_lang);
if ($passwd == $confPasswd) {
 $products = Product::getProducts($id_lang, 0, 0, 'price', 'ASC', false, true);
}
else {
 $products = array();
}
$manMap =array();
foreach ($manufacturers as $manufacturer) {
 $manMap[$manufacturer['id_manufacturer']] = $manufacturer;
}
$catMap =array();
foreach ($categories as $category) {
 $catMap[$category['id_category']] = $category;
}
foreach ($products as $product){
   $product['link'] = $link->getProductLink($product['id_product']);
    $product['price_inc'] = $product['price'] * (1 + $product['tax_rate']/ 100);	 
    $product['price_inc'] = number_format(round($product['price_inc'], 2), 2);
$cover = Product::getCover($product['id_product']);
 $product['imageUrl'] = _PS_BASE_URL_.$link->getImageLink($prodObj->link_rewrite, $product['id_product'].'-'.$cover['id_image'], 'large');

 $product['manufacturerName'] = $manMap[$product['id_manufacturer']]['name'];

 print "  <item>\n";
 foreach ($product as $k => $v) {
   print_field($k, $v);
 }
 $catList = Product::getIndexedCategories($product['id_product']);
 foreach ($catList as $cat) $cat=$catList[0];{
   $catNames = array();
   $catId = $cat['id_category'];
   while ($catId && $catId != 1) {
  array_unshift($catNames, trim($catMap[$catId]['name']));
  $catId = $catMap[$catId]['id_parent'];
   }
   print_field('categoryName', implode(' >> ', $catNames));

    //$result = mysql_query("SELECT * FROM s_category_product WHERE id_category='{$cat['id_category']}'");
    //while($row = mysql_fetch_array($result)) {
		    echo "<category_link>http://www.mypage.lv/category.php?id_category={$cat['id_category']}</category_link>";
    //}
 }
 print "</item>\n";
}
print "</root>\n";

 

And the xml file looks so:

<?xml version="1.0" encoding="utf-8"?>
<root>
 <item>
   <name>Stereo austiņas ar mikrofonu</name>
   <link>http://www.mypage.lv/product.php?id_product=755</link>
   <price>4.50</price>
   <image>http://www.mypage.lv/img/p/755-882-large.jpg</image>
   <category_full>Datoru aksesuari >> Austinas</category_full>
   <category_link>http://www.mypage.lv/category.php?id_category=128</category_link>
 </item>
......

 

All is ok, but there is one problem, when i have a sale or promo product with lowered price, the script shows anyway the deafault price. Lets say, i have a product on shop with sale price 2.99$, but old price is 5.00$, the script exports the old/default price 5.00$ not actual sale price 2.99$. How to fix this problem, what i must add to the php script to solve that??? And how to make cron job for this script? I want that irt updates 3 times in every Day??

Hope that here is some one that have a solution????

Link to comment
Share on other sites

  • 2 months later...

bump !

 

I would really want to know this also.

Could perhaps some of the smart folks look into this?

 

1. Changing the script to export "on sale" "reduced price" prices when there are some.

2. What to do, to make it auto export the file every 3 hours.

 

This is needed for a Product price compare website, that has 500+ e-stores. People type in a product and it shows the cheapest price from all stores!

 

Please help with this.

Link to comment
Share on other sites

  • 5 months later...
  • 3 weeks later...
  • 1 month later...
  • 3 years later...
×
×
  • Create New...