Помогите перенастроить парсер. Нужно что бы брало с сайта картинку и описание. Раньше прайс был другой. и все было нормально. теперь прайсы изменились. и парсер перестал работать. нужно чуть поправить. КТО МОЖЕТ ПОМОЧЬ?
namespace Supplier;
use Model\Supplier;
defined('PIMPORT') or die('Error access');
@package
class Kompl extends \Infr\Supplier {
@var
protected $_host = 'http://www.fcenter.ru';
@var
protected $_productMask = 'http://www.fcenter.ru/product/goods/{PRODUCT_ID}';
@throws @return
protected function _getPrice() {
$class = 'Plugins\Suppliers\Supplier\Kompl';
if (class_exists($class)) {
@var
$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 @param @param @return
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 @param @return @throws
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 @return @throws
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;
}
}