|
| __construct (\Magento\SalesRule\Model\ResourceModel\Coupon\UsageFactory $usageFactory, \Magento\SalesRule\Model\CouponFactory $couponFactory, \Magento\SalesRule\Model\Rule\CustomerFactory $customerFactory, \Magento\Framework\DataObjectFactory $objectFactory, PriceCurrencyInterface $priceCurrency) |
|
| minFix (\Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData, \Magento\Quote\Model\Quote\Item\AbstractItem $item, $qty) |
|
| deltaRoundingFix (\Magento\SalesRule\Model\Rule\Action\Discount\Data $discountData, \Magento\Quote\Model\Quote\Item\AbstractItem $item) |
|
| getItemPrice ($item) |
|
| getItemBasePrice ($item) |
|
| getItemQty ($item, $rule) |
|
| mergeIds ($a1, $a2, $asString=true) |
|
| resetRoundingDeltas () |
|
Definition at line 16 of file Utility.php.
◆ __construct()
__construct |
( |
\Magento\SalesRule\Model\ResourceModel\Coupon\UsageFactory |
$usageFactory, |
|
|
\Magento\SalesRule\Model\CouponFactory |
$couponFactory, |
|
|
\Magento\SalesRule\Model\Rule\CustomerFactory |
$customerFactory, |
|
|
\Magento\Framework\DataObjectFactory |
$objectFactory, |
|
|
PriceCurrencyInterface |
$priceCurrency |
|
) |
| |
- Parameters
-
\Magento\SalesRule\Model\ResourceModel\Coupon\UsageFactory | $usageFactory | |
CouponFactory | $couponFactory | |
Rule\CustomerFactory | $customerFactory | |
\Magento\Framework\DataObjectFactory | $objectFactory | |
PriceCurrencyInterface | $priceCurrency | |
Definition at line 60 of file Utility.php.
◆ deltaRoundingFix()
Process "delta" rounding
- Parameters
-
\Magento\SalesRule\Model\Rule\Action\Discount\Data | $discountData | |
\Magento\Quote\Model\Quote\Item\AbstractItem | $item | |
- Returns
- $this
When we have 100% discount check if totals will not be negative
Definition at line 186 of file Utility.php.
190 $discountAmount = $discountData->getAmount();
191 $baseDiscountAmount = $discountData->getBaseAmount();
192 $rowTotalInclTax =
$item->getRowTotalInclTax();
193 $baseRowTotalInclTax =
$item->getBaseRowTotalInclTax();
197 $percentKey =
$item->getDiscountPercent();
199 $delta = isset($this->_roundingDeltas[$percentKey]) ? $this->_roundingDeltas[$percentKey] : 0;
200 $baseDelta = isset($this->_baseRoundingDeltas[$percentKey]) ? $this->_baseRoundingDeltas[$percentKey] : 0;
202 $discountAmount += $delta;
203 $baseDiscountAmount += $baseDelta;
205 $this->_roundingDeltas[$percentKey] = $discountAmount - $this->priceCurrency->round($discountAmount);
206 $this->_baseRoundingDeltas[$percentKey] = $baseDiscountAmount
207 - $this->priceCurrency->round($baseDiscountAmount);
214 if ($percentKey == 100) {
215 $discountDelta = $rowTotalInclTax - $discountAmount;
216 $baseDiscountDelta = $baseRowTotalInclTax - $baseDiscountAmount;
218 if ($discountDelta < 0) {
219 $discountAmount += $discountDelta;
222 if ($baseDiscountDelta < 0) {
223 $baseDiscountAmount += $baseDiscountDelta;
227 $discountData->setAmount($this->priceCurrency->round($discountAmount));
228 $discountData->setBaseAmount($this->priceCurrency->round($baseDiscountAmount));
◆ getItemBasePrice()
getItemBasePrice |
( |
|
$item | ) |
|
Return item base price
- Parameters
-
\Magento\Quote\Model\Quote\Item\AbstractItem | $item | |
- Returns
- float
Definition at line 252 of file Utility.php.
255 return $price !==
null ?
$item->getBaseDiscountCalculationPrice() :
$item->getBaseCalculationPrice();
◆ getItemPrice()
Return item price
- Parameters
-
\Magento\Quote\Model\Quote\Item\AbstractItem | $item | |
- Returns
- float
Definition at line 239 of file Utility.php.
242 $calcPrice =
$item->getCalculationPrice();
◆ getItemQty()
getItemQty |
( |
|
$item, |
|
|
|
$rule |
|
) |
| |
Return discount item qty
- Parameters
-
\Magento\Quote\Model\Quote\Item\AbstractItem | $item | |
\Magento\SalesRule\Model\Rule | $rule | |
- Returns
- int
Definition at line 265 of file Utility.php.
267 $qty =
$item->getTotalQty();
268 $discountQty =
$rule->getDiscountQty();
269 return $discountQty ? min($qty, $discountQty) : $qty;
◆ mergeIds()
mergeIds |
( |
|
$a1, |
|
|
|
$a2, |
|
|
|
$asString = true |
|
) |
| |
Merge two sets of ids
- Parameters
-
array | string | $a1 | |
array | string | $a2 | |
bool | $asString | |
- Returns
- array|string
Definition at line 280 of file Utility.php.
282 if (!is_array($a1)) {
283 $a1 = empty($a1) ? [] : explode(
',', $a1);
285 if (!is_array($a2)) {
286 $a2 = empty($a2) ? [] : explode(
',', $a2);
288 $a = array_unique(array_merge($a1, $a2));
290 $a = implode(
',', $a);
◆ minFix()
- Parameters
-
\Magento\SalesRule\Model\Rule\Action\Discount\Data | $discountData | |
\Magento\Quote\Model\Quote\Item\AbstractItem | $item | |
float | $qty | |
- Returns
- void
Definition at line 161 of file Utility.php.
169 $itemDiscountAmount =
$item->getDiscountAmount();
170 $itemBaseDiscountAmount =
$item->getBaseDiscountAmount();
172 $discountAmount = min($itemDiscountAmount + $discountData->getAmount(), $itemPrice * $qty);
173 $baseDiscountAmount = min($itemBaseDiscountAmount + $discountData->getBaseAmount(), $baseItemPrice * $qty);
175 $discountData->setAmount($discountAmount);
176 $discountData->setBaseAmount($baseDiscountAmount);
◆ resetRoundingDeltas()
- Returns
- void
Definition at line 298 of file Utility.php.
300 $this->_roundingDeltas = [];
301 $this->_baseRoundingDeltas = [];
◆ $_baseRoundingDeltas
$_baseRoundingDeltas = [] |
|
protected |
◆ $_roundingDeltas
◆ $couponFactory
◆ $customerFactory
◆ $objectFactory
◆ $priceCurrency
◆ $usageFactory
The documentation for this class was generated from the following file: