раньше прайс был другой. и все было нормально. теперь прайсы изменились. и парсер перестал работать. нужно чуть поправить Код (Text): namespace Supplier; use Model\Supplier; defined('PIMPORT') or die('Error access'); /** * Class Kompl * @package Supplier */ class Kompl extends \Infr\Supplier { /** @var string */ protected $_host = 'http://www.fcenter.ru'; /** @var string */ protected $_productMask = 'http://www.fcenter.ru/product/goods/{PRODUCT_ID}'; /** * @throws \Exception * @return string */ protected function _getPrice() { //проверяем подключен ли плагин и к нему поставщик $class = 'Plugins\Suppliers\Supplier\Kompl'; if (class_exists($class)) { /** @var \Plugins\Suppliers\Infr\Supplier $supplierItem */ $supplierItem = new $class; $pricePath = $supplierItem->getPricePath(); if (file_exists($pricePath)) { return file_get_contents($pricePath); } else { throw new \Exception('Прайс-лист для поставщика не загружен'); } } else { throw new \Exception('К плагину Suppliers не подключен нужный поставщик'); } } /** * @param \Model\Supplier $supplier * @param \Model\Supplier\Product $product * @param array $params * @return mixed|\Model\Supplier\Product */ public function getProduct(Supplier $supplier, Supplier\Product $product, array $params = array()) { if ($product->url) { $html = \Infr\Request::httpRequest($product->url); if ($html) { $dom = \Infr\str_get_html($html); if ($dom) { $pict = $dom->find('a.preview', 0); if ($pict) { $product->pictures = array((string) $pict->getAttribute('href')); $pict->clear(); } unset($dom); } } unset($html); } return $product; } /** * @param \Model\Supplier $supplier * @param array $params * @return array|mixed|\Model\Supplier\Product\Collection * @throws \Exception */ public function getProducts(Supplier $supplier, array $params = array()) { $collection = new Supplier\Product\Collection(); $xmlContent = $this->_getPrice(); if (empty($xmlContent)) { return $collection; } $xml = simplexml_load_string($xmlContent); if (!$xml) { throw new \Exception('Из сайта ' . $this->_host . ' не загружен прайс'); } if (!empty($xml->product)) { $categoryCollection = $this->getCategories($supplier); foreach ($xml->product as $product) { $id = (string) $product->id; $categoryId = (string) $product->categoryID; $categoryItem = $categoryCollection->find($categoryId); if (empty($categoryItem)) { continue; } if (empty($id) || empty($categoryId)) { continue; } $data = array( 'id' => $id, 'article' => $id, 'name' => (string) $product->name, 'shortDescription' => '', 'description' => (string) $product->desc, 'price' => (float) $product->wholesale, 'inStock' => 1, 'categoryId' => $categoryId, 'category' => $categoryItem, 'pictures' => array(), 'options' => array(), 'url' => str_replace('{PRODUCT_ID}', $id, $this->_productMask), 'params' => array('article' => $id), ); $productItem = $collection->createElement($data); $collection->add($productItem); } } return $collection; } /** * @param \Model\Supplier $supplier * @return \Model\Supplier\Category\Collection * @throws \Exception */ public function getCategories(Supplier $supplier) { $categoryCollection = new Supplier\Category\Collection(); $xmlContent = $this->_getPrice(); $xml = simplexml_load_string($xmlContent); if (!$xml) { throw new \Exception('Из сайта ' . $this->_host . ' не загружен прайс'); } if (!empty($xml->product)) { $categoriesArray = array(); foreach ($xml->product as $product) { $categoryId = (string) $product->categoryID; $categoryName = (string) $product->category; if (empty($categoryId)) { continue; } $categoriesArray[$categoryId] = $categoryName; } foreach ($categoriesArray as $categoryId => $categoryName) { if ($categoryCollection->find($categoryId)) { continue; } $data = array( 'id' => $categoryId, 'parentId' => 0, 'name' => $categoryName, 'supplierId' => $supplier->id, 'url' => '#' ); $categoryItem = $categoryCollection->createElement($data); $categoryCollection->add($categoryItem); } } return $categoryCollection; } }
прайсы загружаю в xls, автоматом переделывается .xml. артикулы совпадают с сайтом с которого хочу парсить protected $_productMask = 'http://www.fcenter.ru/product/goods/{PRODUCT_ID}'; по этому коду выходит на страницу товара {PRODUCT_ID} артикул товара. --- Добавлено --- Прайс .xml вот такого вида Код (Text): -<products> -<product> <id>1983251</id> -<name> <![CDATA[Сист. блок Flextron 2C (P-G3260-3.30ГГц/H81M-A/2x4ГБ/128ГБ/500ГБ/WiFi) (212643)]]> </name> -<desc> <![CDATA[]]> </desc> -<category> <![CDATA[Компания Ф-Центр→Компания Ф-Центр]]> </category> <categoryID>2022814867</categoryID> <wholesale>24369.108014</wholesale> </product>
Похоже что XML просто не valid, с ошибками или просто с ошибкой был скопирован? --- Добавлено --- тут правилами запрещено парсинг сайтов обсуждать, только через API или скачивание фалов, xls, xml например.