Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Evgeniy
laravel-shop-example
Commits
9d67b89c
Commit
9d67b89c
authored
2 years ago
by
Evgeniy
Browse files
Options
Download
Email Patches
Plain Diff
Discounts usage added.
parent
bf7157c7
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
app/Services/Cart/CartCalculationData.php
+2
-1
app/Services/Cart/CartCalculationData.php
app/Services/Cart/CartService.php
+2
-1
app/Services/Cart/CartService.php
app/Services/Cart/Cost/NewYearCost.php
+23
-0
app/Services/Cart/Cost/NewYearCost.php
app/Services/Cart/Cost/PromoCodeCost.php
+1
-1
app/Services/Cart/Cost/PromoCodeCost.php
resources/views/shop/cart.blade.php
+7
-5
resources/views/shop/cart.blade.php
with
35 additions
and
8 deletions
+35
-8
app/Services/Cart/CartCalculationData.php
View file @
9d67b89c
...
...
@@ -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
];
}
...
...
This diff is collapsed.
Click to expand it.
app/Services/Cart/CartService.php
View file @
9d67b89c
...
...
@@ -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
())))
)
;
}
}
This diff is collapsed.
Click to expand it.
app/Services/Cart/Cost/NewYearCost.php
0 → 100644
View file @
9d67b89c
<?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
;
}
}
This diff is collapsed.
Click to expand it.
app/Services/Cart/Cost/PromoCodeCost.php
View file @
9d67b89c
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
resources/views/shop/cart.blade.php
View file @
9d67b89c
...
...
@@ -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>
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help