Advertisement
Guest User

Untitled

a guest
Jul 13th, 2012
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.21 KB | None | 0 0
  1. <?php
  2.  
  3. require_once('api/Simpla.php');
  4. $simpla = new Simpla();
  5.  
  6. header("Content-type: text/xml; charset=UTF-8");
  7.  
  8. // Заголовок
  9. print
  10. "<?xml version='1.0' encoding='UTF-8'?>
  11. <!DOCTYPE yml_catalog SYSTEM 'shops.dtd'>
  12. <yml_catalog date='".date('Y-m-d H:m')."'>
  13. <shop>
  14. <name>".$simpla->settings->site_name."</name>
  15. <company>".$simpla->settings->company_name."</company>
  16. <url>".$simpla->config->root_url."</url>
  17. ";
  18.  
  19. // Валюты
  20. $currencies = $simpla->money->get_currencies(array('enabled'=>1));
  21. $main_currency = reset($currencies);
  22. print "<currencies>
  23. ";
  24. foreach($currencies as $c)
  25. if($c->enabled)
  26. print "<currency id='".$c->code."' rate='".$c->rate_to/$c->rate_from*$main_currency->rate_from/$main_currency->rate_to."'/>
  27. ";
  28. print "</currencies>
  29. ";
  30.  
  31.  
  32. // Категории
  33. $categories = $simpla->categories->get_categories();
  34. print "<categories>
  35. ";
  36. foreach($categories as $c)
  37. {
  38. print "<category id='$c->id'";
  39. if($c->parent_id>0)
  40.     print " parentId='$c->parent_id'";
  41. print ">".htmlspecialchars($c->name)."</category>
  42. ";
  43. }
  44. print "</categories>
  45. ";
  46.  
  47. // Товары
  48. $simpla->db->query("SET SQL_BIG_SELECTS=1");
  49. // Товары
  50. $simpla->db->query("SELECT v.price, v.id as variant_id, p.name as product_name, v.name as variant_name, v.position as variant_position, p.id as product_id, p.url, p.annotation, pc.category_id, i.filename as image
  51.                     FROM __variants v LEFT JOIN __products p ON v.product_id=p.id
  52.                    
  53.                     LEFT JOIN __products_categories pc ON p.id = pc.product_id AND pc.position=(SELECT MIN(position) FROM __products_categories WHERE product_id=p.id LIMIT 1) 
  54.                     LEFT JOIN __images i ON p.id = i.product_id AND i.position=(SELECT MIN(position) FROM __images WHERE product_id=p.id LIMIT 1)  
  55.                     WHERE p.visible AND (v.stock >0 OR v.stock is NULL) GROUP BY v.id ORDER BY p.id, v.position ");
  56. print "<offers>
  57. ";
  58.  
  59.  
  60. $currency_code = reset($currencies)->code;
  61.  
  62. // В цикле мы используем не results(), a result(), то есть выбираем из базы товары по одному,
  63. // так они нам одновременно не нужны - мы всё равно сразу же отправляем товар на вывод.
  64. // Таким образом используется памяти только под один товар
  65. $prev_product_id = null;
  66. while($p = $simpla->db->result())
  67. {
  68. $variant_url = '';
  69. if ($prev_product_id === $p->product_id)
  70.     $variant_url = '?variant='.$p->variant_id;
  71. $prev_product_id = $p->product_id;
  72.  
  73. $price = round($simpla->money->convert($p->price, $main_currency->id, false),2);
  74. print
  75. "
  76. <offer id='$p->variant_id' available='true'>
  77. <url>".$simpla->config->root_url.'/products/'.$p->url.$variant_url."</url>";
  78. print "
  79. <price>$price</price>
  80. <currencyId>".$currency_code."</currencyId>
  81. <categoryId>".$p->category_id."</categoryId>
  82. ";
  83.  
  84. if($p->image)
  85. print "<picture>".$simpla->design->resize_modifier($p->image, 200, 200)."</picture>
  86. ";
  87.  
  88. print "<name>".htmlspecialchars($p->product_name).($p->variant_name?' '.htmlspecialchars($p->variant_name):'')."</name>
  89. <description>".htmlspecialchars(strip_tags($p->annotation))."</description>
  90. </offer>
  91. ";
  92. }
  93.  
  94. print "</offers>
  95. ";
  96. print "</shop>
  97. </yml_catalog>
  98. ";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement