Помогите добавить параметр description в выглузку xml

v.kravez

Постоялец
Регистрация
26 Апр 2015
Сообщения
64
Реакции
9
Здравствуйте.
Помогите пожалуйста добавить писание в выгрузку xml.
В коде не очень еще силен.
Есть два файла hotline.php и hotline.xml
Пробовал добавить строку: <description>' . $product['product_desc'] . '</description>
Но результата нет.

PHP:
<?php

define('_JEXEC', 1);
define('DS', DIRECTORY_SEPARATOR);
define('JPATH_BASE', str_replace('market', '', dirname(__FILE__)));
define('ORDER', 'на заказ');
define('SKLAD', 'на складе');

require_once(JPATH_BASE.DS.'includes'.DS.'defines.php');
require_once(JPATH_BASE.DS.'includes'.DS.'framework.php');

$app = JFactory::getApplication('site');
$app->initialise();

require(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
VmConfig::loadConfig();
$confFile = "../configuration.php";
require_once($confFile);
$conf = new JConfig();
$link = mysql_connect($conf->host, $conf->user, $conf->password) or die ("Could not connect to MySQL");
mysql_select_db ($conf->db) or die ("Could not select database");

$db = JFactory::getDBO();
$config = new JConfig();

$query = "SELECT prod.virtuemart_product_id, prod.product_name, prod.slug, price.product_price, price.product_currency, med.file_url, manuf.mf_name, prod_sku.product_sku, prod_sku.product_packaging, cat.category_name,
  MAX(prod_cat.virtuemart_category_id) as caty, cat.slug as slugcat
      FROM rt1fh_virtuemart_products_ru_ru AS prod
      LEFT JOIN rt1fh_virtuemart_product_prices AS price ON price.virtuemart_product_id = prod.virtuemart_product_id
      LEFT JOIN rt1fh_virtuemart_product_medias AS prod_img ON prod.virtuemart_product_id = prod_img.virtuemart_product_id
      LEFT JOIN rt1fh_virtuemart_medias AS med ON prod_img.virtuemart_media_id = med.virtuemart_media_id
      LEFT JOIN rt1fh_virtuemart_product_manufacturers AS prod_manuf ON prod.virtuemart_product_id = prod_manuf.virtuemart_product_id
      LEFT JOIN rt1fh_virtuemart_manufacturers_ru_ru AS manuf ON prod_manuf.virtuemart_manufacturer_id = manuf.virtuemart_manufacturer_id
      LEFT JOIN rt1fh_virtuemart_products AS prod_sku ON prod.virtuemart_product_id = prod_sku.virtuemart_product_id
      LEFT JOIN rt1fh_virtuemart_product_categories AS prod_cat ON prod.virtuemart_product_id = prod_cat.virtuemart_product_id
      LEFT JOIN rt1fh_virtuemart_categories_ru_ru AS cat ON prod_cat.virtuemart_category_id = cat.virtuemart_category_id
      WHERE prod_sku.published = 1 AND price.product_price > 4
      GROUP BY prod.virtuemart_product_id
      ORDER BY prod_sku.product_sku
      ";
mysql_query("SET NAMES 'utf8'");


$db->setQuery($query);
$result = $db->loadAssocList();

$query2 = "SELECT caty.virtuemart_category_id, category_parent_id, category_child_id, category_name  FROM rt1fh_virtuemart_categories AS category
                LEFT JOIN rt1fh_virtuemart_categories_ru_ru AS caty ON category.virtuemart_category_id = caty.virtuemart_category_id
                LEFT JOIN rt1fh_virtuemart_category_categories AS child ON category.virtuemart_category_id = child.category_child_id
                WHERE caty.virtuemart_category_id > 0 AND published = 1
                GROUP BY category.virtuemart_category_id
      ";



$db->setQuery($query2);
$result2 = $db->loadAssocList();
// print_r($result2);



$dom = new domDocument();
$xml='<?xml version="1.0" encoding="UTF-8"?>';
$xml .= '<price date="'.date("Y-m-d H:i").'">
     <firmName>Интернет магазин kgu</firmName>
     <firmId>1234</firmId>
  <categories>';
foreach ($result2 as $caty) {
    if(!empty($caty['virtuemart_category_id'])){
        $str =($caty['category_parent_id'] == 0)?'':'<parent>'.$caty['category_parent_id'].'</parent>';
        $xml  .= '
    <category> <id>'.$caty['virtuemart_category_id'].'</id> '.$str.'<name>'.htmlspecialchars($caty['category_name']).'</name></category>';
    }
}

$xml  .='
</categories>
';

$xml  .='<items>';
foreach ($result as $product) {
    //if(empty($product['caty'])) {


        $xml .= '
    <item> <id>"' . $product['virtuemart_product_id'] . '"</id>
    <categoryId>' . $product['caty'] . '</categoryId>
    <code>' . $product['product_sku'] . '</code>
    <vendor>' . $product['mf_name'] . '</vendor>
    <name>' . $product['product_name'] . '</name>
    <priceRUAH>' . (int)$product['product_price'] . '</priceRUAH>
    <url>http://kgu.com.ua/ru/katalog/' . $product['slug'] . '-detail</url>
    <image>http://kgu.com.ua/' . $product['file_url'] . '</image>
    <stock>В наличии</stock>
    </item>';
  //  }


}
$xml .='
</items>
</price>';
//echo $xml;
$dom->loadXML($xml); // Загружаем в объект domDocument XML-разметку

$dom->save("hotline.xml"); // Сохраняем XML-документ в файл
$dom->load("hotline.xml"); // Выгружаем из файла XML-документ
//echo htmlspecialchars($dom->saveXML()); // Выгрузка в окно браузере XML-документа (уже из файла)

header("Location:http://kgu.com.ua/market/hotline.xml");



?>
 
Назад
Сверху