From 7de4c7ff00a2b8ec74ca029bfa9d81cac1b6e147 Mon Sep 17 00:00:00 2001 From: Annika Wolff Date: Thu, 20 Aug 2020 13:31:35 +0200 Subject: [PATCH] minor expansion of api return data --- .../API/Http/Resources/Checkout/Cart.php | 106 +++++++++--------- .../Webkul/API/Http/Resources/Sales/Order.php | 2 +- .../API/Http/Resources/Sales/OrderItem.php | 4 +- 3 files changed, 59 insertions(+), 53 deletions(-) diff --git a/packages/Webkul/API/Http/Resources/Checkout/Cart.php b/packages/Webkul/API/Http/Resources/Checkout/Cart.php index 7b6ca3b56..fa0a67cf9 100644 --- a/packages/Webkul/API/Http/Resources/Checkout/Cart.php +++ b/packages/Webkul/API/Http/Resources/Checkout/Cart.php @@ -5,71 +5,75 @@ namespace Webkul\API\Http\Resources\Checkout; use Illuminate\Http\Resources\Json\JsonResource; use Webkul\API\Http\Resources\Core\Channel as ChannelResource; use Webkul\API\Http\Resources\Customer\Customer as CustomerResource; +use Webkul\Tax\Helpers\Tax; class Cart extends JsonResource { /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request + * @param \Illuminate\Http\Request + * * @return array */ - public function toArray($request) + public function toArray($request): array { - $taxes = \Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($this, false); - $baseTaxes = \Webkul\Tax\Helpers\Tax::getTaxRatesWithAmount($this, true); + $taxes = Tax::getTaxRatesWithAmount($this, false); + $baseTaxes = Tax::getTaxRatesWithAmount($this, true); $formatedTaxes = $this->formatTaxAmounts($taxes, false); $formatedBaseTaxes = $this->formatTaxAmounts($baseTaxes, true); return [ - 'id' => $this->id, - 'customer_email' => $this->customer_email, - 'customer_first_name' => $this->customer_first_name, - 'customer_last_name' => $this->customer_last_name, - 'shipping_method' => $this->shipping_method, - 'coupon_code' => $this->coupon_code, - 'is_gift' => $this->is_gift, - 'items_count' => $this->items_count, - 'items_qty' => $this->items_qty, - 'exchange_rate' => $this->exchange_rate, - 'global_currency_code' => $this->global_currency_code, - 'base_currency_code' => $this->base_currency_code, - 'channel_currency_code' => $this->channel_currency_code, - 'cart_currency_code' => $this->cart_currency_code, - 'grand_total' => $this->grand_total, - 'formated_grand_total' => core()->formatPrice($this->grand_total, $this->cart_currency_code), - 'base_grand_total' => $this->base_grand_total, - 'formated_base_grand_total' => core()->formatBasePrice($this->base_grand_total), - 'sub_total' => $this->sub_total, - 'formated_sub_total' => core()->formatPrice($this->sub_total, $this->cart_currency_code), - 'base_sub_total' => $this->base_sub_total, - 'formated_base_sub_total' => core()->formatBasePrice($this->base_sub_total), - 'tax_total' => $this->tax_total, - 'formated_tax_total' => core()->formatPrice($this->tax_total, $this->cart_currency_code), - 'base_tax_total' => $this->base_tax_total, - 'formated_base_tax_total' => core()->formatBasePrice($this->base_tax_total), - 'discount' => $this->discount_amount, - 'formated_discount' => core()->formatPrice($this->discount_amount, $this->cart_currency_code), - 'base_discount' => $this->base_discount_amount, - 'formated_base_discount' => core()->formatBasePrice($this->base_discount_amount), - 'checkout_method' => $this->checkout_method, - 'is_guest' => $this->is_guest, - 'is_active' => $this->is_active, - 'conversion_time' => $this->conversion_time, - 'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)), - 'channel' => $this->when($this->channel_id, new ChannelResource($this->channel)), - 'items' => CartItem::collection($this->items), - 'selected_shipping_rate' => new CartShippingRate($this->selected_shipping_rate), - 'payment' => new CartPayment($this->payment), - 'billing_address' => new CartAddress($this->billing_address), - 'shipping_address' => new CartAddress($this->shipping_address), - 'created_at' => $this->created_at, - 'updated_at' => $this->updated_at, - 'taxes' => json_encode($taxes, JSON_FORCE_OBJECT), - 'formated_taxes' => json_encode($formatedTaxes, JSON_FORCE_OBJECT), - 'base_taxes' => json_encode($baseTaxes, JSON_FORCE_OBJECT), - 'formated_base_taxes' => json_encode($formatedBaseTaxes, JSON_FORCE_OBJECT), + 'id' => $this->id, + 'customer_email' => $this->customer_email, + 'customer_first_name' => $this->customer_first_name, + 'customer_last_name' => $this->customer_last_name, + 'shipping_method' => $this->shipping_method, + 'coupon_code' => $this->coupon_code, + 'is_gift' => $this->is_gift, + 'items_count' => $this->items_count, + 'items_qty' => $this->items_qty, + 'exchange_rate' => $this->exchange_rate, + 'global_currency_code' => $this->global_currency_code, + 'base_currency_code' => $this->base_currency_code, + 'channel_currency_code' => $this->channel_currency_code, + 'cart_currency_code' => $this->cart_currency_code, + 'grand_total' => $this->grand_total, + 'formated_grand_total' => core()->formatPrice($this->grand_total, $this->cart_currency_code), + 'base_grand_total' => $this->base_grand_total, + 'formated_base_grand_total' => core()->formatBasePrice($this->base_grand_total), + 'sub_total' => $this->sub_total, + 'formated_sub_total' => core()->formatPrice($this->sub_total, $this->cart_currency_code), + 'base_sub_total' => $this->base_sub_total, + 'formated_base_sub_total' => core()->formatBasePrice($this->base_sub_total), + 'tax_total' => $this->tax_total, + 'formated_tax_total' => core()->formatPrice($this->tax_total, $this->cart_currency_code), + 'base_tax_total' => $this->base_tax_total, + 'formated_base_tax_total' => core()->formatBasePrice($this->base_tax_total), + 'discount' => $this->discount_amount, + 'formated_discount' => core()->formatPrice($this->discount_amount, $this->cart_currency_code), + 'base_discount' => $this->base_discount_amount, + 'formated_base_discount' => core()->formatBasePrice($this->base_discount_amount), + 'checkout_method' => $this->checkout_method, + 'is_guest' => $this->is_guest, + 'is_active' => $this->is_active, + 'conversion_time' => $this->conversion_time, + 'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)), + 'channel' => $this->when($this->channel_id, new ChannelResource($this->channel)), + 'items' => CartItem::collection($this->items), + 'selected_shipping_rate' => new CartShippingRate($this->selected_shipping_rate), + 'payment' => new CartPayment($this->payment), + 'billing_address' => new CartAddress($this->billing_address), + 'shipping_address' => new CartAddress($this->shipping_address), + 'created_at' => $this->created_at, + 'updated_at' => $this->updated_at, + 'taxes' => json_encode($taxes, JSON_FORCE_OBJECT), + 'formated_taxes' => json_encode($formatedTaxes, JSON_FORCE_OBJECT), + 'base_taxes' => json_encode($baseTaxes, JSON_FORCE_OBJECT), + 'formated_base_taxes' => json_encode($formatedBaseTaxes, JSON_FORCE_OBJECT), + 'formated_discounted_sub_total' => core()->formatPrice($this->sub_total - $this->discount_amount, $this->cart_currency_code), + 'formated_base_discounted_sub_total' => core()->formatPrice($this->base_sub_total - $this->base_discount_amount, $this->cart_currency_code), ]; } diff --git a/packages/Webkul/API/Http/Resources/Sales/Order.php b/packages/Webkul/API/Http/Resources/Sales/Order.php index 16aeed1ba..b9d4adc26 100644 --- a/packages/Webkul/API/Http/Resources/Sales/Order.php +++ b/packages/Webkul/API/Http/Resources/Sales/Order.php @@ -19,6 +19,7 @@ class Order extends JsonResource { return [ 'id' => $this->id, + 'increment_id' => $this->increment_id, 'status' => $this->status, 'status_label' => $this->status_label, 'channel_name' => $this->channel_name, @@ -103,7 +104,6 @@ class Order extends JsonResource 'items' => OrderItem::collection($this->items), 'invoices' => Invoice::collection($this->invoices), 'shipments' => Shipment::collection($this->shipments), - 'downloadable_links' => $this->downloadable_link_purchased, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at, ]; diff --git a/packages/Webkul/API/Http/Resources/Sales/OrderItem.php b/packages/Webkul/API/Http/Resources/Sales/OrderItem.php index f7eb3b8cb..67705e958 100644 --- a/packages/Webkul/API/Http/Resources/Sales/OrderItem.php +++ b/packages/Webkul/API/Http/Resources/Sales/OrderItem.php @@ -10,7 +10,8 @@ class OrderItem extends JsonResource /** * Transform the resource into an array. * - * @param \Illuminate\Http\Request + * @param \Illuminate\Http\Request + * * @return array */ public function toArray($request) @@ -75,6 +76,7 @@ class OrderItem extends JsonResource 'formated_grant_total' => core()->formatPrice($this->total + $this->tax_amount, $this->order->order_currency_code), 'base_grant_total' => $this->base_total + $this->base_tax_amount, 'formated_base_grant_total' => core()->formatPrice($this->base_total + $this->base_tax_amount, $this->order->order_currency_code), + 'downloadable_links' => $this->downloadable_link_purchased, 'additional' => is_array($this->resource->additional) ? $this->resource->additional : json_decode($this->resource->additional, true),