64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Beike\Shop\Http\Resources;
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class CartDetail extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param Request $request
|
|
* @return array|Arrayable|\JsonSerializable
|
|
* @throws \Exception
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
$sku = $this->sku;
|
|
$product = $sku->product;
|
|
if($product->price_setting == 'num'){
|
|
$price = $product->getNumPricesByNum($this->product_quantity_sum);
|
|
}else{
|
|
$price = $sku->price;
|
|
};
|
|
$skuCode = $sku->sku;
|
|
$description = $product->description;
|
|
|
|
$productName = $description->name;
|
|
$unit = $this->unit;//$description->unit ?? '';
|
|
$subTotal = $price * $this->quantity;
|
|
$image = $sku->image ?: $product->image;
|
|
|
|
$result = [
|
|
'cart_id' => $this->id,
|
|
'product_id' => $this->product_id,
|
|
'sku_id' => $this->product_sku_id,
|
|
'product_sku' => $skuCode,
|
|
'name' => $productName,
|
|
'name_format' => sub_string($productName),
|
|
'unit' => $unit,
|
|
'unit_format' => $unit,
|
|
'trade_term' => $this->trade_term,
|
|
'image' => $image,
|
|
'image_url' => image_resize($image),
|
|
'quantity' => $this->quantity,
|
|
'selected' => $this->selected,
|
|
'price' => $price,
|
|
'price_format' => currency_format($price),
|
|
'tax_class_id' => $product->tax_class_id,
|
|
'subtotal' => $subTotal,
|
|
'subtotal_format' => currency_format($subTotal),
|
|
'variant_labels' => trim($sku->getVariantLabel()),
|
|
'active' => $product->active,
|
|
'minimum_order' => $product->minimum_order,
|
|
'sales_method' => $product->sales_method,
|
|
'piece_to_batch' => $product->piece_to_batch
|
|
];
|
|
|
|
return hook_filter('resource.cart.detail', $result);
|
|
}
|
|
}
|