public function indexAction()
 {
     $select = $this->_categoriesModelMapper->getDbTable()->select()->where('parent_id = ?', 0)->where('active = ?', 1)->where('generate = ?', 1)->order('sorting ASC');
     $categories = $this->_categoriesModelMapper->fetchAll($select);
     $this->view->categories = $categories;
     $request = $this->getRequest();
     $category_id = $request->getParam('category_id');
     $category = $this->_categoriesModelMapper->find($category_id, new Catalog_Model_Categories());
     $expArrayCsv = $this->expArrayForCsv($category_id);
     $this->fileToCsv('./tmp/' . $category->getPath() . '.csv', $expArrayCsv);
     $this->view->array = $expArrayCsv;
 }
 public function init()
 {
     //        Zend_Debug::dump($this->_request->getParams());
     $categories = new Catalog_Model_Mapper_Categories();
     $this->_current_category_id = $this->_getParam('category');
     if (!is_null($this->_getParam('headers'))) {
         $this->setShowHeaders($this->_getParam('headers'));
     }
     $this->view->headers = $this->getShowHeaders();
     if ($this->getCurrentCategoryId() != 0) {
         $this->_current_category = $categories->find($this->getCurrentCategoryId(), new Catalog_Model_Categories());
         $this->_parent_category = $categories->find($this->_current_category->getParentId(), new Catalog_Model_Categories());
     }
     $this->_auth = Zend_Auth::getInstance()->hasIdentity();
 }
 public function editAction()
 {
     //Zend_Debug::dump($this->_request->getParams());
     $productId = $this->_request->getParam('id');
     if (is_null($productId)) {
         $this->_redirector->gotoSimpleAndExit('index');
     }
     $product = $this->_modelMapper->find($productId, new Catalog_Model_Products());
     if ($this->_request->isPost()) {
         $url = $this->_request->getParam('currentUrl');
         if ($this->_request->getParam('dataFormProducts')) {
             $dataProducts = $this->_request->getParam('dataFormProducts');
             //основные - sku, name, description, note, sorting, path
             $product->setOptions($dataProducts);
             //modDate, order
             $product->setModDate(date("Y-m-d H:i:s"));
             $product->setOrder($dataProducts['sorting']);
             //fullPath, categoryId в category_xref
             $categoryId = $this->_request->getParam('categoryId');
             $category = $this->_modelCategoriesMapper->find($categoryId, new Catalog_Model_Categories());
             if ($category) {
                 $fullPath = $category->getFullPath() . '/' . $dataProducts['path'];
                 $product->setFullPath($fullPath);
                 $categoriesXrefMapper = new Catalog_Model_Mapper_CategoriesXref();
                 $oldCategory = $this->_modelMapper->findCategoryRel($productId, new Catalog_Model_Categories());
                 $categoriesXref = $categoriesXrefMapper->find($productId, $oldCategory->getId(), new Catalog_Model_CategoriesXref());
                 $categoriesXref->setCategoryId($categoryId);
                 $categoriesXrefMapper->updateByProductId($categoriesXref);
                 $url = '/catalog/' . $fullPath;
             }
             $upload = new Zend_File_Transfer();
             $uploadPath = '/upload/products/' . $productId . '/';
             //image
             if ($upload->isUploaded('fileLoadImage')) {
                 $imageFile = $this->_uploadFiles($productId, $upload, 'fileLoadImage');
                 $product->setUploadPath($uploadPath)->setImage($imageFile['fileLoadImage']['name']);
             }
             //draft
             if ($upload->isUploaded('fileLoadDraft')) {
                 $imageFile = $this->_uploadFiles($productId, $upload, 'fileLoadDraft');
                 $product->setUploadPathDraft($uploadPath)->setDraft($imageFile['fileLoadDraft']['name']);
             }
             $this->_modelMapper->save($product);
             /*Zend_Debug::dump($upload->isUploaded('fileLoadImage'));
               Zend_Debug::dump($upload->isUploaded('fileLoadDraft'));*/
         }
         //Zend_Debug::dump($product);
         $this->_redirector->gotoUrlAndExit($url);
     }
 }
 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;
 }
Пример #6
0
 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 $id
  * @param $treeCategories
  * @return array
  */
 public function getTopElementsGroup($id, &$treeCategories)
 {
     $group = $this->_modelCategoriesMapper->find($id, new Catalog_Model_Categories());
     return $result = array('id' => $id, 'nm' => $group->getName(), 'el' => $this->getElementsGroup($treeCategories));
 }
 /**
  * @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;
 }