/** * Get/load the feed. * * @param string url The feed url. * @param string category An optional category; default is <code>null</code>. * @param int limit An optional item limit; default is 5; use 0 for all. * @return RssFedd A <code>RssFeed</code> instance. */ public function getFeed($url, $category = null, $limit = 5) { $cacheKey = Toolbox::hash('feeds', $url, implode(':', $this->config)); if (!$this->cache || false === ($rssParser = $this->cache->lookup($cacheKey))) { $rssParser = new RssParser($this->config); // todo: conditional GET $rssParser->parse(file_get_contents($url, $this->config['useIncludePath'], $this->getContext())); } $feed = new RssFeed(); $feed->setChannel(new RssChannel($rssParser->getChannel())); $items = array(); foreach ($rssParser->getItems() as $itemData) { $item = new RssItem($itemData); if (null == $category || in_array($category, $item->getCategories())) { $items[] = $item; } if (0 != $limit && $limit <= count($items)) { break; } } $feed->setItems(new \ArrayIterator($items)); // cache if enabled if ($this->cache) { $this->cache->save($rssParser, $cacheKey); } return $feed; }
/** * Get the allowed product types (ids) for the given category id. * * @return array List of allowed product type ids; an empty list means no restrictions. */ public function getProductTypeIds($categoryId) { if (null !== $this->productTypeIdMap) { return array_key_exists($categoryId, $this->productTypeIdMap) ? $this->productTypeIdMap[$categoryId] : array(); } // first check cache if (false !== ($productTypeIdMap = $this->cache->lookup(Toolbox::hash('categories', 'productTypeIdMap')))) { $this->productTypeIdMap = $productTypeIdMap; return array_key_exists($categoryId, $this->productTypeIdMap) ? $this->productTypeIdMap[$categoryId] : array(); } $productTypeIdMap = array(); $sql = "SELECT * FROM %table.product_types_to_category%\n ORDER BY category_id"; foreach (\ZMRuntime::getDatabase()->fetchAll($sql, array(), 'product_types_to_category') as $result) { if (!array_key_exists($result['categoryId'], $productTypeIdMap)) { $productTypeIdMap[$result['categoryId']] = array(); } $productTypeIdMap[$result['categoryId']][] = $result['productTypeId']; } // save for later $this->cache->save($productTypeIdMap, Toolbox::hash('categories', 'productTypeIdMap')); $this->productTypeIdMap = $productTypeIdMap; return array_key_exists($categoryId, $productTypeIdMap) ? $productTypeIdMap[$categoryId] : array(); }
/** * Update manufacturers click stats. * * @param int id The manufacturer id. * @param int languageId Language id. */ public function updateManufacturerClickCount($id, $languageId) { // clear global cache $cacheKey = Toolbox::hash('manufacturer', $languageId); $this->cache->remove($cacheKey); // remove from cache $cacheKey = Toolbox::hash('manufacturer', $id, $languageId); $this->cache->remove($cacheKey); $sql = "UPDATE %table.manufacturers_info%\n SET url_clicked = url_clicked+1, date_last_click = now()\n WHERE manufacturers_id = :manufacturerId\n AND languages_id = :languageId"; $args = array('manufacturerId' => $id, 'languageId' => $languageId); return \ZMRuntime::getDatabase()->updateObj($sql, $args, array('manufacturers', 'manufacturers_info')); }
/** * Update an existing product. * * @param ZenMagick\StoreBundle\Entity\Product product The product. * @return ZenMagick\StoreBundle\Entity\Product The updated product. */ public function updateProduct($product) { \ZMRuntime::getDatabase()->updateModel('products', $product); \ZMRuntime::getDatabase()->updateModel('products_description', $product); \ZMRuntime::getDatabase()->updateModel('meta_tags_products_description', $product->getMetaTagDetails()); // update cache if (null != $this->cache) { $this->cache->remove(Toolbox::hash('product', $product->getId(), $product->getLanguageId())); } return $product; }