/** * @param Order $order * * @throws \InvalidArgumentException */ private function trackOrder(Order $order) { Analytics::enableEcommerceTracking(); Analytics::ecommerceAddTransaction($order->publicId(), config('app.name'), $order->totalPrice()->asFloat(), 0.0, 0.0); $order->orderItems->each(function (OrderItem $item) { Analytics::ecommerceAddItem($item->id, $item->name(), $item->sku(), $item->category()->name, $item->priceAsFloat(), 1); }); }
/** * @param int $publicId * * @return Order */ public function byPublicId(int $publicId) : Order { /** @var Order $order */ $order = $this->orderResource->with(self::DEFAULT_RELATIONS)->where('id', '=', Order::privateId($publicId))->first(); if ($order instanceof Order) { return $order; } return new Order(); }
/** * 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]); }
/** * @throws \InvalidArgumentException * * @return TelegramMessage */ public function toTelegram() { $env = App::environment(); return TelegramMessage::create()->content(sprintf("%s\n%s", "New Order in *{$env}* {$this->order->publicId()}", "Total {$this->order->totalPrice()->formatted()}"))->button("View new order #{$this->order->publicId()}", route('orders.show', [$this->order])); }
/** * @param int $orderId * * @throws \Illuminate\Database\Eloquent\ModelNotFoundException * * @return string */ public function viewAction(int $orderId) { /** @var Order $order */ $order = $this->orderResource->with(['orderItems.basketItem.productOption.product', 'address'])->findOrFail($this->optimus->decode($orderId)); return $this->webUi->view('customer.orders.view', compact('order')); }
/** * @param BasketItem $basketItem * @param Order $order * * @throws \RuntimeException */ private function basketItemToOrderItem(BasketItem $basketItem, Order $order) { $orderItem = new OrderItem(); $orderItem->price = $basketItem->priceAsFloat(); $orderItem->basketItem()->associate($basketItem); $productOption = $basketItem->productOption; if ($productOption instanceof ProductOptionPresenter) { $productOption = $productOption->getWrappedObject(); } $stockItem = $this->inventory->allocate($productOption); if (!$stockItem->isAvailable()) { throw new StockAllocationException(sprintf('Failed to allocate stock for product option `%s`.', $basketItem->productOption->id)); } $order->orderItems()->save($orderItem); $orderItem->stockItem()->save($stockItem); }
/** * @param FunctionalTest $test * * @return Order|null */ private function orderFromPage(FunctionalTest $test) : Order { $this->orders[] = Order::where('id', '=', Order::privateId($test->getElementText('#order-id')))->first(); return end($this->orders); }