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); } }
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; }