fix on weight
This commit is contained in:
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Shop;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Repositories\Core\User\ShopCart;
|
||||
use App\Repositories\Shop\Baskets;
|
||||
use App\Repositories\Shop\DeliveryTypes;
|
||||
use App\Repositories\Shop\Offers;
|
||||
use App\Repositories\Shop\Orders;
|
||||
use App\Repositories\Users;
|
||||
@@ -62,6 +63,19 @@ class BasketController extends Controller
|
||||
return ShopCart::count();
|
||||
}
|
||||
|
||||
public function getBasketTotal($deliveryTypeId = false)
|
||||
{
|
||||
$data = [
|
||||
'basket' => ShopCart::getSummary(),
|
||||
];
|
||||
|
||||
$weight = Baskets::getWeight();
|
||||
|
||||
$data['basket']['shipping'] = DeliveryTypes::getPrice($deliveryTypeId, $weight);
|
||||
|
||||
return view('Shop.Baskets.partials.basketTotal', $data);
|
||||
}
|
||||
|
||||
public function getSummary()
|
||||
{
|
||||
$data = ShopCart::getSummary();
|
||||
|
||||
@@ -113,6 +113,11 @@ class Offer extends Model
|
||||
return $query->where($this->table.'.stock_current', '>', 0);
|
||||
}
|
||||
|
||||
public function scopeByIds($query, $ids)
|
||||
{
|
||||
return $query->whereIn('id', $ids);
|
||||
}
|
||||
|
||||
public function scopeByArticleNature($query, $article_nature_id)
|
||||
{
|
||||
return $query->whereHas('article.article_nature', function ($query) use ($article_nature_id) {
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<div class="col-6">
|
||||
<span id="basket-count">{{ $basket['count'] ?? 0 }}</span> ARTICLES
|
||||
<span id="basket-count">{{ $basket['quantity'] ?? 0 }}</span> ARTICLES
|
||||
</div>
|
||||
<div class="col-6 text-right font-weight-bold">
|
||||
<span id="basket-total">{{ $basket['total'] ?? 0 }}</span> €
|
||||
@@ -32,6 +32,8 @@
|
||||
TOTAL TTC
|
||||
</div>
|
||||
<div class="col-6 text-right">
|
||||
<span id="basket-total-shipped">{{ App\Repositories\Core\User\ShopCart::fixDecimal(($basket['total'] ?? 0)) }}</span> €
|
||||
<span
|
||||
id="basket-total-shipped">{{ App\Repositories\Core\User\ShopCart::fixDecimal($basket['total'] ?? 0) }}</span>
|
||||
€
|
||||
</div>
|
||||
</div>
|
||||
@@ -5,6 +5,7 @@ Route::prefix('Panier')->name('Basket.')->group(function () {
|
||||
Route::post('addBasket', 'BasketController@addBasket')->name('addBasket');
|
||||
Route::get('modalBasket/{offer_id?}/{quantity?}', 'BasketController@modalBasket')->name('modalBasket');
|
||||
Route::get('getBasket', 'BasketController@getBasket')->name('getBasket');
|
||||
Route::get('getBasketTotal', 'BasketController@getBasketTotal')->name('getBasketTotal');
|
||||
Route::get('getSummary', 'BasketController@getSummary')->name('getSummary');
|
||||
Route::get('countBasket', 'BasketController@countBasket')->name('countBasket');
|
||||
Route::get('clearBasket', 'BasketController@clearBasket')->name('clearBasket');
|
||||
|
||||
Reference in New Issue
Block a user