Jump to content
php.lv forumi

XML izvade no datubāzes


prieks

Recommended Posts

Laikam cena tiek izvadīta šeit, rinda, kur $product['price']

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

Edited by didje3
Link to comment
Share on other sites

Skripts

<?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.lapa.lv/category.php?id_category={$cat['id_category']}</category_link>";
   	//}
 }
 print "</item>\n";
}
print "</root>\n";

Kur mainīgais nemaz nezināšu!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...