public function recentlyViewedProductsAction()
 {
     $env = OnlineShop_Framework_Factory::getInstance()->getEnvironment();
     $recentlyViewed = $env->getCustomItem(self::RECENTLY_VIEWED_PRODUCTS);
     if (!$recentlyViewed) {
         $recentlyViewed = array();
     }
     $exists = false;
     if (in_array($this->_getParam('id'), $recentlyViewed)) {
         $exists = true;
     }
     if (!$exists && $this->_getParam('id')) {
         array_push($recentlyViewed, $this->_getParam('id'));
         if (count($recentlyViewed) > self::MAX_PRODUCTS + 1) {
             array_shift($recentlyViewed);
         }
     }
     $env->setCustomItem(self::RECENTLY_VIEWED_PRODUCTS, $recentlyViewed);
     $env->save();
     unset($recentlyViewed[array_search($this->_getParam('id'), $recentlyViewed)]);
     $products = array();
     foreach ($recentlyViewed as $productId) {
         $products[] = Website_DefaultProduct::getById($productId);
     }
     $this->view->products = $products;
     $this->view->currentId = htmlentities($this->_getParam("id"));
     $this->renderScript('includes/recently-viewed-products.php');
 }
Exemple #2
0
 private function getSimilarProducts(Website_DefaultProduct $product, Object_FilterDefinition $filterDefinition = null)
 {
     if ($filterDefinition) {
         $productList = OnlineShop_Framework_Factory::getInstance()->getIndexService()->getProductListForCurrentTenant();
         $productList->setVariantMode(OnlineShop_Framework_IProductList::VARIANT_MODE_INCLUDE_PARENT_OBJECT);
         $similarityFields = $filterDefinition->getSimilarityFields();
         if ($similarityFields) {
             $statement = $productList->buildSimularityOrderBy($filterDefinition->getSimilarityFields(), $product->getId());
         }
         if (!empty($statement)) {
             $productList->setLimit(2);
             $productList->setOrder("ASC");
             $productList->addCondition("o_virtualProductId != " . $product->internalGetBaseProduct()->getId(), "o_id");
             if ($filterDefinition->getCrossSellingCategory()) {
                 $productList->setCategory($filterDefinition->getCrossSellingCategory());
             }
             $productList->setOrderKey($statement);
             return $productList->load();
         }
     }
     return array();
 }