2015-06-26 18:07:36 +03:00
|
|
|
<?php
|
|
|
|
|
2015-07-23 00:27:20 +03:00
|
|
|
class ModelRetailcrmIcml extends Model
|
|
|
|
{
|
2015-06-26 18:07:36 +03:00
|
|
|
protected $shop;
|
|
|
|
protected $file;
|
|
|
|
protected $properties;
|
|
|
|
protected $params;
|
|
|
|
protected $dd;
|
|
|
|
protected $eCategories;
|
|
|
|
protected $eOffers;
|
|
|
|
|
|
|
|
public function generateICML()
|
|
|
|
{
|
|
|
|
$this->load->language('module/retailcrm');
|
|
|
|
$this->load->model('catalog/category');
|
|
|
|
$this->load->model('catalog/product');
|
|
|
|
$this->load->model('catalog/manufacturer');
|
|
|
|
|
|
|
|
$string = '<?xml version="1.0" encoding="UTF-8"?>
|
|
|
|
<yml_catalog date="'.date('Y-m-d H:i:s').'">
|
|
|
|
<shop>
|
|
|
|
<name>'.$this->config->get('config_name').'</name>
|
|
|
|
<categories/>
|
|
|
|
<offers/>
|
|
|
|
</shop>
|
|
|
|
</yml_catalog>
|
|
|
|
';
|
|
|
|
|
|
|
|
$xml = new SimpleXMLElement(
|
|
|
|
$string,
|
|
|
|
LIBXML_NOENT |LIBXML_NOCDATA | LIBXML_COMPACT | LIBXML_PARSEHUGE
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->dd = new DOMDocument();
|
|
|
|
$this->dd->preserveWhiteSpace = false;
|
|
|
|
$this->dd->formatOutput = true;
|
|
|
|
$this->dd->loadXML($xml->asXML());
|
|
|
|
|
|
|
|
$this->eCategories = $this->dd
|
|
|
|
->getElementsByTagName('categories')->item(0);
|
|
|
|
$this->eOffers = $this->dd
|
|
|
|
->getElementsByTagName('offers')->item(0);
|
|
|
|
|
2015-07-22 23:56:05 +03:00
|
|
|
$this->addCategories();
|
|
|
|
$this->addOffers();
|
2015-06-26 18:07:36 +03:00
|
|
|
|
|
|
|
$this->dd->saveXML();
|
|
|
|
|
2016-02-09 16:21:45 +03:00
|
|
|
$downloadPath = DIR_SYSTEM . '/../';
|
2015-06-26 18:07:36 +03:00
|
|
|
|
|
|
|
if (!file_exists($downloadPath)) {
|
|
|
|
mkdir($downloadPath, 0755);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->dd->save($downloadPath . 'retailcrm.xml');
|
|
|
|
}
|
|
|
|
|
2015-07-23 00:27:20 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2015-06-26 18:07:36 +03:00
|
|
|
private function addCategories()
|
|
|
|
{
|
|
|
|
$categories = $this->model_catalog_category->getCategories(array());
|
|
|
|
foreach($categories as $category) {
|
2016-04-06 12:34:40 +03:00
|
|
|
$category = $this->model_catalog_category->getCategory($category['category_id']);
|
|
|
|
|
2015-06-26 18:07:36 +03:00
|
|
|
$e = $this->eCategories->appendChild(
|
|
|
|
$this->dd->createElement(
|
|
|
|
'category', $category['name']
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2016-01-29 17:59:53 +03:00
|
|
|
$e->setAttribute('id', $category['category_id']);
|
2015-06-26 18:07:36 +03:00
|
|
|
|
|
|
|
if ($category['parent_id'] > 0) {
|
|
|
|
$e->setAttribute('parentId', $category['parent_id']);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private function addOffers()
|
|
|
|
{
|
|
|
|
$offerManufacturers = array();
|
|
|
|
|
|
|
|
$manufacturers = $this->model_catalog_manufacturer
|
|
|
|
->getManufacturers(array());
|
|
|
|
|
|
|
|
foreach ($manufacturers as $manufacturer) {
|
|
|
|
$offerManufacturers[
|
|
|
|
$manufacturer['manufacturer_id']
|
|
|
|
] = $manufacturer['name'];
|
|
|
|
}
|
|
|
|
|
|
|
|
$products = $this->model_catalog_product->getProducts(array());
|
|
|
|
|
|
|
|
foreach ($products as $offer) {
|
|
|
|
|
|
|
|
$e = $this->eOffers->appendChild($this->dd->createElement('offer'));
|
|
|
|
$e->setAttribute('id', $offer['product_id']);
|
|
|
|
$e->setAttribute('productId', $offer['product_id']);
|
|
|
|
$e->setAttribute('quantity', $offer['quantity']);
|
2016-01-29 17:59:53 +03:00
|
|
|
|
2015-06-26 18:07:36 +03:00
|
|
|
/**
|
|
|
|
* Offer activity
|
|
|
|
*/
|
2016-01-29 17:59:53 +03:00
|
|
|
$activity = $offer['status'] == 1 ? 'Y' : 'N';
|
2015-06-26 18:07:36 +03:00
|
|
|
$e->appendChild(
|
|
|
|
$this->dd->createElement('productActivity')
|
|
|
|
)->appendChild(
|
2016-01-29 17:59:53 +03:00
|
|
|
$this->dd->createTextNode($activity)
|
2015-06-26 18:07:36 +03:00
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Offer categories
|
|
|
|
*/
|
|
|
|
$categories = $this->model_catalog_product
|
|
|
|
->getProductCategories($offer['product_id']);
|
2016-01-29 17:59:53 +03:00
|
|
|
|
2015-06-26 18:07:36 +03:00
|
|
|
if (!empty($categories)) {
|
|
|
|
foreach ($categories as $category) {
|
2016-04-06 12:34:40 +03:00
|
|
|
$e->appendChild($this->dd->createElement('categoryId'))
|
2015-06-26 18:07:36 +03:00
|
|
|
->appendChild(
|
|
|
|
$this->dd->createTextNode($category)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name & price
|
|
|
|
*/
|
|
|
|
$e->appendChild($this->dd->createElement('name'))
|
|
|
|
->appendChild($this->dd->createTextNode($offer['name']));
|
|
|
|
$e->appendChild($this->dd->createElement('productName'))
|
|
|
|
->appendChild($this->dd->createTextNode($offer['name']));
|
|
|
|
$e->appendChild($this->dd->createElement('price'))
|
|
|
|
->appendChild($this->dd->createTextNode($offer['price']));
|
2016-01-29 17:59:53 +03:00
|
|
|
|
2015-06-26 18:07:36 +03:00
|
|
|
/**
|
|
|
|
* Vendor
|
|
|
|
*/
|
|
|
|
if ($offer['manufacturer_id'] != 0) {
|
|
|
|
$e->appendChild($this->dd->createElement('vendor'))
|
|
|
|
->appendChild(
|
|
|
|
$this->dd->createTextNode(
|
|
|
|
$offerManufacturers[$offer['manufacturer_id']]
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Image
|
|
|
|
*/
|
|
|
|
if ($offer['image']) {
|
|
|
|
$image = $this->generateImage($offer['image']);
|
|
|
|
$e->appendChild($this->dd->createElement('picture'))
|
|
|
|
->appendChild($this->dd->createTextNode($image));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Url
|
|
|
|
*/
|
|
|
|
$this->url = new Url(
|
|
|
|
HTTP_CATALOG,
|
|
|
|
$this->config->get('config_secure')
|
|
|
|
? HTTP_CATALOG
|
|
|
|
: HTTPS_CATALOG
|
|
|
|
);
|
|
|
|
|
|
|
|
$e->appendChild($this->dd->createElement('url'))
|
|
|
|
->appendChild(
|
|
|
|
$this->dd->createTextNode(
|
|
|
|
$this->url->link(
|
|
|
|
'product/product&product_id=' . $offer['product_id']
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
if ($offer['sku']) {
|
|
|
|
$sku = $this->dd->createElement('param');
|
|
|
|
$sku->setAttribute('code', 'article');
|
|
|
|
$sku->setAttribute('name', $this->language->get('article'));
|
|
|
|
$sku->appendChild($this->dd->createTextNode($offer['sku']));
|
|
|
|
$e->appendChild($sku);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($offer['weight'] != '') {
|
|
|
|
$weight = $this->dd->createElement('param');
|
|
|
|
$weight->setAttribute('color', 'weight');
|
|
|
|
$weight->setAttribute('name', $this->language->get('weight'));
|
|
|
|
$weightValue = (isset($offer['weight_class']))
|
|
|
|
? round($offer['weight'], 3) . ' ' . $offer['weight_class']
|
|
|
|
: round($offer['weight'], 3)
|
|
|
|
;
|
|
|
|
$weight->appendChild($this->dd->createTextNode($weightValue));
|
|
|
|
$e->appendChild($weight);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-07-22 23:56:05 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $image
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2015-06-26 18:07:36 +03:00
|
|
|
private function generateImage($image)
|
|
|
|
{
|
|
|
|
$this->load->model('tool/image');
|
|
|
|
|
|
|
|
return $this->model_tool_image->resize(
|
|
|
|
$image,
|
|
|
|
$this->config->get('config_image_product_width'),
|
|
|
|
$this->config->get('config_image_product_height')
|
2015-07-22 23:56:05 +03:00
|
|
|
);
|
2015-06-26 18:07:36 +03:00
|
|
|
}
|
|
|
|
}
|