/** * Generate RSS item for the given category info. * * @param array categoryInfo The category info. * @param int languageId The language id. * @param boolean fullFeed Optional flag to enable/disable full feed details. * @return RssFeed The feed. */ protected function rssItem($categoryInfo, $languageId, $fullFeed) { $category = $this->container->get('categoryService')->getCategoryForId($categoryInfo['id'], $languageId); $item = new RssItem(); $item->setTitle($category->getName()); $item->setLink($categoryInfo['url']); $html = $this->container->get('htmlTool'); $desc = $html->strip($category->getDescription()); if (!$full) { $desc = $html->more($desc, 60); } $item->setDescription($desc); $item->setPubDate($category->getDateAdded()); $item->addTag('id', $category->getId()); $item->addTag('path', implode('_', $category->getPath())); $item->addTag('children', array('id' => $category->getDecendantIds(false))); if ($full) { $item->addTag('type', 'category'); } return $item; }
/** * Generate RSS item for the given product. * * @param array productInfo The product info. * @param int languageId The language id. * @param boolean fullFeed Optional flag to enable/disable full feed details. * @param boolean multiCurrency Optional flag to enable/disable multi currency details. * @return RssItem The RSS item. */ protected function rssItem($productInfo, $languageId, $fullFeed, $multiCurrency) { $categoryService = $this->container->get('categoryService'); $currencyService = $this->container->get('currencyService'); $product = $this->container->get('productService')->getProductForId($productInfo['id'], $languageId); $item = new RssItem(); $item->setTitle($product->getName()); $item->setLink($productInfo['url']); $html = $this->container->get('htmlTool'); $desc = $html->strip($product->getDescription()); if (!$fullFeed) { $desc = $html->more($desc, 60); } $item->setDescription($desc); $item->setPubDate($product->getDateAdded()); $item->addTag('id', $product->getId()); $item->addTag('model', $product->getModel()); if (null != ($defaultCategory = $product->getDefaultCategory())) { // build id/name path $idPath = array(); $namePath = array(); foreach ($defaultCategory->getPath() as $categoryId) { if (null != ($category = $categoryService->getCategoryForId($categoryId, $languageId))) { $idPath[] = $category->getId(); $namePath[] = $category->getName(); } } $item->addTag('category', array('id' => $defaultCategory->getId(), 'name' => $defaultCategory->getName(), 'path' => array('idPath' => implode('|', $idPath), 'namePath' => implode('|', $namePath)))); } if ($fullFeed) { $offers = $product->getOffers(); $tax = true; $pricing = array('basePrice' => $offers->getBasePrice($tax), 'price' => $offers->getCalculatedPrice(), 'staggered' => $offers->isAttributePrice() ? 'true' : 'false', 'free' => $product->isFree() ? 'true' : 'false'); if (!$product->isFree()) { if ($offers->isSale()) { $pricing['sale'] = $offers->getSalePrice($tax); } elseif ($offers->isSpecial()) { $pricing['special'] = $offers->getSpecialPrice($tax); } } if ($multiCurrency) { $currencyPricings = array(); foreach ($currencyService->getCurrencies() as $currency) { $cp = array(); foreach ($pricing as $key => $value) { if (!is_string($value)) { // convert to currency $value = $currency->convertTo($value); } $cp[$key] = $value; } $currencyPricings[$currency->getCode()] = $cp; } $pricing = $currencyPricings; } $item->addTag('pricing', $pricing); $item->addTag('type', 'product'); if (null != ($manufacturer = $product->getManufacturer())) { $item->addTag('brand', $manufacturer->getName()); } if (null != ($imageInfo = $product->getImageInfo())) { $item->addTag('img', $imageInfo->getDefaultImage()); } $reviewService = $this->container->get('reviewService'); $ar = round($reviewService->getAverageRatingForProductId($product->getId(), $languageId)); $item->addTag('rating', $ar); } if ($product->hasAttributes()) { $attributes = array(); foreach ($product->getAttributes() as $attribute) { $values = array(); foreach ($attribute->getValues() as $value) { $values[] = $value->getName(); } $attributes[$attribute->getName()] = $values; } $item->addTag('attributes', $attributes); } return $item; }