/**
  * @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 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;
 }
 /**
  * @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 $category_id
  * @return Zend_Navigation
  * @throws Zend_Navigation_Exception
  */
 public function containerNavigation($category_id)
 {
     $container = new Zend_Navigation();
     $categoriesMapper = new Catalog_Model_Mapper_Categories();
     $category = $categoriesMapper->find($category_id, new Catalog_Model_Categories());
     $i = 0;
     if ($category) {
         $container->addPage(array('type' => 'uri', 'label' => $category->getName(), 'active' => true));
     }
     $parentCategories = $categoriesMapper->fetchTreeParentCategories($category->getParentId());
     if (!empty($parentCategories)) {
         foreach ($parentCategories as $parentCategory) {
             $container->addPage(array("action" => "index", "controller" => "categories", "module" => "admin", 'order' => $i, 'route' => 'adminCategoriesEdit', "params" => array('parent_id' => $parentCategory->id != 0 ? $parentCategory->id : null), 'reset_params' => true, 'encode_url' => false, 'label' => $parentCategory->name));
             $i--;
         }
     }
     $container->addPage(new Zend_Navigation_Page_Uri(array('label' => 'Каталог', 'uri' => '/admin/categories/', 'order' => $i)));
     return $container;
 }
 /**
  * @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;
 }