Jump to content

Recommended Posts

Подскажите как переделать данный скрипт экспорта xml для вывода данных на двух языках ,данный скрипт может выводить на нескольких языках но по отдельности хотелось бы  объединить два в одном скрипте.

<?php
class ControllerFeedShopXML extends Controller {
private $currencies = array();

public function index() {
if ($this->config->get('shopxml_status')) {

$xmlstr = '<?xml version="1.0" encoding="utf-8" ?>

<root></root>';

$xml = new SimpleXMLElement($xmlstr);

if(isset($_GET["lang_export"])){
$languages = array();
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "language` WHERE status = '1'");
foreach($query->rows as $result){
$languages[$result['code']] = $result;
}
if(isset($languages[$_GET["lang_export"]]["language_id"])){
$this->config->set("config_language", $_GET["lang_export"]);
$this->config->set("config_language_id", $languages[$_GET["lang_export"]]["language_id"]);
}
}

$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');

$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "currency");

foreach ($query->rows as $result) {
if($result['status'] == 1){
$this->currencies[$result['code']] = array(
'currency_id' => $result['currency_id'],
'title' => $result['title'],
'symbol_left' => $result['symbol_left'],
'symbol_right' => $result['symbol_right'],
'decimal_place' => $result['decimal_place'],
'value' => $result['value']
);
}
}

if(isset($this->request->get['cur_export']) && (array_key_exists($this->request->get['cur_export'], $this->currencies))){
$this->currency->set($this->request->get['cur_export']);
} else{
$this->currency->set($this->config->get('config_currency'));
}


$products = $this->model_catalog_product->getProducts();
foreach($products as $product){
$item = $xml->addChild('item');
$item->name = $product['name'];
if(isset($product["description"]) && isset($_GET["desc_export"])){
$item->description = html_entity_decode($product['description'], ENT_QUOTES, 'UTF-8') ;
}

if($product['image']){
$item->image = $this->model_tool_image->resize($product['image'], 500, 500);
} else{
$item->image = $this->model_tool_image->resize('no_image.jpg', 500, 500);
}
$categories = $this->model_catalog_product->getCategories($product['product_id']);
$string = '';
$lastCat = '';
$caturl = '';
foreach($categories as $category){
$path = $this->getPath($category['category_id']);
$caturl = HTTP_SERVER . $this->config->get("config_language").'/'.'index.php?route=product/category&path=' . $path;
if($path){
foreach(explode('_', $path) as $path_id){
$category_info = $this->model_catalog_category->getCategory($path_id);
$lastCat = $category_info['name'];
if($category_info){
if(!$string){
$string = $category_info['name'];
} else{
$string .= ' >> ' . $category_info['name'];
}
}
}
}
break;
}


$currency_code = $this->currency->getCode();
$currency_value = $this->currency->getValue();

$item->link = HTTP_SERVER . $this->config->get("config_language").'/'.'?route=product/product&product_id=' . $product['product_id'].'&currency='.$currency_code;
$caturl .= '&currency='.$currency_code;



if((float)$product['special']){
$item->price = $this->currency->format($this->tax->calculate($product['special'],
$product['tax_class_id']),
$currency_code,
$currency_value,
false);
} else{
$item->price = $this->currency->format($this->tax->calculate($product['price'],
$product['tax_class_id']),
$currency_code,
$currency_value,
false);
}
$item->category = $lastCat;
$item->category_full = $string;
$item->category_link = $caturl;
$item->manufacturer = $product['manufacturer'];
$item->model = $product['model'];
$item->in_stock = $product['quantity'];
$item->upc = $product['quantity'];
$item->weight = $product['weight'];
}
$this->response->addHeader('Content-Type: application/xml');
$this->response->setOutput($xml->asXML());





}







}

protected function getPath($parent_id, $current_path = '') {
$category_info = $this->model_catalog_category->getCategory($parent_id);
if ($category_info) {
if (!$current_path) {
$new_path = $category_info['category_id'];
} else {
$new_path = $category_info['category_id'] . '_' . $current_path;
}

$path = $this->getPath($category_info['parent_id'], $new_path);
if ($path) {
return $path;
} else {
return $new_path;
}
}
}
}
?>

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×

Important Information

On our site, cookies are used and personal data is processed to improve the user interface. To find out what and what personal data we are processing, please go to the link. If you click "I agree," it means that you understand and accept all the conditions specified in this Privacy Notice.