Esempio n. 1
0
 function indexAction()
 {
     function addToXml($xml, $parent, $nodeName, $text)
     {
         $node = $parent->appendChild($xml->createElement($nodeName));
         $node->appendChild($xml->createTextNode($text));
         return $node;
     }
     $imp = new DOMImplementation();
     $dtd = $imp->createDocumentType('yml_catalog', '', 'shops.dtd');
     $xml = $imp->createDocument('', '', $dtd);
     $xml->encoding = 'UTF-8';
     $xml->formatOutput = true;
     $root = $xml->createElement('yml_catalog');
     $root->setAttribute("date", date('Y-m-d H:i'));
     $root = $xml->appendChild($root);
     $shop = $xml->createElement('shop');
     addToXml($xml, $shop, 'name', \App::$cur->config['site']['name']);
     addToXml($xml, $shop, 'company', \App::$cur->config['site']['company_name']);
     addToXml($xml, $shop, 'url', 'http://' . INJI_DOMAIN_NAME);
     $currencies = $xml->createElement('currencies');
     $currency = $currencies->appendChild($xml->createElement('currency'));
     $currency->setAttribute('id', 'RUR');
     $currency->setAttribute('rate', '1');
     $currency->setAttribute('plus', '');
     $shop->appendChild($currencies);
     $categories = $xml->createElement('categories');
     foreach (Ecommerce\Category::getList() as $category) {
         $xmlCategory = addToXml($xml, $categories, 'category', $category->name);
         $xmlCategory->setAttribute('id', $category->id);
         if ($category->parent_id) {
             $xmlCategory->setAttribute('parentId', $category->parent_id);
         }
     }
     $shop->appendChild($categories);
     addToXml($xml, $shop, 'local_delivery_cost', '300');
     $offers = $xml->createElement('offers');
     foreach (App::$cur->ecommerce->getItems() as $item) {
         $offer = $offers->appendChild($xml->createElement('offer'));
         addToXml($xml, $offer, 'url', 'http://' . INJI_DOMAIN_NAME . '/ecommerce/view/' . $item->id);
         addToXml($xml, $offer, 'price', $item->getPrice()->price);
         addToXml($xml, $offer, 'currencyId', 'RUR');
         addToXml($xml, $offer, 'categoryId', $item->category_id);
         addToXml($xml, $offer, 'delivery', 'true');
         addToXml($xml, $offer, 'local_delivery_cost', '300');
         addToXml($xml, $offer, 'vendor', 'vendor');
         addToXml($xml, $offer, 'model', 'model');
         addToXml($xml, $offer, 'description', $item->description);
         addToXml($xml, $offer, 'manufacturer_warranty', 'true');
         addToXml($xml, $offer, 'country_of_origin', 'Китай');
         foreach ($item->options as $option) {
             $param = addToXml($xml, $offer, 'param', $option->value);
             $param->setAttribute('name', $option->item_option_name);
             if ($option->item_option_postfix) {
                 $param->setAttribute('unit', $option->item_option_postfix);
             }
         }
     }
     $shop->appendChild($offers);
     $root->appendChild($shop);
     header("Content-Type: text/xml");
     header("Expires: Thu, 19 Feb 1998 13:24:18 GMT");
     header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
     header("Cache-Control: no-cache, must-revalidate");
     header("Cache-Control: post-check=0,pre-check=0");
     header("Cache-Control: max-age=0");
     header("Pragma: no-cache");
     echo $xml->saveXML();
 }
Esempio n. 2
0
 public function viewAction($id = '')
 {
     $item = \Ecommerce\Item::get((int) $id);
     if (!$item) {
         Tools::redirect('/ecommerce/', 'Такой товар не найден');
     }
     $active = $item->category_id;
     $catalog = $item->category;
     $bread = [];
     $bread[] = ['text' => 'Каталог', 'href' => '/ecommerce'];
     $catalogIds = array_values(array_filter(explode('/', $item->tree_path)));
     foreach ($catalogIds as $id) {
         $cat = Ecommerce\Category::get($id);
         if ($cat) {
             $bread[] = ['text' => $cat->name, 'href' => '/ecommerce/itemList/' . $cat->id];
         }
     }
     $bread[] = ['text' => $item->name()];
     $this->view->setTitle($item->name());
     $options = ['data' => compact('item', 'active', 'catalog', 'bread')];
     if (isset($_GET['quickview'])) {
         $options['page'] = 'blank';
     }
     $this->view->addMetaTag(['property' => 'og:title', 'content' => $item->name]);
     $this->view->addMetaTag(['property' => 'og:description', 'content' => $item->description]);
     if ($item->image) {
         $this->view->addMetaTag(['property' => 'og:image', 'content' => 'http://' . INJI_DOMAIN_NAME . $item->image->path]);
     }
     $this->view->addMetaTag(['property' => 'og:url', 'content' => 'http://' . INJI_DOMAIN_NAME . '/view/' . $item->id]);
     $options['content'] = $item->view ? $item->view : 'view';
     $this->view->page($options);
 }