public function indexAction() { $cache = Zend_Registry::get('cache'); $select = $this->_modelMapper->getDbTable()->select(); $select->order('sorting ASC'); if ($this->_request->getParam('category_id')) { $cacheName = 'Admin_CatalogProductsList_' . $this->_request->getParam('category_id'); if (!($pageItems = $cache->load($cacheName))) { $pageItems = $this->_modelCategoriesMapper->fetchProductsRel($this->_request->getParam('category_id'), $select); $cache->save($pageItems, $cacheName, array('admin', 'Catalog', 'CatalogProductsList')); } $category = $this->_modelCategoriesMapper->find($this->_request->getParam('category_id'), new Catalog_Model_Categories()); } else { $cacheName = 'Admin_CatalogProductsList_All'; if (!($pageItems = $cache->load($cacheName))) { $pageItems = $this->_modelMapper->fetchAll($select); $cache->save($pageItems, $cacheName, array('admin', 'Catalog', 'CatalogProductsList')); } } if (!empty($pageItems)) { $pageItems = $this->setPaginationPage($pageItems); } $this->view->assign('pages', $pageItems); if (isset($category)) { $this->view->categoryName = $category->getName() . ' - '; $this->view->current_category = $category->getId(); } }
/** * @param int $category_id * @param int $active * @return array */ function GetProductsCategory($category_id, $active = 0) { $categories = new Catalog_Model_Mapper_Categories(); $productsMapper = new Catalog_Model_Mapper_Products(); $select = $productsMapper->getDbTable()->select(); $select->where('active != ?', $active)->order('sorting ASC'); $entries = $categories->fetchProductsRel($category_id, $select); return $entries; }
/** * @param $id_group * @return Catalog_Model_Products[]|null */ private function _getCategoryProducts($id_group) { $cache = Zend_Registry::get('cache'); $cacheName = 'categoryProducts_' . $id_group; $select = $this->_modelProductsMapper->getDbTable()->select()->order('sorting ASC'); if (!($products = $cache->load($cacheName))) { ini_set('max_execution_time', 900); $products = $this->_modelCategoriesMapper->fetchProductsRel($id_group, $select); $cache->save($products, $cacheName, array('api', 'Catalog', 'categoryProducts')); } return $products; }
/** * @throws Zend_Controller_Action_Exception * */ public function indexAction() { $fullPath = $this->getFullPath(); $categories = new Catalog_Model_Mapper_Categories(); $category = new Catalog_Model_Categories(); $category = $categories->findByFulPath($fullPath, $category); if (is_null($category)) { throw new Zend_Controller_Action_Exception("Страница не найдена", 404); } $this->setCurrentCategory($category); $current_category_id = $category->getId(); $productsMapper = new Catalog_Model_Mapper_Products(); $select = $productsMapper->getDbTable()->select(); if (!Zend_Auth::getInstance()->hasIdentity()) { $select->where('deleted != ?', 1)->where('active != ?', 0); } $select->order('sorting ASC'); $entries = $categories->fetchProductsRel($current_category_id, $select); if (!empty($entries)) { $this->view->entries = $entries; } if ($category->getMetaDescription() != '') { $meta_description = $category->getMetaDescription(); } else { $categoryMapper = new Catalog_Model_Mapper_Categories(); $parentCategories = $categoryMapper->fetchTreeParentCategories($category->getId()); $aDescription = array(); if (!empty($parentCategories)) { foreach ($parentCategories as $parentCategory) { $aDescription[] = $parentCategory->name; } } $aDescription[] = 'Альфа-Гидро - Каталог продукции'; $meta_description = implode(", ", array_reverse($aDescription)); } if ($category->getMetaKeywords() != '') { $meta_keywords = $category->getMetaKeywords(); } else { $aKeywords = array(); if (!empty($entries)) { foreach ($entries as $propduct) { $sku = $propduct->getSku(); $aKeywords[] = str_replace('A', '', $sku); $aKeywords[] = str_replace(' ', '', $sku); $aKeywords[] = str_replace(array(' ', 'A'), '', $sku); } } $aKeywords[] = $category->getName(); $meta_keywords = implode(", ", array_reverse($aKeywords)); } $this->view->assign(array('adminPath' => 'categories/list/' . $current_category_id, 'full_path_category' => $this->getFullPath(), 'title' => $category->getName(), 'current_category' => $current_category_id, 'meta_description' => $meta_description, 'meta_keywords' => $meta_keywords)); }
public function editAction() { $categoryId = $this->_request->getParam('id'); if (is_null($categoryId)) { $this->_redirector->gotoSimpleAndExit('index'); } $category = $this->_modelMapper->find($categoryId, new Catalog_Model_Categories()); if (is_null($category)) { throw new Zend_Controller_Action_Exception("Страница не найдена", 404); } $parentCategoryId = $category->getParentId(); if ($this->_request->isPost()) { //Zend_Debug::dump($this->_request->getParams()); $url = $this->_request->getParam('currentUrl'); if ($this->_request->getParam('dataFormCategory')) { $dataCategory = $this->_request->getParam('dataFormCategory'); $category->setOptions($dataCategory); $category->setModDate(date("Y-m-d H:i:s")); $context_html = Michelf\MarkdownExtra::defaultTransform($dataCategory['contentMarkdown']); $category->setContentHtml($context_html); $parentFullPath = $this->_modelMapper->generateFullPath($dataCategory['parentId']); $fullPath = !is_null($parentFullPath) ? $parentFullPath . '/' . $category->getPath() : $category->getPath(); $category->setFullPath($fullPath); $url = '/catalog/' . $fullPath; $productsRel = $this->_modelMapper->fetchProductsRel($categoryId); if ($productsRel) { $productsMapper = new Catalog_Model_Mapper_Products(); /** @var Catalog_Model_Products $product */ foreach ($productsRel as $product) { $product->setFullPath($fullPath . '/' . $product->getPath()); $productsMapper->save($product); } } $upload = new Zend_File_Transfer(); if ($upload->isUploaded()) { $imageFile = $this->_uploadFiles($categoryId, $upload); $category->setUploadPath('/upload/categories/' . $categoryId . '/'); $category->setImage($imageFile['fileLoad']['name']); } $this->_modelMapper->save($category); } $this->clearCache('CatalogCategories'); $this->_redirector->gotoUrlAndExit($url); } }
/** * @param $category_id * @return array */ public function getProductsCategory($category_id) { $cache = Zend_Registry::get('cache'); if (!($expProducts = $cache->load('productsCategory' . $category_id))) { $expProducts = array(); $categoryMapper = new Catalog_Model_Mapper_Categories(); $productMapper = new Catalog_Model_Mapper_Products(); $selectProduct = $productMapper->getDbTable()->select()->where('deleted != ?', 1)->where('active != ?', 0)->order('sorting ASC'); $products = $categoryMapper->fetchProductsRel($category_id, $selectProduct); if (!empty($products)) { foreach ($products as $product) { $expProducts[] = array('item', 'name', 'image', 'uri', 'description', 'note'); $item = $this->productToArray($product); $expProducts[] = $item; $property = $this->productProperty_Csv($product, false); if (!empty($property)) { $expProducts[] = array('propertiesTable'); $expProducts[] = $property['name']; $expProducts[] = $property['value']; } $modifications = $this->productModificationTableValues($product, false); if (!empty($modifications)) { $expProducts[] = array('modificationsTable'); foreach ($modifications as $modification) { $expProducts[] = $modification; } } } } $cache->save($expProducts, 'productsCategory' . $category_id); } return $expProducts; }