Ejemplo n.º 1
0
 public function action_detail($code = null)
 {
     $this->data['product'] = Model_Base_Product::get_by_code($code, array('where' => array(array('status', '=', 1))));
     if (empty($this->data['product']['id'])) {
         Response::redirect('/');
     }
     $this->data['product']['sub_photo'] = Model_Base_Product::get_sub_photo($this->data['product']['id']);
     $category_ids = Model_Base_ProductCategory::get_by('category_id', 'product_id', $this->data['product']['id']);
     if (!empty($category_ids)) {
         $this->data['products'] = Model_Base_Product::get_by_category_ids($category_ids, 0, 5);
     }
     View::set_global('product', $this->data['product']);
     $this->template->title = 'Product List';
     $this->template->content = View::forge($this->layout . '/product/detail', $this->data);
 }
Ejemplo n.º 2
0
 public function post_update()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('id', Lang::get('label.product'), 'required|valid_product');
     $val->add_field('category_ids', Lang::get('label.category'), 'required');
     $val->add_field('product_name', Lang::get('label.product_name'), 'required|max_length[255]');
     $val->add_field('product_description', Lang::get('label.description'), 'trim|max_length[1024]');
     $val->add_field('product_info', Lang::get('label.information'), 'trim|max_length[10000]');
     if ($val->run()) {
         DB::start_transaction();
         $product_id = $val->validated('id');
         $category_ids = implode(',', $val->validated('category_ids'));
         $category_name = Model_Service_Util::mb_trim($val->validated('product_name'));
         $product_description = Model_Service_Util::mb_trim($val->validated('product_description'));
         $product_info = $val->validated('product_info');
         $product_props = array('product_name' => $category_name, 'product_description' => $product_description, 'product_info' => $product_info);
         if (Model_Base_Product::update($product_id, $product_props) && Model_Base_ProductCategory::update($product_id, $category_ids)) {
             DB::commit_transaction();
             $this->data['success'] = Lang::get($this->controller . '.' . $this->action . '.success');
         } else {
             DB::rollback_transaction();
             $this->data['error'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }