コード例 #1
0
 public function editAction()
 {
     if ($this->getCurrentOptionValue()) {
         $product = new Catalog_Model_Product();
         if ($product_id = $this->getRequest()->getParam('id')) {
             $product->find($product_id);
             if ($product->getId() and $product->getValueId() != $this->getCurrentOptionValue()->getId()) {
                 throw new Exception($this->_('An error occurred while loading your product.'));
             }
         } else {
             if ($category_id = $this->getRequest()->getParam('category_id')) {
                 $category = new Catalog_Model_Category();
                 $category->find($category_id);
                 if ($category->getValueId() != $this->getCurrentOptionValue()->getId()) {
                     $category = null;
                     $category_id = Catalog_Model_Category();
                 }
                 $product->setCategory($category)->setCategoryId($category_id);
             }
         }
         $this->loadPartials(null, false);
         $this->getLayout()->getPartial('content')->setOptionValue($this->getCurrentOptionValue())->setProduct($product);
         $html = $this->getLayout()->render();
         $this->getLayout()->setHtml($html);
     }
 }
コード例 #2
0
ファイル: Category.php プロジェクト: bklein01/SiberianCMS
 public function getParent()
 {
     if (!$this->_parent) {
         $category = new Catalog_Model_Category();
         if ($this->getParentId()) {
             $category->find($this->getParentId());
         }
         $this->_parent = $category;
     }
     return $this->_parent;
 }
コード例 #3
0
 public function editpostAction()
 {
     if ($datas = $this->getRequest()->getPost()) {
         try {
             if (empty($datas['value_id'])) {
                 throw new Exception($this->_('An error occurred while saving the category. Please try again later.'));
             }
             $option_value = new Application_Model_Option_Value();
             $option_value->find($datas['value_id']);
             $html = array();
             $category = new Catalog_Model_Category();
             if (!empty($datas['category_id'])) {
                 $category->find($datas['category_id']);
             }
             $isNew = (bool) (!$category->getId());
             if ($category->getId() and $category->getValueId() != $option_value->getId()) {
                 throw new Exception($this->_('An error occurred while saving the category. Please try again later.'));
             }
             if (!isset($datas['is_active'])) {
                 $datas['is_active'] = 1;
             }
             $datas['value_id'] = $option_value->getId();
             if (!empty($datas['is_deleted']) and $category->getParentId()) {
                 foreach ($category->getProducts() as $product) {
                     $product->setCategoryId($category->getParentId())->save();
                 }
             }
             //                $category->setPosIds(!empty($datas['outlets']) ? $datas['outlets'] : array());
             $category->addData($datas);
             $category->save();
             $html = array('success' => 1, 'is_new' => (int) $isNew, 'parent_id' => $category->getParentId(), 'category_id' => $category->getId(), 'is_deleted' => $category->getIsDeleted() ? 1 : 0);
             if ($isNew) {
                 if ($category->getParentId()) {
                     $html['li_html'] = $this->getLayout()->addPartial('row', 'admin_view_default', 'catalog/application/edit/category/subcategory.phtml')->setCategory($category->getParent())->setSubcategory($category)->setOptionValue($option_value)->toHtml();
                 } else {
                     $html['category_html'] = $this->getLayout()->addPartial('row', 'admin_view_default', 'catalog/application/edit/category.phtml')->setCategory($category)->setOptionValue($option_value)->toHtml();
                 }
             }
         } catch (Exception $e) {
             $html['message'] = $e->getMessage();
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
     return $this;
 }
コード例 #4
0
ファイル: Category.php プロジェクト: bklein01/siberian_cms_2
 public function createDummyContents($option_value, $design, $category)
 {
     $option = new Application_Model_Option();
     $option->find($option_value->getOptionId());
     $dummy_content_xml = $this->_getDummyXml($design, $category);
     if ($option->getCode() == "catalog") {
         foreach ($dummy_content_xml->catalog->children() as $categories) {
             $this->unsData();
             //check si la category existe sur cette app
             $category_data = array("name" => $categories->name, "value_id" => $option_value->getId());
             $category_id = $this->find($category_data)->getCategoryId();
             if (!$category_id) {
                 $this->setName((string) $categories->name)->setValueId($option_value->getId())->save();
                 $category_id = $this->getId();
             }
             foreach ($categories->products->children() as $product) {
                 $product_model = new Catalog_Model_Product();
                 if ($product->attributes()->subcategory) {
                     $sub_category_model = new Catalog_Model_Category();
                     //check si la sous category existe sur cette app
                     $subcategory_data = array("name" => $product->attributes()->subcategory, "value_id" => $option_value->getId());
                     $sub_category_model->find($subcategory_data);
                     if (!$sub_category_model->getCategoryId()) {
                         $sub_category_model->setName($product->attributes()->subcategory)->setValueId($option_value->getId())->setParentId($category_id)->save();
                         $product_model->setCategoryId($sub_category_model->getId());
                     } else {
                         $sub_category_model->setParentId($category_id)->save();
                         $product_model->setCategoryId($sub_category_model->getId());
                     }
                 } else {
                     $product_model->setCategoryId($category_id);
                 }
                 foreach ($product->content->children() as $key => $value) {
                     $product_model->addData((string) $key, (string) $value);
                 }
                 if ($product->formats) {
                     $format_option = array();
                     foreach ($product->formats->children() as $format) {
                         foreach ($format as $key => $val) {
                             $format_option[$format->getName()][(string) $key] = (string) $val;
                         }
                     }
                     $product_model->setOption($format_option);
                 }
                 $product_model->setValueId($option_value->getId())->save();
             }
         }
     }
 }