first upload all files
This commit is contained in:
19
Modules/Coupon/Checkers/AlreadyApplied.php
Normal file
19
Modules/Coupon/Checkers/AlreadyApplied.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Cart\Facades\Cart;
|
||||
use Modules\Coupon\Exceptions\CouponAlreadyAppliedException;
|
||||
|
||||
class AlreadyApplied
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
if (Cart::couponAlreadyApplied($coupon)) {
|
||||
throw new CouponAlreadyAppliedException;
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
29
Modules/Coupon/Checkers/ApplicableCategories.php
Normal file
29
Modules/Coupon/Checkers/ApplicableCategories.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Cart\Facades\Cart;
|
||||
use Modules\Coupon\Exceptions\InapplicableCouponException;
|
||||
|
||||
class ApplicableCategories
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
$coupon->load('categories');
|
||||
|
||||
if ($coupon->categories->isEmpty()) {
|
||||
return $next($coupon);
|
||||
}
|
||||
|
||||
$cartItems = Cart::items()->filter(function ($cartItem) use ($coupon) {
|
||||
return $coupon->categories->intersect($cartItem->product->categories)->isNotEmpty();
|
||||
});
|
||||
|
||||
if ($cartItems->isEmpty()) {
|
||||
throw new InapplicableCouponException;
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
29
Modules/Coupon/Checkers/ApplicableProducts.php
Normal file
29
Modules/Coupon/Checkers/ApplicableProducts.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Cart\Facades\Cart;
|
||||
use Modules\Coupon\Exceptions\InapplicableCouponException;
|
||||
|
||||
class ApplicableProducts
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
$coupon->load('products');
|
||||
|
||||
if ($coupon->products->isEmpty()) {
|
||||
return $next($coupon);
|
||||
}
|
||||
|
||||
$cartItems = Cart::items()->filter(function ($cartItem) use ($coupon) {
|
||||
return $coupon->products->contains($cartItem->product);
|
||||
});
|
||||
|
||||
if ($cartItems->isEmpty()) {
|
||||
throw new InapplicableCouponException;
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
18
Modules/Coupon/Checkers/CouponExists.php
Normal file
18
Modules/Coupon/Checkers/CouponExists.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Coupon\Exceptions\CouponNotExistsException;
|
||||
|
||||
class CouponExists
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
if (is_null($coupon)) {
|
||||
throw new CouponNotExistsException;
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
32
Modules/Coupon/Checkers/ExcludedCategories.php
Normal file
32
Modules/Coupon/Checkers/ExcludedCategories.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Cart\Facades\Cart;
|
||||
use Modules\Coupon\Exceptions\InapplicableCouponException;
|
||||
|
||||
class ExcludedCategories
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
$coupon->load('excludeCategories');
|
||||
|
||||
if ($coupon->excludeCategories->isEmpty()) {
|
||||
return $next($coupon);
|
||||
}
|
||||
|
||||
foreach (Cart::items() as $cartItem) {
|
||||
if ($this->inExcludedCategories($coupon, $cartItem)) {
|
||||
throw new InapplicableCouponException;
|
||||
}
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
|
||||
private function inExcludedCategories($coupon, $cartItem)
|
||||
{
|
||||
return $coupon->excludeCategories->intersect($cartItem->product->categories)->isNotEmpty();
|
||||
}
|
||||
}
|
||||
32
Modules/Coupon/Checkers/ExcludedProducts.php
Normal file
32
Modules/Coupon/Checkers/ExcludedProducts.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Cart\Facades\Cart;
|
||||
use Modules\Coupon\Exceptions\InapplicableCouponException;
|
||||
|
||||
class ExcludedProducts
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
$coupon->load('excludeProducts');
|
||||
|
||||
if ($coupon->excludeProducts->isEmpty()) {
|
||||
return $next($coupon);
|
||||
}
|
||||
|
||||
foreach (Cart::items() as $cartItem) {
|
||||
if ($this->inExcludedProducts($coupon, $cartItem)) {
|
||||
throw new InapplicableCouponException;
|
||||
}
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
|
||||
private function inExcludedProducts($coupon, $cartItem)
|
||||
{
|
||||
return $coupon->excludeProducts->contains($cartItem->product);
|
||||
}
|
||||
}
|
||||
18
Modules/Coupon/Checkers/MaximumSpend.php
Normal file
18
Modules/Coupon/Checkers/MaximumSpend.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Coupon\Exceptions\MaximumSpendException;
|
||||
|
||||
class MaximumSpend
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
if ($coupon->spentMoreThanMaximumAmount()) {
|
||||
throw new MaximumSpendException($coupon->maximum_spend);
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
18
Modules/Coupon/Checkers/MinimumSpend.php
Normal file
18
Modules/Coupon/Checkers/MinimumSpend.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Coupon\Exceptions\MinimumSpendException;
|
||||
|
||||
class MinimumSpend
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
if ($coupon->didNotSpendTheRequiredAmount()) {
|
||||
throw new MinimumSpendException($coupon->minimum_spend);
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
18
Modules/Coupon/Checkers/UsageLimitPerCoupon.php
Normal file
18
Modules/Coupon/Checkers/UsageLimitPerCoupon.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Coupon\Exceptions\CouponUsageLimitReachedException;
|
||||
|
||||
class UsageLimitPerCoupon
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
if ($coupon->usageLimitReached()) {
|
||||
throw new CouponUsageLimitReachedException;
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
18
Modules/Coupon/Checkers/UsageLimitPerCustomer.php
Normal file
18
Modules/Coupon/Checkers/UsageLimitPerCustomer.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Coupon\Exceptions\CouponUsageLimitReachedException;
|
||||
|
||||
class UsageLimitPerCustomer
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
if ($coupon->perCustomerUsageLimitReached()) {
|
||||
throw new CouponUsageLimitReachedException;
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
18
Modules/Coupon/Checkers/ValidCoupon.php
Normal file
18
Modules/Coupon/Checkers/ValidCoupon.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Coupon\Checkers;
|
||||
|
||||
use Closure;
|
||||
use Modules\Coupon\Exceptions\InvalidCouponException;
|
||||
|
||||
class ValidCoupon
|
||||
{
|
||||
public function handle($coupon, Closure $next)
|
||||
{
|
||||
if ($coupon->invalid()) {
|
||||
throw new InvalidCouponException;
|
||||
}
|
||||
|
||||
return $next($coupon);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user