/** * Builds an instance * * @param \Shop\Service\ProductManagerInterface $productManager * @param \Krystal\Http\PersistentStorageInterface $storage * @param \Krystal\Stdlib\VirtualEntity $config * @return \Shop\Service\RecentProduct */ public static function build(ProductManagerInterface $productManager, PersistentStorageInterface $storage, VirtualEntity $config) { $amount = (int) $config->getMaxRecentAmount(); $tool = new CsvLimitedTool(null, $amount + 1); $rp = new RecentProduct($productManager, $tool, $storage); $rp->load(); return $rp; }
/** * Returns an array of entities of recent products * * @param string $id Current product id to be excluded * @return array */ public function getRecentProducts($id) { // Since the method is usually gets called twice, it would make sense to cache its calls static $result = null; if ($result === null) { if ($this->config->getMaxRecentAmount() > 0) { $result = $this->recentProduct->getWithRecent($id); } else { // If that functionality is disabled, then dummy empty array is used instead $result = array(); } } return $result; }