public function setName($name) { if (strlen(trim($name)) > 0) { $this->name = YMarket::specialChars($name); return true; } else { return false; } }
protected function getProp($data) { $tmp = ''; if (is_array($data)) { foreach ($data as $key => $value) { if (is_array($value)) { $tmp .= $this->getProp($value); } else { if (strlen(trim($value)) > 0) { $tmp .= "<{$key}>" . YMarket::specialChars(trim($value)) . "</{$key}>\r\n"; } } } } return $tmp; }
public function generate($to_file = true) { $link = new Link(); include_once 'YMarket.class.php'; //Язык по умолчанию $id_lang = intval(Configuration::get('PS_LANG_DEFAULT')); //Валюта по умолчанию $curr_def = new Currency(intval(Configuration::get('PS_CURRENCY_DEFAULT'))); //создаем новый магазин $market = new YMarket($this->_settings['y_sn'], $this->_settings['y_fn'], 'http://' . Tools::getHttpHost(false, true), $this->_settings['y_ldc']); //Валюты if ($this->_settings['y_cu']) { $currencies = Currency::getCurrencies(); foreach ($currencies as $currency) { $market->add(new yCurrency($currency['iso_code'], floatval($currency['conversion_rate']))); } unset($currencies); } else { $market->add(new yCurrency($curr_def->iso_code, floatval($curr_def->conversion_rate))); } //Категории $categories = Category::getCategories($id_lang, false, false); foreach ($categories as $category) { $catdesc = $category['meta_title'] ? $category['meta_title'] : $category['name']; $market->add(new yCategory($category['id_category'], $catdesc, $category['id_parent'])); } unset($categories); //Продукты $products = self::getProducts($id_lang); while ($product = Db::getInstance()->nextRow($products)) { $tmp = new yOffer($product['id_product'], $product['name'], Product::getPriceStatic($product['id_product'], $usetax = true, NULL, $decimals = 2, $divisor = NULL, $only_reduc = false, $usereduc = true, $quantity = 1, $forceAssociatedTax = true)); $tmp->id = $product['id_product']; $tmp->type = ''; $tmp->sales_notes = $this->_settings['y_sl']; $tmp->url = $link->getProductLink((int) $product['id_product'], $product['link_rewrite']); //Картинка if ($cover = self::getCover($product['id_product'])) { $tmp->picture = $link->getImageLink($product['link_rewrite'], $cover); } $tmp->currencyId = $curr_def->iso_code; $tmp->categoryId = $product['id_category_default']; //$tmp->vendorCode = $product['reference']; $tmp->description = $product['description']; if ($this->_settings['y_dl']) { $tmp->delivery = 'true'; } else { $tmp->delivery = 'false'; } switch ($this->_settings['y_av']) { case 1: $tmp->available = $product['quantity'] == 0 ? 'false' : 'true'; break; case 3: $tmp->available = 'false'; break; default: $tmp->available = 'true'; } //$tmp->barcode = $product['ean13']; if (ProductDownload::getIdFromIdProduct($product['id_product'])) { $tmp->downloadable = 'true'; } if (!($this->_settings['y_av'] == 2 and $product['quantity'] == 0)) { $market->add($tmp); } } if ($to_file) { $fp = fopen(dirname(__FILE__) . '/../../upload/yml.xml' . ($this->_settings['y_gz'] ? '.gz' : ''), 'w'); fwrite($fp, $market->generate(false, $this->_settings['y_gz'])); fclose($fp); } else { $market->generate(true, $this->_settings['y_gz']); } }