Ejemplo n.º 1
0
 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));
     }
 }
Ejemplo n.º 2
0
 public function findallAction()
 {
     if ($value_id = $this->getRequest()->getParam('value_id')) {
         $data = array("collection" => array());
         $menu = new Catalog_Model_Product();
         $offset = $this->getRequest()->getParam('offset', 0);
         $menus = $menu->findAll(array('value_id' => $value_id, 'type' => 'menu'), array(), array("offset" => $offset, "limit" => Catalog_Model_Product::DISPLAYED_PER_PAGE));
         foreach ($menus as $menu) {
             switch ($this->getCurrentOptionValue()->getLayoutId()) {
                 case 2:
                 case 3:
                     $data["collection"][] = array("title" => $menu->getName(), "subtitle" => $menu->getFormattedPrice(), "picture" => $menu->getThumbnailUrl(), "url" => $this->getPath("catalog/mobile_setmeal_view", array("value_id" => $value_id, "set_meal_id" => $menu->getId())));
                     break;
                 case 1:
                 default:
                     $data["collection"][] = array("title" => $menu->getName(), "subtitle" => $menu->getConditions(), "picture" => $menu->getThumbnailUrl(), "url" => $this->getPath("catalog/mobile_setmeal_view", array("value_id" => $value_id, "set_meal_id" => $menu->getId())));
                     break;
             }
         }
         $data["page_title"] = $this->getCurrentOptionValue()->getTabbarName();
         $data["displayed_per_page"] = Catalog_Model_Product::DISPLAYED_PER_PAGE;
         $this->_sendHtml($data);
     }
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 public function loadProducts()
 {
     $product = new Catalog_Model_Product();
     $products = $product->findByCategory($this->getId());
     foreach ($products as $product) {
         $this->_products[$product->getId()] = $product;
     }
     return $this;
 }
Ejemplo n.º 5
0
 public function sortproductsAction()
 {
     if ($rows = $this->getRequest()->getParam('product')) {
         $html = array();
         try {
             if (!$this->getCurrentOptionValue()) {
                 throw new Exception('Une erreur est survenue lors de la sauvegarde.');
             }
             $product = new Catalog_Model_Product();
             $products = $product->findByValueId($this->getCurrentOptionValue()->getId());
             $product_ids = array();
             foreach ($products as $product) {
                 $product_ids[] = $product->getId();
             }
             foreach ($rows as $key => $row) {
                 if (!in_array($row, $product_ids)) {
                     throw new Exception($this->_('An error occurred while saving. One of your products could not be identified.'));
                 }
             }
             $product->updatePosition($rows);
             $html = array('success' => 1);
         } catch (Exception $e) {
             $html = array('message' => $e->getMessage());
         }
         $this->getLayout()->setHtml(Zend_Json::encode($html));
     }
 }