public function generateXML($cron) { $shop_url = 'http://' . Tools::getHttpHost(false, true) . __PS_BASE_URI__; $id_lang = (int) Configuration::get('PS_LANG_DEFAULT'); $currency_default = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $this->currency_iso = $currency_default->iso_code; $country = new Country(Configuration::get('PS_COUNTRY_DEFAULT')); $this->country_name = $country->name; $currencies = Currency::getCurrencies(); $categories = Category::getCategories($id_lang, false, false); $yamarket_set_combinations = Configuration::get('YA_MARKET_SET_COMBINATIONS'); $this->yamarket_availability = Configuration::get('YA_MARKET_DOSTUPNOST'); $this->gzip = Configuration::get('YA_MARKET_SET_GZIP'); /*-----------------------------------------------------------------------------*/ $cats = array(); if ($c = Configuration::get('YA_MARKET_CATEGORIES')) { $uc = unserialize($c); if (is_array($uc)) { $cats = $uc; } } $yml = new Yml(); $yml->yml('utf-8'); $yml->setShop(Configuration::get('PS_SHOP_NAME'), Configuration::get('YA_MARKET_NAME'), $shop_url); if (Configuration::get('YA_MARKET_SET_ALLCURRENCY')) { foreach ($currencies as $currency) { $yml->addCurrency($currency['iso_code'], (double) $currency_default->conversion_rate / (double) $currency['conversion_rate']); } unset($currencies); } else { $yml->addCurrency($currency_default->iso_code, (double) $currency_default->conversion_rate); } foreach ($categories as $category) { if (!in_array($category['id_category'], $cats) || $category['id_category'] == 1) { continue; } if (Configuration::get('YA_MARKET_SET_NACTIVECAT')) { if (!$category['active']) { continue; } } if (Configuration::get('YA_MARKET_CATALL')) { if (in_array($category['id_category'], $cats)) { $yml->addCategory($category['name'], $category['id_category'], $category['id_parent']); } } else { $yml->addCategory($category['name'], $category['id_category'], $category['id_parent']); } } foreach ($yml->categories as $cat) { $category_object = new Category($cat['id']); $products = $category_object->getProducts($id_lang, 1, 10000); if ($products) { foreach ($products as $product) { if ($product['id_category_default'] != $cat['id']) { continue; } $data = array(); if ($yamarket_set_combinations && !Configuration::get('YA_MARKET_SHORT')) { $product_object = new Product($product['id_product'], false, $id_lang); $combinations = $product_object->getAttributeCombinations($id_lang); } else { $combinations = false; } if (is_array($combinations) && count($combinations) > 0) { $comb_array = array(); foreach ($combinations as $combination) { $comb_array[$combination['id_product_attribute']]['id_product_attribute'] = $combination['id_product_attribute']; $comb_array[$combination['id_product_attribute']]['price'] = Product::getPriceStatic($product['id_product'], true, $combination['id_product_attribute']); $comb_array[$combination['id_product_attribute']]['reference'] = $combination['reference']; $comb_array[$combination['id_product_attribute']]['ean13'] = $combination['ean13']; $comb_array[$combination['id_product_attribute']]['quantity'] = $combination['quantity']; $comb_array[$combination['id_product_attribute']]['minimal_quantity'] = $combination['minimal_quantity']; $comb_array[$combination['id_product_attribute']]['weight'] = $combination['weight']; $comb_array[$combination['id_product_attribute']]['attributes'][$combination['group_name']] = $combination['attribute_name']; if (!isset($comb_array[$combination['id_product_attribute']]['comb_url'])) { $comb_array[$combination['id_product_attribute']]['comb_url'] = ''; } $comb_array[$combination['id_product_attribute']]['comb_url'] .= '/' . Tools::str2url($combination['group_name']) . '-' . str_replace(Configuration::get('PS_ATTRIBUTE_ANCHOR_SEPARATOR'), '_', Tools::str2url(str_replace(array(',', '.'), '-', $combination['attribute_name']))); } foreach ($comb_array as $combination) { $data = $this->makeData($product, $combination); $available = $data['available']; unset($data['available']); if (!empty($data) && $data['price'] != 0) { $yml->addOffer($data['id'], $data, $available); } } } else { $data = $this->makeData($product); $available = $data['available']; unset($data['available']); if (!empty($data) && (int) $data['price'] != 0) { $yml->addOffer($data['id'], $data, $available); } } unset($data); } } unset($product); } unset($categories); $xml = $yml->getXml(); if ($cron) { if ($fp = fopen(_PS_UPLOAD_DIR_ . 'yml.' . $this->context->shop->id . '.xml' . ($this->gzip ? '.gz' : ''), 'w')) { fwrite($fp, $xml); fclose($fp); $this->logSave('market_generate: Cron ' . $this->l('Generate price')); } } else { if ($this->gzip) { header('Content-type:application/x-gzip'); header('Content-Disposition: attachment; filename=yml.' . $this->context->shop->id . '.xml.gz'); $this->logSave('market_generate: gzip view ' . $this->l('Generate price')); } else { header('Content-type:application/xml; charset=windows-1251'); } $this->logSave('market_generate: view ' . $this->l('Generate price')); echo $xml; exit; } }
<?php namespace infrajs\yml; if (!is_file('vendor/autoload.php')) { chdir('../../../../'); } require_once 'vendor/autoload.php'; Yml::show();