/** * Removes a product by its associated id * * @param string $id Product id * @return boolean */ private function removeById($id) { // Remove from a storage first $this->productMapper->deleteById($id); $this->imageMapper->deleteAllByProductId($id); // Now remove from the file-system $this->imageManager->delete($id); return true; }
/** * Refresh the statistic * * @return void */ private function refresh() { $ids = $this->collection->getKeys(); foreach ($ids as $id) { $valid = $this->productMapper->isPrimaryKeyValue($id); if (!$valid) { $this->removeById($id); } } }
/** * Counts amount of products associated with provided category id * * @param string $id Category id * @return integer */ public function getProductCountByCategoryId($id) { //@TODO: Add caching layer return $this->productMapper->countAllByCategoryId($id); }
/** * Fetches latest product entities * * @param integer $limit Limit for fetching * @param integer $categoryId Optionally can be filtered by category id * @return array */ public function fetchLatestPublished($limit, $categoryId = null) { return $this->prepareResults($this->productMapper->fetchLatestPublished($limit, $categoryId)); }