E
E
Evgen Nova2016-05-11 14:11:25
PHP
Evgen Nova, 2016-05-11 14:11:25

What is the correct way to add additional photos for XML export?

Uploading main photos using the code:

$img_file = ( is_file('./../files/store'.$g_hash[0].'.jpg') ) ? 'files/store'.$g_hash[0].'.jpg' : 'files/store_default.jpg';
$xml->PutTag('picture', array(), $url.'/'.$img_file);

$g_hash[0- id code
output additional photos:
foreach((scandir('files')) as $entry) {
if (strpos($entry, 'store_apendix_big'.$g_hash[0]) === 0) {
$filelist[] = $entry;
}
}
$xml->PutTag('picture', array(), $url.'/'.$filelist);

But when checking the XML file, only one incomplete line is displayed in the column:
<picture>http://site.com/files/</picture>
, but it should be something like
<picture>http://site.com/files/store5437.jpg</picture>
<picture>http://site.com/files/store_apendix_big5437_16537.jpg</picture>
<picture>http://site.com/files/store_apendix_big5437_20407.jpg</picture>

Where can be an error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2016-05-11
@ThunderCat

You can’t understand anything from these snippets, put a wardump through the line, maybe some array is empty, or all empty, or some other data does not get into the script.

E
Evgen Nova, 2016-05-27
@evgen_nova

// Define script folder 
define('FOLDER', './../');

 
// Require classes and includes
require_once('./privat/privat.php');
require_once('./includes/common.php');
require_once('./class/show/class.XML.php');

// Start sessions
shop_session();

// Personal param
$gUser['currency'] = 'UAH'; // EUR | RUR | UAH | USD
$gUser['vendor'] = '80'; // ID характеристики "Производитель" Введите сюда ID своей характеристики (посмотреть в менеджере характеристик)


// Go!
main();


/**
 * Function main
 **/
function main()
{
  global $gData, $gOptions, $gUser, $gTpl, $gStartPoint;

  // Get start point for time
  $gStartPoint = run_time(0);
  
  // Connect to Data 
  $gData = data_connect();	


  $prec = $gOptions['main_prec'];
  $url = rtrim($gOptions['attr_base_url'],'/');
  $curr = $gOptions['main_base_curr'];
  
  // Start XML file
  $xml_file = './tmp/'.md5(session_id()).'.xml';
  $xml = new XML(SHOP_CHARSET, $xml_file, 'Windows-1251', false);
  $xml->PutXML('<!DOCTYPE yml_catalog SYSTEM "shops.dtd">');
  $xml->StartTag('yml_catalog', array('date' 	=> date("Y-m-d H:i", strtotime($gOptions['main_update_time']))));
  $xml->StartTag('shop');

  $xml->PutTag('name', array(), $gOptions['attr_shop_name']);
  $xml->PutTag('company', array(), $gOptions['attr_shop_org']);
  $xml->PutTag('url', array(), $gOptions['attr_shop_url']);
  $xml->StartTag('currencies');
  $xml->PutTag('currency', array('id' => $gUser['currency'], 'rate' => '1'));
  $xml->PutTag('currency', array('id' => 'USD', 'rate' => 'CBRF'));
  $xml->PutTag('currency', array('id' => 'EUR', 'rate' => 'CBRF'));
  $xml->CloseTag('currencies');
  
  // Topics
  $topic = $gData->GetCatForXML();
  $rows = $gData->GetNumRows($topic);
  if ( $rows == 0 )  exit;	
  $xml->StartTag('categories');
  for ( $n = 1; $n <= $rows; $n++ ) 
  {			
    $hash = $gData->FetchRow($topic);
    $xml->PutTag('category', array('id' => $hash[0], 'parentId' => $hash[7]), $hash[1]);
  }	
  $xml->CloseTag('categories');
  
  // Request topic & goods
  $xml->StartTag('offers');
  $gData->DataSeek($topic, 0);
  for ( $n = 1; $n <= $rows; $n++ ) 
  {			
    $hash = $gData->FetchRow($topic);
    $topic_id = $hash[0];

    // Create Goods
    $goods = $gData->GetGoodsForXML($hash[0]);
    $goods_rows = $gData->GetNumRows($goods);
    for ( $i = 1; $i <= $goods_rows; $i++ ) 
    {			
      $g_hash = $gData->FetchRow($goods);
      $price = ( $g_hash[11] > 0 ) ? $g_hash[11] : $g_hash[6];
      $status = ( $g_hash[4] == 0 || $g_hash[4] == 4) ? 'true' : 'false';
      $link = ( strlen($g_hash[15]) > 0 ) ? 'goods_'.urlencode($g_hash[15]).'.htm' : 'goods.php?id='.$g_hash[0];
      $xml->StartTag('offer', array('id'	=> $g_hash[0], 'available' => $status));
      $xml->PutTag('url', array(), $url.'/'.$link);
      $xml->PutTag('price', array(), number_format($price, $prec, "." ,""));
      $xml->PutTag('currencyId', array(), $gUser['currency']);
      $xml->PutTag('categoryId', array(), $topic_id);
      $img_file = ( is_file('./../files/store'.$g_hash[0].'.jpg') ) ? 'files/store'.$g_hash[0].'.jpg' : 'files/store_default.jpg';
      $xml->PutTag('picture', array(), $url.'/'.$img_file);
      $xml->PutTag('name', array(), $g_hash[3]);
      $xml->PutTag('vendor', array(), $gData->GetInfoValueGoods($g_hash[0], $gUser['vendor']));
      $xml->PutTag('vendorCode', array(), $g_hash[1]);
      $xml->PutTag('description', array(), html2text($g_hash[5]));
      $xml->CloseTag('offer');
    }
  }

  $xml->CloseTag('offers');
  
  $xml->CloseTag('shop');
  $xml->CloseTag('yml_catalog');
  $xml->Free();
  
  header('Content-type: text/xml; charset=Windows-1251');
  echo implode('',file($xml_file));
  @unlink($xml_file);
  
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question