Commit 9d67b89c authored by Evgeniy's avatar Evgeniy
Browse files

Discounts usage added.

parent bf7157c7
Showing with 35 additions and 8 deletions
+35 -8
......@@ -24,10 +24,11 @@ public function getDiscounts(){
return $this->discounts;
}
public function setDiscount($discountName, $discountValue){
public function setDiscount($discountName, $discountValue, $discountType){
$this->discounts[] = [
'name' => $discountName,
'discount' => $discountValue,
'type' => $discountType
];
}
......
......@@ -2,6 +2,7 @@
namespace App\Services\Cart;
use App\Services\Cart\Cost\NewYearCost;
use App\Services\Cart\Cost\PromoCodeCost;
use App\Services\Cart\Cost\SimpleCost;
use App\Services\Cart\Interfaces\CartServiceInterface;
......@@ -12,6 +13,6 @@ class CartService implements CartServiceInterface
public Cart $cart;
public function __construct(){
$this->cart = new Cart((new CartSessionStorageService), (new PromoCodeCost(new SimpleCost(), new CouponSessionStorage())));
$this->cart = new Cart((new CartSessionStorageService), (new NewYearCost(new PromoCodeCost(new SimpleCost(), new CouponSessionStorage()))));
}
}
<?php
namespace App\Services\Cart\Cost;
use App\Services\Cart\Cost\Interfaces\CartCostCalculator;
use App\Services\Coupon\Interface\CouponStorageInterface;
class NewYearCost implements CartCostCalculator
{
public function __construct(CartCostCalculator $calculator){
$this->next = $calculator;
}
public function getCost(array $items){
$cartData = $this->next->getCost($items);
if(date('m') == 9){
$newYearDiscount = $cartData->getSubTotal() * 0.05;
$cartData->setTotal($cartData->getTotal() - $newYearDiscount);
$cartData->setDiscount('Happy New Year! 5% off on all products <3.', $newYearDiscount, 'value');
}
return $cartData;
}
}
......@@ -17,7 +17,7 @@ public function getCost(array $items){
if($cartCoupon !== null){
$couponDiscount = $cartCoupon->calculateCoupon($cartData->getSubTotal());
$cartData->setTotal($cartData->getTotal() - $couponDiscount);
$cartData->setDiscount($cartCoupon->getCouponName(), $couponDiscount);
$cartData->setDiscount($cartCoupon->getCouponName(), $couponDiscount, 'coupon');
}
return $cartData;
}
......
......@@ -126,11 +126,13 @@
<li class="d-flex flex-row align-items-center justify-content-start">
<div class="cart_total_title">
<span>{{$discount['name']}}</span>
<form action="{{ route('shop.cart.coupon.removeCoupon') }}" method="POST" style="display: inline">
@csrf
@method('DELETE')
<button type="submit">Remove</button>
</form>
@if($discount['type'] === 'coupon')
<form action="{{ route('shop.cart.coupon.removeCoupon') }}" method="POST" style="display: inline">
@csrf
@method('DELETE')
<button type="submit">Remove</button>
</form>
@endif
</div>
<div class="cart_total_value ml-auto">-{{$discount['discount']}}</div>
</li>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment