コード例 #1
0
 public function addAction()
 {
     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 = new Catalog_Model_Products($dataProducts);
             //modDate, order
             $product->setMetaTitle($dataProducts['name'])->setMetaDescription($dataProducts['description'])->setMetaKeywords($dataProducts['name'])->setOrder($dataProducts['sorting'])->setActive(1)->setDeleted(0)->setAddDate(date("Y-m-d H:i:s"))->setModDate(date("Y-m-d H:i:s"));
             $this->_modelMapper->save($product);
             $productId = $this->_modelMapper->getDbTable()->getAdapter()->lastInsertId();
             $categoriesMapperXref = new Catalog_Model_Mapper_CategoriesXref();
             $categoriesMapperXref->save(new Catalog_Model_CategoriesXref(array('productId' => $productId, 'categoryId' => $this->_request->getParam('categoryId'))));
             $product = $this->_modelMapper->find($productId, $this->_model);
             $upload = new Zend_File_Transfer();
             $uploadPath = '/upload/products/' . $product->getId() . '/';
             //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);
             $url = '/catalog/' . $product->getFullPath();
         }
         $this->clearCache('CatalogProductsList');
         $this->_redirector->gotoUrlAndExit($url);
     }
     //Zend_Debug::dump($this->_request->getParams());
 }
コード例 #2
0
 public function indexAction()
 {
     $productsMapper = new Catalog_Model_Mapper_Products();
     $products = $productsMapper->fetchAll();
     $countDraft = 0;
     /** @var Catalog_Model_Products $product */
     foreach ($products as $product) {
         if (!is_null($product->getAImages())) {
             $draftImages = unserialize($product->getAImages());
             if (!empty($draftImages)) {
                 $product->setDraft($draftImages[0]);
                 $productsMapper->save($product);
             }
             $countDraft++;
         }
     }
     Zend_Debug::dump($countDraft, 'Сгенерировано чертежей: ', true);
 }
コード例 #3
0
 public function generateProductsFullPathAction()
 {
     $products = new Catalog_Model_Mapper_Products();
     $freePathProducts = $products->fetchFreeRowColumn('full_path');
     foreach ($freePathProducts as $product) {
         $product->fullPath = $products->generateFullPath($product->id);
         $mapper = new Catalog_Model_Mapper_Products();
         $mapper->save($product);
     }
     return $this->view->entries = $products->fetchFreeRowColumn('full_path');
 }
コード例 #4
0
 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);
     }
 }