public function getProduct() { if (is_null($this->_product) and $id = $this->getRequest()->getParam('id')) { $product = new Catalog_Model_Product(); $product->find($id); $this->_product = $product; } return $this->_product; }
public function findAction() { if ($value_id = $this->getRequest()->getParam('value_id') and $set_meal_id = $this->getRequest()->getParam('set_meal_id')) { $set_meal = new Catalog_Model_Product(); $set_meal->find($set_meal_id); $option_value = $this->getCurrentOptionValue(); $data = array(); if ($set_meal->getData("type") == "menu") { $data = array("name" => $set_meal->getName(), "conditions" => $set_meal->getConditions(), "description" => $set_meal->getDescription(), "price" => $set_meal->getPrice() > 0 ? $set_meal->getFormattedPrice() : null, "picture" => $set_meal->getPictureUrl(), "social_sharing_active" => $option_value->getSocialSharingIsActive()); } $this->_sendHtml($data); } }
public function findAction() { if ($value_id = $this->getRequest()->getParam('value_id') and $product_id = $this->getRequest()->getParam('product_id')) { $product = new Catalog_Model_Product(); $product->find($product_id); $option_value = $this->getCurrentOptionValue(); $data = array(); if ($product->getData("type") != "menu") { $format = array(); if ($product->getData("type") == "format") { foreach ($product->getType()->getOptions() as $option) { $format[] = array("id" => $option->getId(), "title" => $option->getTitle(), "price" => $option->getFormattedPrice()); } } $data = array("name" => $product->getName(), "conditions" => $product->getConditions(), "description" => $product->getDescription(), "price" => $product->getPrice() > 0 ? $product->getFormattedPrice() : null, "picture" => $product->getPictureUrl(), "formats" => $format, "social_sharing_active" => $option_value->getSocialSharingIsActive()); } $this->_sendHtml($data); } }
public function viewAction() { try { $product = new Catalog_Model_Product(); $product->find($this->getRequest()->getParam('product_id')); if (!$product->getId() or $product->getValueId() != $this->getCurrentOptionValue()->getId()) { throw new Exception($this->_('An error occurred while loading your product.')); } $option = $this->getCurrentOptionValue(); $this->loadPartials($this->getFullActionName('_') . '_l' . $this->_layout_id, false); $this->getLayout()->getPartial('content')->setCurrentProduct($product); $html = array('html' => $this->getLayout()->render(), 'title' => $option->getTabbarName()); if ($url = $option->getBackgroundImageUrl()) { $html['background_image_url'] = $url; } $html['use_homepage_background_image'] = (int) $option->getUseHomepageBackgroundImage() && !$option->getHasBackgroundImage(); $html = array_merge($html, array('next_button_title' => $this->_('Cart'), 'next_button_arrow_is_visible' => 1)); } catch (Exception $e) { $html = array('message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($html)); }
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)); } }
public function deletepostAction() { $id = $this->getRequest()->getParam("id"); $html = ''; try { $menu = new Catalog_Model_Product(); $menu->find($id)->delete(); $html = array('menu_id' => $id, 'success' => 1, 'success_message' => $this->_('Set meal successfully deleted.'), 'message_timeout' => 2, 'message_button' => 0, 'message_loader' => 0); } catch (Exception $e) { $html = array('message' => $e->getMessage()); } $this->getLayout()->setHtml(Zend_Json::encode($html)); }