public function editpostAction() { if ($datas = $this->getRequest()->getPost()) { try { $option_value = new Application_Model_Option_Value(); $option_value->find($datas['value_id']); $datas = $datas['menus']; foreach ($datas as $product_id => $data) { $product = new Catalog_Model_Product(); if ($id = $this->getRequest()->getParam('id')) { $product->find($id); if ($product->getValueId() != $option_value->getId()) { throw new Exception($this->_('An error occurred while saving. Please try again later.')); } } if (!$product->getId()) { $product->setValueId($option_value->getId()); } $pos_datas = array(); if (!empty($data['pos'])) { foreach ($data['pos'] as $key => $pos_data) { $pos_datas[$key] = $pos_data; } } if (!empty($data['picture'])) { if (substr($data['picture'], 0, 1) == '/') { unset($data['picture']); } else { $illus_relative_path = '/feature/' . $option_value->getValueId() . '/'; $folder = Application_Model_Application::getBaseImagePath() . $illus_relative_path; $file = Core_Model_Directory::getTmpDirectory(true) . '/' . $data['picture']; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!copy($file, $folder . $data['picture'])) { throw new exception($this->_('An error occurred while saving your picture. Please try againg later.')); } else { $data['picture'] = $illus_relative_path . $data['picture']; } } } $product->addData($data)->setType('menu'); $product->setPosDatas($pos_datas); $product->save(); } $html = array(); if (!$product->getData('is_deleted')) { $html['menu_id'] = $product->getId(); } $html['success'] = 1; $html['success_message'] = $this->_('Set meal successfully saved.'); $html['message_timeout'] = 2; $html['message_button'] = 0; $html['message_loader'] = 0; } catch (Exception $e) { $html = array('message' => $this->_('An error occurred while saving the set meal. Please try again later.')); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }
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(); } } } }
public function editpostAction() { if ($data = $this->getRequest()->getPost()) { try { if (empty($data['value_id'])) { throw new Exception($this->_('An error occurred while saving the product. Please try again later.')); } $option_value = new Application_Model_Option_Value(); $option_value->find($data['value_id']); $html = array(); $product = new Catalog_Model_Product(); if (!empty($data['product_id'])) { $product->find($data['product_id']); } $isNew = (bool) (!$product->getId()); $isDeleted = !empty($data['is_deleted']); if ($product->getId() and $product->getValueId() != $option_value->getId()) { throw new Exception($this->_('An error occurred while saving the product. Please try again later.')); } if (!$isDeleted) { if (!isset($data['is_active'])) { $data['is_active'] = 1; } $data['value_id'] = $option_value->getValueId(); $parent_id = $data['category_id']; if (!empty($data['subcategory_id'])) { $data['category_id'] = $data['subcategory_id']; } if (!empty($data['picture'])) { if (!file_exists(Core_Model_Directory::getTmpDirectory(true) . "/" . $data['picture'])) { unset($data['picture']); } else { $illus_relative_path = $option_value->getImagePathTo(); $folder = Application_Model_Application::getBaseImagePath() . $illus_relative_path; $file = pathinfo(Core_Model_Directory::getBasePathTo($data['picture'])); $filename = $file['basename']; $img_src = Core_Model_Directory::getTmpDirectory(true) . "/" . $data['picture']; $img_dst = $folder . '/' . $filename; if (!is_dir($folder)) { mkdir($folder, 0777, true); } if (!@copy($img_src, $img_dst)) { throw new exception($this->_('An error occurred while saving your picture. Please try againg later.')); } else { $data['picture'] = $illus_relative_path . '/' . $filename; } } } } if (!$product->getId() and empty($data['is_multiple']) or $product->getId() and $product->getData('type') != 'format' and isset($data['option'])) { unset($data['option']); } $product->addData($data); $product->save(); $html = array('success' => 1); if (!$isDeleted) { $product_id = $product->getId(); $product = new Catalog_Model_Product(); $product->find($product_id); $html = array('success' => 1, 'product_id' => $product->getId(), 'parent_id' => $parent_id, 'category_id' => $data['category_id']); $html['product_html'] = $this->getLayout()->addPartial('row', 'admin_view_default', 'catalog/application/edit/category/product.phtml')->setProduct($product)->setOptionValue($option_value)->toHtml(); } } catch (Exception $e) { $html['message'] = $e->getMessage(); } $this->getLayout()->setHtml(Zend_Json::encode($html)); } }