php - Prestashop 1.5.4.x: how to get proper category_link, image, price? -
prestashop 1.5.4.x how proper category_link, image, price in code below? print name, link, manufacturer, category_full. script show incorrect format price: 191.26073 instead of 191.26 , 65 instead of 65.00
. images script show incorrect path: http://mysite.x10.mx/img/p/8-27-large.jpg, correct patch need http://mysite.x10.mx/27-thickbox_default/picture.jpg
the full code used:
<?php include(dirname(__file__).'/config/config.inc.php'); require_once(dirname(__file__).'/init.php'); // 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'] $child) $ret .= constructtreenode($child); $ret .= ';'; } return $ret; } foreach ($categtree['children'] $child) $ultree .= constructtreenode($child); $tab_cat=explode(';',$ultree); foreach ($tab_cat $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 $id_category=>$name_category){ $products = product::getproducts(intval($cookie->id_lang), 0, ($number > 10000 ? 10000 : $number), $orderby, $orderway, $id_category, true); foreach ($products $product) { $image = image::getimages(intval($cookie->id_lang), $product['id_product']); $prix=product::getpricestatic($product['id_product']); 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>".$prix."</price>\n"; echo "<image>"._ps_base_url_.__ps_base_uri__."img/p/".$image[0]['id_product']."-".$image[0]['id_image']."-large.jpg</image>\n"; echo "<category_full><![cdata[".$name_category."]]></category_full>\n"; echo "<category_link><![cdata[".htmlspecialchars($link->getcategorylink($category['id_category'], $category['link_rewrite'], tools::getvalue('id_category'))).$affiliate."]]></category_link>\n"; echo "<manufacturer><![cdata[".$product['manufacturer_name']."]]></manufacturer>\n"; echo "<reference><![cdata[".$product['id_product']."]]></reference>\n"; echo "</item>\n"; } } ?> </root>
here's code should be:
$default_currency = new currency(configuration::get('ps_currency_default')); foreach ($tab_cat_final $id_category=>$name_category) { $products = product::getproducts(intval($cookie->id_lang), 0, ($number > 10000 ? 10000 : $number), $orderby, $orderway, $id_category, true); foreach ($products $product) { $price = product::getpricestatic($product['id_product']); if ($product['reduction_percent'] > 0) $prix_promo = $price * (1 - $product['reduction_percent'] / 100); else $prix_promo = ($price-$product['reduction_price']); $id_image = image::getcover($product['id_product']); $image_link = $link->getimagelink($product['link_rewrite'], $id_image, 'large_default'); 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>".tools::displayprice($price, $default_currency)."</price>\n"; echo "<image>".$image_link."</image>\n"; echo "<category_full><![cdata[".$name_category."]]></category_full>\n"; echo "<category_link><![cdata[".htmlspecialchars($link- >getcategorylink($category['id_category'], $category['link_rewrite'], tools::getvalue('id_category'))).$affiliate."]]></category_link>\n"; echo "<manufacturer><![cdata[".$product['manufacturer_name']."]]></manufacturer>\n"; echo "<reference><![cdata[".$product['id_product']."]]></reference>\n"; echo "</item>\n"; } }
here's price right:
$default_currency = new currency(configuration::get('ps_currency_default')); tools::displayprice($prix, $default_currency)
here's image right:
$id_image = image::getcover($product['id_product']); $image_link = $link->getimagelink($product['link_rewrite'], $id_image, 'large_default');
Comments
Post a Comment