init
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Esun\CustomerCoupon\Model\Coupon;
|
||||
|
||||
use Magento\Quote\Model\Quote;
|
||||
use Magento\SalesRule\Model\Rule;
|
||||
|
||||
class EligibilityService
|
||||
{
|
||||
public function isApplicableToQuote(Rule $rule, Quote $quote): bool
|
||||
{
|
||||
if (!$quote->getItemsCount()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$address = $quote->getIsVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
|
||||
if (!$rule->getConditions()->validate($address)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!$rule->getActions()->getConditions()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($quote->getAllVisibleItems() as $item) {
|
||||
if ($rule->getActions()->validate($item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user