Advertisement
Guest User

Untitled

a guest
Oct 18th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.15 KB | None | 0 0
  1. $v = array(
  2. 'supplier_code' => $key,
  3. 'vendor_code' => $key,
  4. 'title' => (string) $xml->Наименование,
  5. 'available' => $available,
  6. 'price' => $this->model->NormalizePrice($price),
  7. 'price_rrp' => $price_rrp,
  8. 'category' => (string) $xml->Сл_КатегорияТовара
  9. );
  10.  
  11. $this->_data['Products'][$this->id_bn][$key] = $v;
  12.  
  13.  
  14.  
  15. return true;
  16. }
  17.  
  18. /**
  19. * Обертка для чтения ХМЛ
  20. * Метод для получения списка товаров имеющегося в наличии
  21. * @param type $reader
  22. */
  23. protected function xmlCurrencies($reader) {
  24. $xml = $reader->expandSimpleXml();
  25. $att = $xml->attributes();
  26.  
  27. $id = (string) $att->id;
  28. $rate = (string) $att->rate;
  29.  
  30.  
  31. $this->_data['Currencies'][$id] = $rate;
  32.  
  33. // [@attributes] => Array
  34. // (
  35. // [id] => GBP
  36. // [rate] => 34.0600
  37. // )
  38.  
  39.  
  40. return true;
  41. }
  42.  
  43. }
  44.  
  45. $loader = new InterSystemsApiLoader($conf, $this->db, $this->model);
  46.  
  47.  
  48. $supplier_id = $conf['supplier_id'];
  49.  
  50. // Bn
  51. $sup_type = 470;
  52. $data = $loader->getPrices(1, $sup_type);
  53. $this->model->importPricesData($data, $sup_type, $supplier_id);
  54.  
  55.  
  56. // Nal
  57. $sup_type = 469;
  58. $data = $loader->getPrices(0, $sup_type);
  59. $this->model->importPricesData($data, $sup_type, $supplier_id);
  60.  
  61. $resp = (string) $loader->getResp();
  62. [root@office suppliers]# clear
  63. [root@office suppliers]# cat load_InterSystems.php
  64. <?php
  65.  
  66. /*
  67. * Загрузка цен + цен БН
  68. */
  69.  
  70. class InterSystemsApiLoader extends Loader {
  71.  
  72. // private $_tmp_file = '/tmp/InterSystems/'; // debug, Сохранять ли файл на хранение
  73.  
  74. /*
  75. * Инициализация
  76. */
  77.  
  78. private function _Init() {
  79. // Обучаем читалку ХМЛ
  80. $this->registerCallback('/Прайс/currencies/currency', array($this, 'xmlCurrencies'));
  81. $this->registerCallback('/Прайс/Номенклатура', array($this, 'xmlProducts'));
  82. }
  83.  
  84. //new function
  85.  
  86. private function _listFiles() {
  87. echo $this->_resp[] = dt() . ' Чтение прайса ' . PHP_EOL;
  88.  
  89. $url = 'http://inter-systems.com.ua/content/price_file/file_exchange/InterSystems.xml';
  90.  
  91. $output = file_get_contents($url);
  92.  
  93. $this->xml($output);
  94. $this->parse();
  95. $this->close();
  96.  
  97. if (isset($this->_tmp_file))
  98. file_put_contents($this->_tmp_file . $this->id_bn, $output);
  99.  
  100. echo $this->_resp[] = dt() . ' Прайс сохранен на диске ' . PHP_EOL;
  101. }
  102.  
  103. /**
  104. * Вернуть цены
  105. * @return type
  106. */
  107. public function getPrices($id_bn, $sup_type) {
  108. $this->id_bn = $id_bn;
  109. echo $this->_resp[] = dt() . ' Обработка цен ' . $sup_type . PHP_EOL;
  110.  
  111. $this->_listFiles();
  112.  
  113. if ($this->_data['items']) {
  114.  
  115. $rate = $this->model->getCurrencyBySupID($this->_conf['suppliers_prices_type_id']);
  116.  
  117. foreach ($this->_data['items'] as $k => $item) {
  118.  
  119. $item['category'] = $this->model->toggleCategory($item['category'], $this->_conf['supplier_id']);
  120.  
  121. if ($rate['is_bn'] == 1)
  122. $item['price_bn'] = $item['price'];
  123. else
  124. $item['price_bn'] = 0;
  125.  
  126. $data[$k][] = $item;
  127. }
  128.  
  129. return $data;
  130. }
  131.  
  132. return $data;
  133. }
  134.  
  135. /**
  136. * Обертка для чтения ХМЛ
  137. * Метод для получения списка товаров имеющегося в наличии
  138. * @param type $reader
  139. */
  140. protected function xmlProducts($reader) {
  141. $xml = $reader->expandSimpleXml();
  142. // $att = $xml->attributes();
  143.  
  144. $key = (string) $xml->Артикул;
  145.  
  146. $price_rrp = 'NULL';
  147. if ($this->id_bn) {
  148. $price = (string) $xml->ДопДанные->Цены->Дилер_грн;
  149. $price_rrp = $this->model->NormalizePrice((string) $xml->ДопДанные->Цены->РЦ);
  150. } else {
  151. $price = (string) $xml->ДопДанные->Цены->Дилер;
  152. $price_rrp = $this->model->NormalizePrice((string) $xml->ДопДанные->Цены->РЦ);
  153. }
  154.  
  155. $available = 0;
  156.  
  157. // Обновляем все кроме, но ставим что не в наличии
  158. if ($this->_conf['status'] == 2)
  159. $available = 0;
  160. else
  161. $available = 1;
  162.  
  163. $v = array(
  164. 'supplier_code' => $key,
  165. 'vendor_code' => $key,
  166. 'title' => (string) $xml->Наименование,
  167. 'available' => $available,
  168. 'price' => $this->model->NormalizePrice($price),
  169. 'price_rrp' => $price_rrp,
  170. 'category' => (string) $xml->Сл_КатегорияТовара
  171. );
  172.  
  173. $this->_data['Products'][$this->id_bn][$key] = $v;
  174.  
  175.  
  176.  
  177. return true;
  178. }
  179.  
  180. /**
  181. * Обертка для чтения ХМЛ
  182. * Метод для получения списка товаров имеющегося в наличии
  183. * @param type $reader
  184. */
  185. protected function xmlCurrencies($reader) {
  186. $xml = $reader->expandSimpleXml();
  187. $att = $xml->attributes();
  188.  
  189. $id = (string) $att->id;
  190. $rate = (string) $att->rate;
  191.  
  192.  
  193. $this->_data['Currencies'][$id] = $rate;
  194.  
  195. // [@attributes] => Array
  196. // (
  197. // [id] => GBP
  198. // [rate] => 34.0600
  199. // )
  200.  
  201.  
  202. return true;
  203. }
  204.  
  205. }
  206.  
  207. $loader = new InterSystemsApiLoader($conf, $this->db, $this->model);
  208.  
  209.  
  210. $supplier_id = $conf['supplier_id'];
  211.  
  212. // Bn
  213. $sup_type = 470;
  214. $data = $loader->getPrices(1, $sup_type);
  215. $this->model->importPricesData($data, $sup_type, $supplier_id);
  216.  
  217.  
  218. // Nal
  219. $sup_type = 469;
  220. $data = $loader->getPrices(0, $sup_type);
  221. $this->model->importPricesData($data, $sup_type, $supplier_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement