Jump to content

Product export to xml / for websites who search product problem


awfuljka
 Share

Recommended Posts

Dear friend , i have found script that export products to xml file

Here is script :

<?php
include(dirname(__FILE__).'/config/config.inc.php');
require_once(dirname(__FILE__).'/init.php');
// Get data
$number = (intval(Tools::getValue('n')) ? intval(Tools::getValue('n')) : 10000);
$orderByValues = array(0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position');
$orderWayValues = array(0 => 'ASC', 1 => 'DESC');
$orderBy = Tools::strtolower(Tools::getValue('orderby', $orderByValues[intval(Configuration::get('PS_PRODUCTS_ORDER_BY'))]));
$orderWay = Tools::strtoupper(Tools::getValue('orderway', $orderWayValues[intval(Configuration::get('PS_PRODUCTS_ORDER_WAY'))]));
if (!in_array($orderBy, $orderByValues))
$orderBy = $orderByValues[0];
if (!in_array($orderWay, $orderWayValues))
$orderWay = $orderWayValues[0];
//$id_category = (intval(Tools::getValue('id_category')) ? intval(Tools::getValue('id_category')) : 1);
$currency = new Currency(intval($cookie->id_currency));
$affiliate = (Tools::getValue('ac') ? '?ac='.Tools::getValue('ac') : '');
$categTree = Category::getRootCategory()->recurseLiteCategTree(0);
function constructTreeNode($node){
							$ret = ';';
							$ret .= $node['id'].'|'.$node['name'].';';
							if(!empty($node['children']))
							{
															$ret .= ';';
															foreach ($node['children'] AS $child)
																							$ret .= constructTreeNode($child);
															$ret .= ';';
							}
							return $ret;
}
foreach ($categTree['children'] AS $child)
							$ulTree .= constructTreeNode($child);
$tab_cat=explode(';',$ulTree);
foreach ($tab_cat as $id2cat){
$tab_id2cat=explode('|',$id2cat);
if (!empty($tab_id2cat)) $tab_cat_final[$tab_id2cat[0]]=$tab_id2cat[1];
}
header("Content-Type:text/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>'."\n";
?>
<root>
<?php
foreach ($tab_cat_final as $id_category=>$name_category){
$products = Product::getProducts(intval($cookie->id_lang), 0, ($number > 10000 ? 10000 : $number), $orderBy, $orderWay, $id_category, true);
foreach ($products AS $product)
{
// $image = Image::getImages(intval($cookie->id_lang), $product['id_product']);
$lg = Context::getContext()->language->id;
$idcarr = Image::getCover($product['id_product']);
$idcover = $idcarr['id_image'];
$img = Context::getContext()->link->getImageLink($product['link_rewrite'], $idcover, 'large_default');
$prix=Product::getPriceStatic($product['id_product']);
$prs = number_format($prix, 2, '.', '');
$t = Category::getLinkRewrite((int)$product['id_category_default'], $lg);
$qtty = StockAvailable::getQuantityAvailableByProduct($product['id_product'], $product['id_product_attribute']);
if ($product['reduction_percent']>0) $prix_promo=$prix*(1-$product['reduction_percent']/100);else $prix_promo=($prix-$product['reduction_price']);

 echo "<item>\n";
 echo "<name><![CDATA[".$product['name']."]]></name>\n";
 echo "<link><![CDATA[".htmlspecialchars($link->getproductLink($product['id_product'], $product['link_rewrite'], Tools::getValue('id_category'))).$affiliate."]]></link>\n";
 echo "<price>".$prs."</price>\n";
 echo "<image>".$img."</image>\n";
 echo "<category_full><![CDATA[".$name_category."]]></category_full>\n";
 echo "<category_link><![CDATA["._PS_BASE_URL_.__PS_BASE_URI__.$product['id_category_default']."-".$t."]]></category_link>\n";
 echo "<manufacturer><![CDATA[".$product['manufacturer_name']."]]></manufacturer>\n";
 echo "<reference><![CDATA[".$product['id_product']."]]></reference>\n";
 echo "<in_stock>".$qtty."</in_stock>\n";
 echo "<model><![CDATA[".$product['reference']."]]></model>\n";
 echo "</item>\n";
}
}
?>
</root>

Then I run this script in my homepage

Opera and IE give me this error :

 

Ошибка разбора XML

 

Ошибка разбора XML: синтаксическая ошибка (Строка: 3, Символ: 0)

 

Обработать документ как HTML

Ошибка:

unexpected end-of-file

Описание:

http://www.w3.org/TR/REC-xml/

1: <?xml version="1.0" encoding="UTF-8"?>

2: <root>

 

Where is problem ? :(

Share this post


Link to post
Share on other sites

  • 5 weeks later...

Nice script, where did you find it? I would like more info on some issues.

 

On your problem, I didn't have problem with the xml, maybe you have too many products and php runtime restrictions? Try with fewer products for start.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More