*/ /** * Klasa stSkapiec * * @package stSkapiecPlugin * @subpackage libs */ class stSkapiec extends stPriceCompareGenerateFile implements stPriceCompareGenerateFileInterface { /** * Konstruktor */ public function __construct() { parent::__construct(__CLASS__); } /** * Generowanie stopki pliku * * @return string */ protected function getFileHead() { $content = xml_open_tag('?xml version="1.0" encoding="ISO-8859-2"?'); $content.= xml_open_tag('xmldata'); $content.= xml_tag('version', '10'); $headerContent = xml_tag('name', $this->getConfig('shop_name')); $headerContent.= xml_tag('shopid', $this->getConfig('shop_id')); $headerContent.= xml_tag('www', $this->getShopUrl()); $headerContent.= xml_tag('time', date('Y-m-d')); $content.= xml_tag('header', $headerContent); $content.= $this->getCategory(); $content.= xml_open_tag('data'); return mb_convert_encoding($content, 'ISO-8859-2', 'UTF-8'); } /** * Generowanie zawartości pliku * * @param integer $step numer kroku * @return string */ protected function getFileBody($step) { $priceCompareProducts = $this->getProducts($step); $content = ""; foreach ($priceCompareProducts as $priceCompareProduct) { $parsedProduct = new stPriceCompareProductParser($priceCompareProduct->getProduct()); if ($parsedProduct->checkProduct()) { $this->product = $priceCompareProduct->getProduct(); $productContent = xml_tag('compid', $parsedProduct->getId()); if ($parsedProduct->hasProducer()) $productContent.= xml_tag('vendor', htmlspecialchars($parsedProduct->getProducer())); $productContent.= xml_tag('desc', htmlspecialchars($parsedProduct->getName())); $productContent.= xml_cdata_tag('desclong', $parsedProduct->getDescription()); $productContent.= xml_tag('price', $parsedProduct->getPrice()); $productContent.= xml_tag('catid', $parsedProduct->getCategoryId()); $productContent.= xml_tag('foto', $parsedProduct->getPhoto()); $productContent.= xml_tag('url', $parsedProduct->getUrl()); if ($this->getConfig('use_product_code') == true) { $productContent.= xml_tag('partnr', $parsedProduct->getCode()); } if ($this->getConfig('use_ean') == true && $parsedProduct->hasManCode()) { $productContent.= xml_tag('ean', $parsedProduct->getManCode()); } $productContent = stEventDispatcher::getInstance()->filter(new sfEvent($this, 'stSkapiecPlugin.stSkapiecProductContent', array('product' => $this->product)), $productContent)->getReturnValue(); $content.= xml_tag('item', $productContent); } unset($parsedProduct); } return mb_convert_encoding($content, 'ISO-8859-2', 'UTF-8'); } /** * Generowanie nagłówka pliku * * @return string */ protected function getFileFoot() { $content = xml_close_tag('data'); $content.= xml_close_tag('xmldata'); return mb_convert_encoding($content, 'ISO-8859-2', 'UTF-8'); } /** * Generowanie kategorii * * @return string */ private function getCategory() { $content = ''; $c = new Criteria(); $c->addJoin(ProductPeer::ID, SkapiecPeer::PRODUCT_ID, Criteria::JOIN); $c->addJoin(ProductPeer::ID, ProductHasCategoryPeer::PRODUCT_ID, Criteria::JOIN); $c->add(SkapiecPeer::ACTIVE, 1); $c->add(ProductHasCategoryPeer::IS_DEFAULT, 1); $c->addGroupByColumn(ProductHasCategoryPeer::CATEGORY_ID); $products = ProductPeer::doSelect($c); foreach ($products as $product) { $product->getDefaultCategory()->setCulture('pl_PL'); if (is_object($product->getDefaultCategory())) { $categoriesPath = ''; foreach ($product->getDefaultCategory()->getPath() as $category) { $category->setCulture('pl_PL'); if (is_object($category)) { $categoryName = $category->getName(); if (!empty($categoryName)) $categoriesPath .= $categoryName.'/'; } } $catItemContent = xml_tag('catid', $product->getDefaultCategory()->getId()); $catItemContent.= xml_tag('catname', htmlspecialchars($categoriesPath.$product->getDefaultCategory()->getName())); $catItemContent.= xml_tag('dprice', ''); $content.= xml_tag('catitem', $catItemContent); } } return xml_tag('category', $content); } /** * Pobieranie infromacji o porównywarce podczas eksportu * * @param object $object * @return integer */ static public function getProduct($object = null) { return stPriceCompareGenerateFile::getProductForExport(__CLASS__, $object); } /** * Ustawianie infromacji o porównywarce podczas importu * * @param object $object * @param integer $value * @return boolean */ static public function setProduct($object = null, $active = 0) { return stPriceCompareGenerateFile::setProductForImport(__CLASS__, $object, $active); } }