Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $v = array(
- 'supplier_code' => $key,
- 'vendor_code' => $key,
- 'title' => (string) $xml->Наименование,
- 'available' => $available,
- 'price' => $this->model->NormalizePrice($price),
- 'price_rrp' => $price_rrp,
- 'category' => (string) $xml->Сл_КатегорияТовара
- );
- $this->_data['Products'][$this->id_bn][$key] = $v;
- return true;
- }
- /**
- * Обертка для чтения ХМЛ
- * Метод для получения списка товаров имеющегося в наличии
- * @param type $reader
- */
- protected function xmlCurrencies($reader) {
- $xml = $reader->expandSimpleXml();
- $att = $xml->attributes();
- $id = (string) $att->id;
- $rate = (string) $att->rate;
- $this->_data['Currencies'][$id] = $rate;
- // [@attributes] => Array
- // (
- // [id] => GBP
- // [rate] => 34.0600
- // )
- return true;
- }
- }
- $loader = new InterSystemsApiLoader($conf, $this->db, $this->model);
- $supplier_id = $conf['supplier_id'];
- // Bn
- $sup_type = 470;
- $data = $loader->getPrices(1, $sup_type);
- $this->model->importPricesData($data, $sup_type, $supplier_id);
- // Nal
- $sup_type = 469;
- $data = $loader->getPrices(0, $sup_type);
- $this->model->importPricesData($data, $sup_type, $supplier_id);
- $resp = (string) $loader->getResp();
- [root@office suppliers]# clear
- [root@office suppliers]# cat load_InterSystems.php
- <?php
- /*
- * Загрузка цен + цен БН
- */
- class InterSystemsApiLoader extends Loader {
- // private $_tmp_file = '/tmp/InterSystems/'; // debug, Сохранять ли файл на хранение
- /*
- * Инициализация
- */
- private function _Init() {
- // Обучаем читалку ХМЛ
- $this->registerCallback('/Прайс/currencies/currency', array($this, 'xmlCurrencies'));
- $this->registerCallback('/Прайс/Номенклатура', array($this, 'xmlProducts'));
- }
- //new function
- private function _listFiles() {
- echo $this->_resp[] = dt() . ' Чтение прайса ' . PHP_EOL;
- $url = 'http://inter-systems.com.ua/content/price_file/file_exchange/InterSystems.xml';
- $output = file_get_contents($url);
- $this->xml($output);
- $this->parse();
- $this->close();
- if (isset($this->_tmp_file))
- file_put_contents($this->_tmp_file . $this->id_bn, $output);
- echo $this->_resp[] = dt() . ' Прайс сохранен на диске ' . PHP_EOL;
- }
- /**
- * Вернуть цены
- * @return type
- */
- public function getPrices($id_bn, $sup_type) {
- $this->id_bn = $id_bn;
- echo $this->_resp[] = dt() . ' Обработка цен ' . $sup_type . PHP_EOL;
- $this->_listFiles();
- if ($this->_data['items']) {
- $rate = $this->model->getCurrencyBySupID($this->_conf['suppliers_prices_type_id']);
- foreach ($this->_data['items'] as $k => $item) {
- $item['category'] = $this->model->toggleCategory($item['category'], $this->_conf['supplier_id']);
- if ($rate['is_bn'] == 1)
- $item['price_bn'] = $item['price'];
- else
- $item['price_bn'] = 0;
- $data[$k][] = $item;
- }
- return $data;
- }
- return $data;
- }
- /**
- * Обертка для чтения ХМЛ
- * Метод для получения списка товаров имеющегося в наличии
- * @param type $reader
- */
- protected function xmlProducts($reader) {
- $xml = $reader->expandSimpleXml();
- // $att = $xml->attributes();
- $key = (string) $xml->Артикул;
- $price_rrp = 'NULL';
- if ($this->id_bn) {
- $price = (string) $xml->ДопДанные->Цены->Дилер_грн;
- $price_rrp = $this->model->NormalizePrice((string) $xml->ДопДанные->Цены->РЦ);
- } else {
- $price = (string) $xml->ДопДанные->Цены->Дилер;
- $price_rrp = $this->model->NormalizePrice((string) $xml->ДопДанные->Цены->РЦ);
- }
- $available = 0;
- // Обновляем все кроме, но ставим что не в наличии
- if ($this->_conf['status'] == 2)
- $available = 0;
- else
- $available = 1;
- $v = array(
- 'supplier_code' => $key,
- 'vendor_code' => $key,
- 'title' => (string) $xml->Наименование,
- 'available' => $available,
- 'price' => $this->model->NormalizePrice($price),
- 'price_rrp' => $price_rrp,
- 'category' => (string) $xml->Сл_КатегорияТовара
- );
- $this->_data['Products'][$this->id_bn][$key] = $v;
- return true;
- }
- /**
- * Обертка для чтения ХМЛ
- * Метод для получения списка товаров имеющегося в наличии
- * @param type $reader
- */
- protected function xmlCurrencies($reader) {
- $xml = $reader->expandSimpleXml();
- $att = $xml->attributes();
- $id = (string) $att->id;
- $rate = (string) $att->rate;
- $this->_data['Currencies'][$id] = $rate;
- // [@attributes] => Array
- // (
- // [id] => GBP
- // [rate] => 34.0600
- // )
- return true;
- }
- }
- $loader = new InterSystemsApiLoader($conf, $this->db, $this->model);
- $supplier_id = $conf['supplier_id'];
- // Bn
- $sup_type = 470;
- $data = $loader->getPrices(1, $sup_type);
- $this->model->importPricesData($data, $sup_type, $supplier_id);
- // Nal
- $sup_type = 469;
- $data = $loader->getPrices(0, $sup_type);
- $this->model->importPricesData($data, $sup_type, $supplier_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement