Jump to content

[Доработка] Скрипт экспорта товаров в XML


Recommended Posts

Помогите с доработкой скрипта экспорта товаров в XML:

Есть скрипт экспорта товаров xmlexport.php

<?php
include(dirname(__FILE__).'/config/config.inc.php');
require_once(dirname(__FILE__).'/init.php');
$confPasswd = 'ssss';
$tags = array(
 'name' => 'name',
 'url' => 'url',
 'imageUrl' => 'imageUrl',
 'price_inc' => 'price',
 'description_short' => 'description',
 'id_product' => 'id',
 'ean' => 'ean',
 'categoryName' => 'category',
 'subCategoryName' => 'subCategory',
 'shipping_cost' => 'shipping',
 'manufacturerName' => 'manufacturer',
);

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 my_number_format($t)
{
 return number_format($t, 2, '.', '');
}

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"?>'."\n";
print "<products>\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) {
 $prodObj = new Product($product['id_product'], false, $id_lang);
 $product['url'] = $link->getProductLink($prodObj);
 $product['price_exc'] = my_number_format($prodObj->getPrice(false));
 $product['price_inc'] = my_number_format($prodObj->getPrice(true));
 $cover = Product::getCover($product['id_product']);
 $product['imageUrl'] = $link->getImageLink($prodObj->link_rewrite, $product['id_product'].'-'.$cover['id_image'], 'large');
 if (intval($configuration['PS_SHIPPING_METHOD']))
$shipping_cost = $carrier->getDeliveryPriceByWeight($product['weight'], $id_zone);
 else
$shipping_cost = $carrier->getDeliveryPriceByPrice($product['price_inc'], $id_zone);
 $shipping_cost *= 1 + ($carrierTax / 100);
 $shipping_cost += floatval($configuration['PS_SHIPPING_HANDLING']);
 $product['shipping_cost'] = my_number_format($shipping_cost);
 $product['manufacturerName'] = $manMap[$product['id_manufacturer']]['name'];
 $product['description_short'] = my_strip_tags($product['description_short']);
 print "  <product>\n";
 foreach ($product as $k => $v) {
print_field($k, $v);
 }
 $catList = Product::getIndexedCategories($product['id_product']);
 foreach ($catList as $cat) {
if ($cat['id_category'] != 1) {
  if ($catMap[$cat['id_category']]['id_parent'] == 1) {
print_field('categoryName', $catMap[$cat['id_category']]['name']);
  }
  else {
print_field('subCategoryName', $catMap[$cat['id_category']]['name']);
  }
}
 }
 print "  </product>\n";
}
print "</products>\n";
?>

Ложите в корень, вводите http://адрес_сайта/x...php?passwd=ssss

Вывод xml такого вида:

<?xml version="1.0" encoding="UTF-8"?>
<products>
 <product>
<id>502</id>
<description>  Magie Noire - знаменитый классический парфюм с острым древесным ароматом.  Композиция кедра, мускуса, жасмина создает опьяняющую ночную магию прекрасной зрелой женщины.   </description>
<name>Magie Noire</name>
<url>http://parfumeur.com.ua/lancome/502-magie-noire.html</url>
<price>130.00</price>
<imageUrl>http://parfumeur.com.ua/502-546-large/magie-noire.jpg</imageUrl>
<shipping>0.00</shipping>
<manufacturer>LANCOME</manufacturer>
<category>Женская парфюмерия</category>
<subCategory>LANCOME</subCategory>
 </product>
<products>

Задача: как привести вывод XML для каталога магазинов на META.UA формат XML такой:

<?xml version="1.0" encoding="windows-1251"?>
<!DOCTYPE e-shop SYSTEM "http://market.meta.ua/market.dtd">
<e-shop name="Computers LTD">
<categories>
<category id="1">Компьютеры и ПО</category>
<category id="2">Комплектующие к ПК</category>
<category id="3" parent="1">Видео</category>
<category id="4" parent="1">Процессоры</category>
<category id="5" parent="1">HDD</category>
</categories>
<currencies>
<currency  id="UAH" rate="1"/>
<currency  id="USD" rate="5,35"/>
</currencies>
<itemlist>
<item id="25" category="4" priority="20">
 <link img="http://server.dom/dataimg/02-006-000003.gif"
 click="http://server.dom/partners/click/?p=3&p_id=25" />
 <type>Процессор</type>
 <vendor>Intel</vendor>
 <name>Pentium 4 1,8 GHz (FSB 400) BOX</name>
 <price cid="USD">120.00</price>
 <description>Процессор Intel Pentium 4 18 GHz (FSB 400) BOX ...</description>
</item>
</itemlist>
</e-shop>

На сайте META прилагается библиотека для формирования XML прайса - export_price.zip

Но после двух суток танцев с бубном... результатом явилось ничего... Молю о помощи!!!

xmlexport.zip

META_xml_export.zip

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...
×
×
  • Create New...