Fix on addresses

This commit is contained in:
ludo
2023-11-13 00:02:21 +01:00
parent 4ce3d528dd
commit 9f90f983ab
29 changed files with 660 additions and 447 deletions

View File

@@ -17,16 +17,17 @@ class Baskets
return $data ? ShopCart::add($data, $update) : false;
}
public static function getBasketSummary($sale_channel_id = false)
public static function getBasketSummary($saleChannelId = false)
{
$basket = ShopCart::getContent();
$offers = Offer::with('variation')->whereIn('id', ShopCart::keys())->get();
$total = 0;
$total_taxed = 0;
$totalTaxed = 0;
$shipping = 5;
foreach ($basket as $item) {
$offer = $offers->where('id', $item->id)->first();
$prices = Offers::getPrice($item->id, $item->quantity, $sale_channel_id);
$prices = Offers::getPrice($item->id, $item->quantity, $saleChannelId);
$weight = $offer->weight * $item->quantity;
$detail[] = [
'offer_id' => (int) $item->id,
'name' => $offer->article->name.' ('.$offer->variation->name.')',
@@ -37,17 +38,18 @@ class Baskets
'total' => self::getTotal($item->quantity, $prices->price),
'total_tax' => self::getTotal($item->quantity, $prices->price_taxed - $prices->price),
'total_taxed' => self::getTotal($item->quantity, $prices->price_taxed),
'weight' => $weight,
];
$total += self::getTotal($item->quantity, $prices->price);
$total_taxed += self::getTotal($item->quantity, $prices->price_taxed);
$totalTaxed += self::getTotal($item->quantity, $prices->price_taxed);
}
$data = [
'detail' => $detail,
'total' => $total,
'taxes' => $total_taxed - $total,
'total_taxed' => $total_taxed,
'taxes' => $totalTaxed - $total,
'total_taxed' => $totalTaxed,
'shipping' => $shipping,
'total_shipped' => $total_taxed + $shipping,
'total_shipped' => $totalTaxed + $shipping,
];
return $data ?? false;
@@ -58,9 +60,9 @@ class Baskets
return $quantity * $price;
}
public static function getBasket($sale_channel_id = false)
public static function getBasket($saleChannelId = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$basket = ShopCart::getContent();
// dump($basket->toArray());
$offers = Offer::with([
@@ -69,7 +71,7 @@ class Baskets
'article.product.Specie',
'article.image',
'price_lists.price_list_values',
])->withPriceListsBySaleChannel($sale_channel_id)
])->withPriceListsBySaleChannel($saleChannelId)
->whereIn('id', ShopCart::keys())->get();
foreach ($basket as $item) {
$offer = $offers->where('id', $item->id)->first();

View File

@@ -84,7 +84,9 @@ class Customers
public static function getWithAddresses($id = false)
{
return self::get($id, ['invoicing_addresses', 'delivery_addresses']);
$id = $id ? $id : self::getId();
return self::get($id, ['invoice_addresses', 'delivery_addresses']);
}
public static function getName($id = false)
@@ -99,18 +101,16 @@ class Customers
return self::guard()->user();
}
public static function get($id, $relations = false, $relationsCount = false)
{
$id = $id ? $id : self::getId();
return self::getModelRelations($relations, $relationsCount)->find($id);
}
public static function getId()
{
return self::guard()->id();
}
public static function isNotConnected()
{
return ! self::isConnected();
}
public static function isConnected()
{
return self::guard()->check();
@@ -118,7 +118,7 @@ class Customers
public static function edit($id)
{
$customer = self::get($id, 'addresses');
$customer = self::get($id, ['delivery_addresses', 'invoice_addresses']);
$data = $customer->toArray();
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
@@ -128,12 +128,12 @@ class Customers
public static function storeFull($data)
{
$deliveries = $data['deliveries'];
$addresses = $data['addresses'];
$invoices = $data['invoices'];
unset($data['deliveries']);
unset($data['addresses']);
unset($data['invoices']);
$customer = self::store($data);
self::storeDeliveries($customer, $deliveries);
self::storeAddresses($customer, $addresses);
self::storeAddresses($customer, $deliveries);
self::storeAddresses($customer, $invoices);
return $customer->id;
}

View File

@@ -11,17 +11,24 @@ class Offers
return Offer::count();
}
public static function getFull($id, $sale_channel_id = false)
public static function getWeight($id, $quantity = 1)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$offer = self::get($id);
return $offer ? $offer->weight * $quantity : 0;
}
public static function getFull($id, $saleChannelId = false)
{
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$offer = Offer::with([
'article.article_nature',
'article.product',
'tariff' => function ($query) use ($sale_channel_id) {
$query->bySaleChannel($sale_channel_id);
'tariff' => function ($query) use ($saleChannelId) {
$query->bySaleChannel($saleChannelId);
},
'tariff.price_lists' => function ($query) use ($sale_channel_id) {
$query->BySaleChannel($sale_channel_id);
'tariff.price_lists' => function ($query) use ($saleChannelId) {
$query->BySaleChannel($saleChannelId);
},
'tariff.price_lists.price_list_values',
'variation',
@@ -32,43 +39,43 @@ class Offers
return $offer;
}
public static function getPrice($id, $quantity = 1, $sale_channel_id = false)
public static function getPrice($id, $quantity = 1, $saleChannelId = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$offer = Offer::withPriceBySaleChannelByQuantity($sale_channel_id, $quantity)->find($id);
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
$offer = Offer::withPriceBySaleChannelByQuantity($saleChannelId, $quantity)->find($id);
return $offer->price_lists->first()->price_list_values->first();
}
public static function getOffersByArticles($article_ids, $sale_channel_id = false)
public static function getOffersByArticles($article_ids, $saleChannelId = false)
{
return self::getOffersBySaleChannelRaw($sale_channel_id)->byArticles($article_ids)->get();
return self::getOffersBySaleChannelRaw($saleChannelId)->byArticles($article_ids)->get();
}
public static function getOffersByArticle($article_id, $sale_channel_id = false)
public static function getOffersByArticle($article_id, $saleChannelId = false)
{
return self::getOffersBySaleChannelRaw($sale_channel_id)->byArticle($article_id)->get();
return self::getOffersBySaleChannelRaw($saleChannelId)->byArticle($article_id)->get();
}
public static function getOffersBySaleChannel($sale_channel_id = false)
public static function getOffersBySaleChannel($saleChannelId = false)
{
return self::getOffersBySaleChannelRaw($sale_channel_id)->get();
return self::getOffersBySaleChannelRaw($saleChannelId)->get();
}
public static function getOffersBySaleChannelRaw($sale_channel_id = false)
public static function getOffersBySaleChannelRaw($saleChannelId = false)
{
$sale_channel_id = $sale_channel_id ? $sale_channel_id : SaleChannels::getDefaultID();
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
return Offer::active()->byStockAvailable()
->with([
'article_nature',
'variation',
'tariff.price_lists' => function ($query) use ($sale_channel_id) {
$query->bySaleChannel($sale_channel_id);
'tariff.price_lists' => function ($query) use ($saleChannelId) {
$query->bySaleChannel($saleChannelId);
},
'tariff.price_lists.price_list_values',
])
->bySaleChannel($sale_channel_id);
->bySaleChannel($saleChannelId);
}
public static function getThumbSrcById($id)

View File

@@ -16,6 +16,22 @@ class Orders
return Order::byUUID($uuid)->first();
}
public static function getFullByUUID($uuid)
{
return Order::with(['customer', 'delivery', 'delivery_address', 'detail', 'invoice.address', 'sale_channel'])
->byUUID($uuid)->first();
}
public static function view($uuid)
{
$data = [];
$order = self::getFullByUUID($uuid);
$data = $order->toArray();
$data['payment_type'] = InvoicePayments::getPaymentType($order->payment_type);
$data['status'] = Orders::getStatus($order->status);
return $data;
}
public static function saveOrder($data)
{
$data += $data['basket'];