Ejemplo n.º 1
0
 /** @test */
 function an_order_consists_of_products()
 {
     $order = new Order();
     $product = new Product('Fallout 4', 59);
     $product2 = new Product('pillowcase', 7);
     $order->add($product);
     $order->add($product2);
     $this->assertCount(2, $order->products());
 }
Ejemplo n.º 2
0
 public function finalizarCompra(Request $request)
 {
     $order = new Order();
     $order->payment_method = 'visa';
     $order->order_date = $now = date('Y-m-d H:i:s', strtotime('now'));
     $order->source_name = $request['source_name'];
     $order->source_address = $request['source_address'];
     $order->source_email = $request['source_email'];
     $order->amount = $request['amount'];
     $order->save();
     $order->products()->attach($request->session()->get('Product'));
     $request->session()->flush();
     return view('orders.finalizar_compra', ['personal_info' => $request, 'order_date' => $now, 'order_id' => $order->id]);
 }
 /**
  * Remove the specified resource from storage.
  * order product
  * @param  int  $id
  * @return Response
  */
 public function destroy(Order $order, Product $product)
 {
     DB::transaction(function () use($product, $order) {
         if ($order->status != 1) {
             $product->update(['quantity' => $product->quantity + $order->products()->find($product->id)->pivot->quantity]);
         }
         $order->products()->detach($product->id);
     });
     return redirect(route('orders.edit', $order->id));
 }