示例#1
0
 /**
  * Creates a product meta option.
  *
  * @param int $meta_id Product meta ID.
  *
  * @return void
  */
 public function post_index($meta_id = null)
 {
     $meta = $this->get_meta($meta_id);
     $validator = \Validation_Product_Meta_Option::create();
     if (!$validator->run()) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $option = \Service_Product_Meta_Option::create($data['value'], $meta);
     if (!$option) {
         throw new HttpServerErrorException();
     }
     $this->response($option);
 }
示例#2
0
 /**
  * Validates meta option data for a given action type.
  *
  * @param string $type The action to process (create, update).
  * @param array  $data The data to validate.
  *
  * @return array|bool
  */
 protected function validate_meta_option($type, $data)
 {
     if ($type == 'create') {
         $validator = Validation_Product_Meta_Option::create();
     } else {
         $validator = Validation_Product_Meta_Option::update();
     }
     if (!$validator->run($data)) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     return $validator->validated();
 }