/** * Whether the item row total may be compounded with others * * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item * @return bool * @SuppressWarnings(PHPMD.BooleanGetMethodName) */ public function getIsItemRowTotalCompoundable(\Magento\Quote\Model\Quote\Item\AbstractItem $item) { if ($item->getData("skip_compound_{$this->_itemRowTotalKey}")) { return false; } return true; }
/** * Distribute discount at parent item to children items * * @param \Magento\Quote\Model\Quote\Item\AbstractItem $item * @return $this */ protected function distributeDiscount(\Magento\Quote\Model\Quote\Item\AbstractItem $item) { $parentBaseRowTotal = $item->getBaseRowTotal(); $keys = ['discount_amount', 'base_discount_amount', 'original_discount_amount', 'base_original_discount_amount']; $roundingDelta = []; foreach ($keys as $key) { //Initialize the rounding delta to a tiny number to avoid floating point precision problem $roundingDelta[$key] = 1.0E-7; } foreach ($item->getChildren() as $child) { $ratio = $child->getBaseRowTotal() / $parentBaseRowTotal; foreach ($keys as $key) { if (!$item->hasData($key)) { continue; } $value = $item->getData($key) * $ratio; $roundedValue = $this->priceCurrency->round($value + $roundingDelta[$key]); $roundingDelta[$key] += $value - $roundedValue; $child->setData($key, $roundedValue); } } foreach ($keys as $key) { $item->setData($key, 0); } return $this; }
/** * Compare quote items and ensure fields match * * @param \Magento\Quote\Model\Quote\Item\AbstractItem $nativeItem * @param \Magento\Quote\Model\Quote\Item\AbstractItem $avaTaxItem * @return $this */ protected function compareItems(\Magento\Quote\Model\Quote\Item\AbstractItem $nativeItem, \Magento\Quote\Model\Quote\Item\AbstractItem $avaTaxItem) { foreach ($this->quoteItemFieldsEnsureMatch as $value) { $this->assertEquals($nativeItem->getData($value), $avaTaxItem->getData($value), 'native/AvaTax calculation does not match for quote item field: ' . $value); } return $this; }