fix on weight
This commit is contained in:
@@ -17,37 +17,29 @@ class Baskets
|
||||
return $data ? ShopCart::add($data, $update) : false;
|
||||
}
|
||||
|
||||
public static function getBasketSummary($saleChannelId = false)
|
||||
public static function getBasketSummary($saleChannelId = false, $deliveryTypeId = false)
|
||||
{
|
||||
$basket = ShopCart::getContent();
|
||||
$offers = Offer::with('variation')->whereIn('id', ShopCart::keys())->get();
|
||||
$total = 0;
|
||||
$totalTaxed = 0;
|
||||
$shipping = 5;
|
||||
$totalWeight = 0;
|
||||
foreach ($basket as $item) {
|
||||
$offer = $offers->where('id', $item->id)->first();
|
||||
$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.')',
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => (float) $prices->price,
|
||||
'tax' => $prices->price_taxed - $prices->price,
|
||||
'price_taxed' => (float) $prices->price_taxed,
|
||||
'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,
|
||||
];
|
||||
$detail[] = self::getRowDetail($item, $offer, $prices, $weight);
|
||||
$total += self::getTotal($item->quantity, $prices->price);
|
||||
$totalTaxed += self::getTotal($item->quantity, $prices->price_taxed);
|
||||
$totalWeight += $weight;
|
||||
}
|
||||
$shipping = 0;
|
||||
$data = [
|
||||
'detail' => $detail,
|
||||
'total' => $total,
|
||||
'taxes' => $totalTaxed - $total,
|
||||
'total_taxed' => $totalTaxed,
|
||||
'total_weight' => $totalWeight,
|
||||
'shipping' => $shipping,
|
||||
'total_shipped' => $totalTaxed + $shipping,
|
||||
];
|
||||
@@ -55,6 +47,36 @@ class Baskets
|
||||
return $data ?? false;
|
||||
}
|
||||
|
||||
public static function getRowDetail($item, $offer, $prices, $weight)
|
||||
{
|
||||
return [
|
||||
'offer_id' => (int) $item->id,
|
||||
'name' => $offer->article->name.' ('.$offer->variation->name.')',
|
||||
'quantity' => (int) $item->quantity,
|
||||
'price' => (float) $prices->price,
|
||||
'tax' => $prices->price_taxed - $prices->price,
|
||||
'price_taxed' => (float) $prices->price_taxed,
|
||||
'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,
|
||||
];
|
||||
}
|
||||
|
||||
public static function getWeight()
|
||||
{
|
||||
$basket = ShopCart::getContent();
|
||||
$offers = Offer::with('variation')->byIds(ShopCart::keys())->get();
|
||||
$totalWeight = 0;
|
||||
foreach ($basket as $item) {
|
||||
$offer = $offers->where('id', $item->id)->first();
|
||||
$weight = $offer->weight * $item->quantity;
|
||||
$totalWeight += $weight;
|
||||
}
|
||||
|
||||
return $totalWeight;
|
||||
}
|
||||
|
||||
public static function getTotal($quantity, $price)
|
||||
{
|
||||
return $quantity * $price;
|
||||
|
||||
@@ -9,6 +9,13 @@ class DeliveryTypeCalculations
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getPriceByDeliveryType($deliveryTypeId, $weight)
|
||||
{
|
||||
$price = DeliveryTypeCalculation::byDeliveryType($deliveryTypeId)->byWeight($weight)->first();
|
||||
|
||||
return $price ? $price->price : false;
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return DeliveryTypeCalculation::query();
|
||||
|
||||
@@ -9,6 +9,11 @@ class DeliveryTypes
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function getPrice($id, $weight)
|
||||
{
|
||||
return DeliveryTypeCalculations::getPriceByDeliveryType($id, $weight);
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return DeliveryType::query();
|
||||
|
||||
Reference in New Issue
Block a user