-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathPluginUtility.php
58 lines (50 loc) · 1.53 KB
/
PluginUtility.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
/***
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
*/
namespace MagePal\LimitGuestCheckoutCoupon\Plugin;
class PluginUtility
{
/**
* @var \Magento\SalesRule\Model\CouponFactory
*/
protected $couponFactory;
/**
* @var \MagePal\LimitGuestCheckoutCoupon\Helper\Data
*/
protected $helperData;
/**
* PluginUtility constructor.
* @param \Magento\SalesRule\Model\CouponFactory $couponFactory
* @param \MagePal\LimitGuestCheckoutCoupon\Helper\Data $helperData
*/
public function __construct(
\Magento\SalesRule\Model\CouponFactory $couponFactory,
\MagePal\LimitGuestCheckoutCoupon\Helper\Data $helperData
) {
$this->couponFactory = $couponFactory;
$this->helperData = $helperData;
}
/**
* @param $subject
* @param \Closure $proceed
* @param $rule
* @param $address
* @return bool
* @throws \Exception
*/
public function aroundCanProcessRule($subject, \Closure $proceed, $rule, $address)
{
$result = $proceed($rule, $address);
$couponCode = $address->getQuote()->getCouponCode();
if ($this->helperData->isEnabled() && $couponCode) {
$coupon = $this->couponFactory->create();
$coupon->load($couponCode, 'code');
if ($coupon->getId() && $rule->getUsesPerCoupon() && $coupon->getTimesUsed() >= $rule->getUsesPerCoupon()) {
$result = false;
}
}
return $result;
}
}