8 class Discount extends \Magento\Quote\Model\Quote\Address\Total\AbstractTotal
48 $this->calculator = $validator;
64 \
Magento\
Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment,
69 $store = $this->storeManager->getStore(
$quote->getStoreId());
70 $address = $shippingAssignment->getShipping()->getAddress();
73 $items = $shippingAssignment->getItems();
79 'website_id' =>
$store->getWebsiteId(),
80 'customer_group_id' =>
$quote->getCustomerGroupId(),
81 'coupon_code' =>
$quote->getCouponCode(),
84 $this->calculator->init(
$store->getWebsiteId(),
$quote->getCustomerGroupId(),
$quote->getCouponCode());
87 $address->setDiscountDescription([]);
92 if (
$item->getNoDiscount() || !$this->calculator->canApplyDiscount(
$item)) {
93 $item->setDiscountAmount(0);
94 $item->setBaseDiscountAmount(0);
97 if (
$item->getHasChildren() &&
$item->isChildrenCalculated()) {
98 foreach (
$item->getChildren() as $child) {
99 $child->setDiscountAmount(0);
100 $child->setBaseDiscountAmount(0);
106 if (
$item->getParentItem()) {
110 $eventArgs[
'item'] =
$item;
111 $this->eventManager->dispatch(
'sales_quote_address_discount_item', $eventArgs);
113 if (
$item->getHasChildren() &&
$item->isChildrenCalculated()) {
114 $this->calculator->process(
$item);
116 foreach (
$item->getChildren() as $child) {
117 $eventArgs[
'item'] = $child;
118 $this->eventManager->dispatch(
'sales_quote_address_discount_item', $eventArgs);
122 $this->calculator->process(
$item);
128 $address->setShippingDiscountAmount(0);
129 $address->setBaseShippingDiscountAmount(0);
130 if (
$address->getShippingAmount()) {
131 $this->calculator->processShippingAmount(
$address);
133 $total->addBaseTotalAmount($this->
getCode(), -
$address->getBaseShippingDiscountAmount());
134 $total->setShippingDiscountAmount(
$address->getShippingDiscountAmount());
135 $total->setBaseShippingDiscountAmount(
$address->getBaseShippingDiscountAmount());
138 $this->calculator->prepareDescription(
$address);
139 $total->setDiscountDescription(
$address->getDiscountDescription());
141 $total->setBaseSubtotalWithDiscount(
$total->getBaseSubtotal() +
$total->getBaseDiscountAmount());
156 $total->addTotalAmount($this->
getCode(), -$item->getDiscountAmount());
157 $total->addBaseTotalAmount($this->
getCode(), -$item->getBaseDiscountAmount());
169 $parentBaseRowTotal =
$item->getBaseRowTotal();
172 'base_discount_amount',
173 'original_discount_amount',
174 'base_original_discount_amount',
177 foreach ($keys as $key) {
179 $roundingDelta[$key] = 0.0000001;
181 foreach (
$item->getChildren() as $child) {
182 $ratio = $parentBaseRowTotal != 0 ? $child->getBaseRowTotal() / $parentBaseRowTotal : 0;
183 foreach ($keys as $key) {
184 if (!
$item->hasData($key)) {
188 $roundedValue = $this->priceCurrency->round(
$value + $roundingDelta[$key]);
189 $roundingDelta[$key] +=
$value - $roundedValue;
190 $child->setData($key, $roundedValue);
194 foreach ($keys as $key) {
195 $item->setData($key, 0);
collect(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Api\Data\ShippingAssignmentInterface $shippingAssignment, \Magento\Quote\Model\Quote\Address\Total $total)
__construct(\Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\SalesRule\Model\Validator $validator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency)
aggregateItemDiscount(\Magento\Quote\Model\Quote\Item\AbstractItem $item, \Magento\Quote\Model\Quote\Address\Total $total)
distributeDiscount(\Magento\Quote\Model\Quote\Item\AbstractItem $item)
fetch(\Magento\Quote\Model\Quote $quote, \Magento\Quote\Model\Quote\Address\Total $total)