Пример #1
0
 /**
  * Creates a product meta.
  *
  * @param int $product_id Product ID.
  *
  * @return void
  */
 public function post_index($product_id = null)
 {
     $product = $this->get_product($product_id);
     $validator = \Validation_Product_Meta::create();
     if (!$validator->run()) {
         throw new HttpBadRequestException($validator->errors());
     }
     $data = $validator->validated();
     $meta = \Service_Product_Meta::create($data['name'], $product, $data);
     if (!$meta) {
         throw new HttpServerErrorException();
     }
     $this->response($meta);
 }
Пример #2
0
 /**
  * POST Create action.
  *
  * @param int $product_id Product ID the new meta should belong to.
  *
  * @return void
  */
 public function post_create($product_id = null)
 {
     $this->get_create($product_id);
     $validator = Validation_Product_Meta::create();
     if (!$validator->run()) {
         Session::set_alert('error', __('form.error'));
         $this->view->errors = $validator->error();
         return;
     }
     $product = $this->get_product($product_id);
     $data = $validator->validated();
     if (!($meta = Service_Product_Meta::create($data['name'], $product))) {
         Session::set_alert('error', 'There was an error adding the product meta.');
         return;
     }
     foreach (array_filter(Input::post('value')) as $value) {
         if (!($data = $this->validate_meta_option('create', array('value' => $value)))) {
             return;
         }
         Service_Product_Meta_Option::create($data['value'], $meta);
     }
     Session::set_alert('success', 'The product meta has been added.');
     Response::redirect($product->link('metas'));
 }