/**
  * Seed an order.
  */
 private function seedOrder()
 {
     $basket = Basket::create();
     $address = Address::create(['name' => $this->faker()->name, 'line_one' => $this->faker()->streetAddress, 'line_two' => $this->faker()->streetName, 'city' => $this->faker()->city, 'post_code' => $this->faker()->postcode, 'country_code' => $this->faker()->countryCode]);
     $basket->address()->associate($address);
     $basket->save();
     $basketItems = [];
     $this->repeat(function () use($basket, &$basketItems) {
         $basketItems[] = BasketItem::create(['basket_id' => $basket->id, 'product_option_id' => ProductOption::inRandomOrder()->first()->id]);
     }, random_int(1, 4));
     $order = Order::create();
     $order->address()->associate($address);
     $order->save();
     /** @var BasketItem $basketItem */
     foreach ($basketItems as $basketItem) {
         $stockItem = new StockItem();
         $basketItem->productOption->stockItems()->save($stockItem);
         $orderItem = OrderItem::create(['basket_item_id' => $basketItem->id, 'order_id' => $order->id, 'price' => $basketItem->priceAsFloat()]);
         $orderItem->stockItem()->save($stockItem);
     }
     Payment::create(['order_id' => $order->id, 'settlement_id' => PayPalSettlement::create(['payment_id' => $this->faker()->uuid, 'payer_id' => $this->faker()->uuid])->id, 'settlement_type' => PayPalSettlement::class]);
 }
Exemple #2
0
 /**
  * @param Settlement|Model $settlement
  *
  * @return Payment
  */
 private function paymentForSettlement(Settlement $settlement) : Payment
 {
     $payment = new Payment();
     $payment->settlement()->associate($settlement);
     return $payment;
 }