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'); }
/** * show product detail page * @throws Zend_Controller_Router_Exception */ public function detailAction() { $this->enableLayout(); // load product $product = Website_DefaultProduct::getById($this->getParam("product")); if (!$product || !$product->isActive()) { throw new Zend_Controller_Router_Exception("die gewünschte Seite existiert nicht mehr"); } $this->view->product = $product; $category = Object_ProductCategory::getById($this->getParam("category")); // recently viewed products $recently = new Website_OnlineShop_Demo_OnlineShop_RecentlyViewedProducts(OnlineShop_Framework_Factory::getInstance()->getEnvironment(), function ($id) { return Website_DefaultProduct::getById($id); }); $sizeVariants = $product->getSizeVariants(); if (empty($sizeVariants)) { $linkProduct = $product; } else { $linkProduct = array_shift(array_values($sizeVariants)); } $this->view->recentlyViewed = $recently->addProduct($linkProduct)->getProducts(4); $filterdefinition = null; if ($category) { $filterdefinition = $category->getFilterdefinition(); } if (empty($filterdefinition)) { $filterdefinition = Pimcore_Config::getWebsiteConfig()->fallbackFilterdefinition; } $this->view->similarProducts = $this->getSimilarProducts($product, $filterdefinition); }