/** * @param int $category_id * @param int $active * @return array */ function GetSubCategories($category_id, $active = 0) { $categories = new Catalog_Model_Mapper_Categories(); $select = $categories->getDbTable()->select(); $select->where('parent_id = ?', $category_id)->where('active != ?', $active)->order('sorting ASC'); $entries = $categories->fetchAll($select); return $entries; }
/** * @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 $category_id * @return array */ public function getSidebarItem($category_id) { $categories = new Catalog_Model_Mapper_Categories(); $select = $categories->getDbTable()->select(); $select->where('parent_id = ?', $category_id)->where('deleted != ?', 1)->order('sorting ASC'); if (!$this->_auth) { $select->where('active != ?', 0); } $entries = $categories->fetchAll($select); return $entries; }
/** * Ajax Data */ public function generateCategoriesFullPathAction() { $categories = new Catalog_Model_Mapper_Categories(); $freePathCategories = $categories->fetchFreeRowColumn('full_path'); foreach ($freePathCategories as $category) { $id = $category->id; $fullPath = $categories->generateFullPath($id); $category->fullPath = $fullPath; //if($this->_validateColumn($category->fullPath, 'categories', 'full_path')){ $mapper = new Catalog_Model_Mapper_Categories(); $mapper->save($category); //} } $this->view->entries = $categories->fetchFreeRowColumn('full_path'); }
/** * @param $id * @return int */ protected function _countSubCategories($id) { $select = $this->_modelMapper->getDbTable()->select(); $select->where('parent_id = ?', $id)->order('sorting ASC'); $entries = $this->_modelMapper->fetchAll($select); return count($entries); }
/** * @param $id * @return array * @throws Zend_Exception */ public function getAllProductsCategory($id) { $cache = Zend_Registry::get('cache'); if (!($products = $cache->load('productsCategoryObj' . $id))) { $products = $this->_categoriesModelMapper->fetchAllProductsCategory($id); $cache->save($products, 'productsCategoryObj' . $id, array('productsCategoryObj')); } return $products; }
public function init() { $this->_pagesMapper = new Pages_Model_Mapper_Pages(); $this->_redirector = $this->_helper->getHelper('Redirector'); $this->_auth = Zend_Auth::getInstance()->hasIdentity(); $this->_page = $this->pageModule(); $this->view->meta_title = !$this->_page->getMetaTitle() ? $this->_page->getTitle() : $this->_page->getMetaTitle(); $this->view->meta_description = !$this->_page->getMetaDescription() ? 'Альфа-Гидро - Каталог продукции: Гидравлическое оборудование, гидрокомпоненты, рукава высокого давления, шланги, втулки и фитинги, защита для шлангов, БРС, скобы, трубы, соединительная арматура, краны, манометры, уплотнительная техника.' : $this->_page->getMetaDescription(); $this->view->meta_keywords = !$this->_page->getMetaKeywords() ? 'каталог, оборудование, гидрокомпоненты, РВД, шланги, втулки, фитинги, защита для шлангов, БРС, скобы, трубы, арматура, краны, манометры, уплотнители.' : $this->_page->getMetaKeywords(); $this->view->adminPath = 'categories'; $categories = new Catalog_Model_Mapper_Categories(); $select = $categories->getDbTable()->select(); $select->where('parent_id = ?', 0)->where('deleted != ?', 1)->order('sorting ASC'); if (!$this->_auth) { $select->where('active != ?', 0); } $entries = $categories->fetchAll($select); $this->view->entries = $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; }
/** * @param $id * @param bool $full * @return array */ public function breadcrumbs($id, $full = false) { $entries = $this->_modelCategoriesMapper->fetchTreeParentCategories($id); $breadcrumbs = array(); foreach ($entries as $entry) { $breadcrumbs[] = $entry->name; } if (!empty($breadcrumbs) && !$full) { array_shift($breadcrumbs); } $treeCategories = array('breadcrumbs' => implode(" > ", array_reverse($breadcrumbs))); return $treeCategories; }
public function sidebarHeading(Catalog_Model_Categories $category = null) { $html = '<li class="list-group-item sidebar-heading">'; if (!is_null($category)) { $html .= '<span class="badge"><i class="fa fa-level-up fa-fw"></i></span>'; $categories = new Catalog_Model_Mapper_Categories(); $parent_id = 0; if ($parentCategory = $categories->find($category->getParentId(), new Catalog_Model_Categories())) { $parent_id = $parentCategory->getId(); } $url = '/catalog/'; $textLink = 'Каталог'; if ($parent_id != 0) { $url .= $parentCategory->getFullPath() . '/'; $textLink = $parentCategory->getName(); } $html .= '<a href="' . $url . '">' . $textLink . '</a>'; } else { $html .= 'Каталог'; } $html .= '</li>'; return $html; }
public function genBreadcrumbs() { $breadcrumbs = new Zend_Navigation(); $categoriesMapper = new Catalog_Model_Mapper_Categories(); $category = $this->getCategoryId() ? $categoriesMapper->find($this->getCategoryId(), new Catalog_Model_Categories()) : null; $i = 0; if (isset($category) && is_null($this->getProductId())) { $breadcrumbs->addPage(array('type' => 'uri', 'label' => $category->getName(), 'active' => true)); } $parentCategories = $categoriesMapper->fetchTreeParentCategories($category->getParentId()); if (!is_null($this->getProductId())) { $parentCategories = $categoriesMapper->fetchTreeParentCategories($this->getCategoryId()); } if (!empty($parentCategories)) { foreach ($parentCategories as $parentCategory) { $breadcrumbs->addPage(array("action" => "index", "controller" => "categories", "module" => "catalog", 'order' => $i, 'route' => 'catalog', "params" => array('fullPath' => $parentCategory->id != 0 ? $parentCategory->full_path : null), 'reset_params' => true, 'encode_url' => false, 'label' => $parentCategory->name)); $i--; } } $breadcrumbs->addPage(new Zend_Navigation_Page_Uri(array('label' => 'Каталог', 'uri' => '/catalog/', 'order' => $i))); $breadcrumbs->addPage(new Zend_Navigation_Page_Uri(array('label' => 'Главная', 'uri' => '/', 'order' => $i - 1))); return $breadcrumbs; }
public function redirectCatalogItem($item) { $category_id = $item['category_id']; $product_id = $item['product_id']; $fullPath = ''; if (!is_null($category_id)) { $categoryMapper = new Catalog_Model_Mapper_Categories(); $category = $categoryMapper->find($category_id, new Catalog_Model_Categories()); if (!is_null($category)) { $fullPath = $category->getFullPath() . '/'; } } if (!is_null($product_id)) { $productMapper = new Catalog_Model_Mapper_Products(); $product = $productMapper->find($product_id, new Catalog_Model_Products()); if (!is_null($product)) { $fullPath = $product->getFullPath() . '/'; } } $url = '/catalog/' . $fullPath; Zend_Controller_Front::getInstance()->getResponse()->setRedirect($url, 301); return; }
/** * @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; }
/** * @throws Zend_Controller_Action_Exception * */ public function viewAction() { $fullPath = $this->getFullPath(); $products = new Catalog_Model_Mapper_Products(); $product = new Catalog_Model_Products(); $product = $products->findByFulPath($fullPath, $product); if (is_null($product)) { throw new Zend_Controller_Action_Exception("Страница не найдена", 404); } if (!is_null($this->getRequest()->getParam('json')) && Zend_Auth::getInstance()->hasIdentity()) { $this->forward('json', 'products', 'admin', array('id' => $product->getId())); return; } $categoryRel = $products->findCategoryRel($product->getId(), new Catalog_Model_Categories()); $this->setCurrentCategory($categoryRel); if ($product->getDeleted() != '0') { if (!Zend_Auth::getInstance()->hasIdentity()) { throw new Zend_Controller_Action_Exception("Страница не найдена", 404); } $this->_redirector->gotoRouteAndExit(array('module' => 'admin', 'controller' => 'categories', 'action' => 'list', 'id' => $categoryRel->getId()), 'adminEdit', true); } $this->view->draftImage = $product->getDraft(); if (!is_null($product->getAImages())) { $draftImages = unserialize($product->getAImages()); if (!empty($draftImages)) { $this->view->draftImage = $draftImages[0]; } } $productsParams = new Catalog_Model_Mapper_ProductParams(); $select = $productsParams->getDbTable()->select()->order('order ASC'); $productProrerty = $products->findProductParams($product->getId(), $select); if (!empty($productProrerty)) { $this->view->productProperty = $productProrerty; } $subproducts = new Catalog_Model_Mapper_Subproducts(); $select = $subproducts->getDbTable()->select()->where('deleted != ?', 1)->order('order ASC'); $modifications = $products->findSubproductsRel($product->getId(), $select); if (!empty($modifications)) { $this->view->modificationsTableValues = $this->modificationsTableValues($modifications); $this->view->modifications = $modifications; } $subproductParams = new Catalog_Model_Mapper_SubproductParams(); $select = $subproductParams->getDbTable()->select()->order('order ASC'); $subproductProperty = $products->findSubproductParams($product->getId(), $select); if (!empty($subproductProperty)) { $this->view->assign('subproductProperty', $subproductProperty); } if ($product->getMetaDescription() != '') { $meta_description = $product->getMetaDescription(); } else { $categoryMapper = new Catalog_Model_Mapper_Categories(); $parentCategories = $categoryMapper->fetchTreeParentCategories($categoryRel->getId()); $aDescription = array(); $aDescription[] = $product->getName(); if (!empty($parentCategories)) { foreach ($parentCategories as $parentCategory) { $aDescription[] = $parentCategory->name; } } $aDescription[] = 'Альфа-Гидро - Каталог продукции'; $meta_description = implode(", ", array_reverse($aDescription)); } if ($product->getMetaKeywords() != '') { $meta_keywords = $product->getMetaKeywords(); } else { $aKeywords = array(); if (!empty($modifications)) { /**@var $modification Catalog_Model_Subproducts*/ foreach ($modifications as $modification) { $sku = $modification->getSku(); $aKeywords[] = str_replace('A', '', $sku); $aKeywords[] = str_replace(' ', '', $sku); $aKeywords[] = str_replace(array(' ', 'A'), '', $sku); } } $aKeywords[] = $product->getSku(); $aKeywords[] = $product->getName(); $meta_keywords = implode(", ", array_reverse($aKeywords)); } $this->view->assign(array('current_category' => $categoryRel->getId(), 'product' => $product, 'title' => $this->transformSku($product->getSku()), 'secondaryHeader' => $product->getName(), 'adminPath' => 'categories/list/' . $categoryRel->getId(), 'meta_description' => $meta_description, 'meta_keywords' => $meta_keywords)); if ($product->getActive() != '1' && !Zend_Auth::getInstance()->hasIdentity()) { $this->view->assign(array('breadcrumbs' => true, 'sidebar_headers' => true)); throw new Zend_Controller_Action_Exception("Товар временно не доступен", 403); } if (Zend_Auth::getInstance()->hasIdentity()) { $this->_request->setParams(array('dataItem' => array('controller' => 'products', 'id' => $product->getId(), 'active' => $product->getActive(), 'deleted' => $product->getDeleted()))); } }
/** * @param Catalog_Model_Categories $category * @return mixed|string */ public function setMetaDescription(Catalog_Model_Categories $category) { 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)); } return $meta_description; }