示例#1
0
 /**
  * Updates a product meta.
  *
  * @param int $product_id Product ID.
  * @param int $id         Product meta ID.
  *
  * @return void
  */
 public function put_index($product_id = null, $id = null)
 {
     $product = $this->get_product($product_id);
     $meta = $this->get_meta($id, $product);
     $validator = \Validation_Product_Meta::update();
     if (!$validator->run(\Input::put())) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $meta = \Service_Product_Meta::update($meta, $data);
     if (!$meta) {
         throw new HttpServerErrorException();
     }
     $this->response($meta);
 }
示例#2
0
 /**
  * POST Edit action.
  *
  * @param int $product_id Product ID.
  * @param int $id         Product meta ID.
  *
  * @return void
  */
 public function post_edit($product_id = null, $id = null)
 {
     $this->get_edit($product_id, $id);
     $validator = Validation_Product_Meta::update();
     if (!$validator->run()) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     $product = $this->get_product($product_id);
     $meta = $this->get_meta($id);
     $data = $validator->validated();
     if (!Service_Product_Meta::update($meta, $data)) {
         Session::set_alert('error', 'There was an error updating the product meta.');
         return;
     }
     $options = $meta->options;
     foreach (array_filter(Input::post('value')) as $option_id => $value) {
         if ($option = Arr::get($options, $option_id)) {
             // Update existing meta option.
             if (!($data = $this->validate_meta_option('update', array('value' => $value)))) {
                 return;
             }
             $option = Service_Product_Meta_Option::update($option, $data);
         } else {
             // Create new meta option.
             if (!($data = $this->validate_meta_option('create', array('value' => $value)))) {
                 return;
             }
             $option = Service_Product_Meta_Option::create($data['value'], $meta);
         }
         if (!$option) {
             Session::set_alert('error', 'There was an error updating the product meta option(s).');
             return;
         }
     }
     Session::set_alert('success', 'The product meta has been updated.');
     Response::redirect($product->link('metas'));
 }