Esempio n. 1
0
 public function test_deleting_a_product_also_deletes_related_options()
 {
     $product = Factory::create(new Product());
     $product->options()->add(Factory::create(new Option()));
     $product->delete();
     $this->assertFalse(Option::where('product_id', $product->id)->exists());
 }
 /**
  * Create an inventory option and attach it to the Product
  *
  * @param  integer  $id
  * @param  string   $sessionKey
  * @return array
  */
 protected function saveOption($id, $sessionKey)
 {
     $option = Option::findOrNew($id);
     $option->product_id = $this->model->id;
     $option->name = input('name');
     $option->placeholder = input('placeholder');
     $option->validate();
     $option->bindSelections(input('selections'));
     $message = $this->getLangString($option);
     $option->save();
     $option->load('selections');
     if (!$this->model->id) {
         $this->model->options()->add($option, $sessionKey);
     }
     $name = Lang::get('bedard.shop::lang.option.resource_singular');
     Flash::success(Lang::get($message, ['name' => $name]));
     $this->prepareVars($sessionKey);
     return ['target' => $this->makePartial('options_li', ['option' => $option]), '[data-partial="inventories"]' => $this->makePartial('inventories')];
 }