Skip to content

Commit 0d9ecaa

Browse files
author
Tang, Yu(ytang1)
committed
Merge pull request #391 from magento-fearless-kiwis/develop
[FearlessKiwis] Weee Price Variation Caching
2 parents cfdbe77 + aa44545 commit 0d9ecaa

File tree

25 files changed

+2026
-541
lines changed

25 files changed

+2026
-541
lines changed

app/code/Magento/Checkout/view/frontend/web/js/action/select-payment-method.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,10 @@ define(
8080
});
8181
if (proceed) {
8282
quote.setPaymentMethod(methodData.method);
83+
//set the totals before setting PaymentData
84+
quote.setTotals(response);
8385
service.setSelectedPaymentData(methodData);
8486
service.setSelectedPaymentInfo(methodInfo);
85-
quote.setTotals(response);
8687
navigator.setCurrent('paymentMethod').goNext();
8788
}
8889
}

app/code/Magento/Sales/etc/extension_attributes.xml

Lines changed: 0 additions & 14 deletions
This file was deleted.

app/code/Magento/Tax/Model/App/Action/ContextPlugin.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ public function aroundDispatch(
8484
\Closure $proceed,
8585
\Magento\Framework\App\RequestInterface $request
8686
) {
87-
if (!$this->moduleManager->isEnabled('Magento_PageCache') ||
87+
if (!$this->customerSession->isLoggedIn() ||
88+
!$this->moduleManager->isEnabled('Magento_PageCache') ||
8889
!$this->cacheConfig->isEnabled() ||
8990
!$this->taxHelper->isCatalogPriceDisplayAffectedByTax()) {
9091
return $proceed($request);

app/code/Magento/Tax/Model/Observer.php

Lines changed: 0 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ class Observer
2020
*/
2121
protected $_taxData;
2222

23-
/**
24-
* @var \Magento\Tax\Model\Sales\Order\TaxFactory
25-
*/
26-
protected $_orderTaxFactory;
27-
28-
/**
29-
* @var \Magento\Sales\Model\Order\Tax\ItemFactory
30-
*/
31-
protected $_taxItemFactory;
32-
3323
/**
3424
* @var \Magento\Tax\Model\Calculation
3525
*/
@@ -57,8 +47,6 @@ class Observer
5747

5848
/**
5949
* @param \Magento\Tax\Helper\Data $taxData
60-
* @param \Magento\Tax\Model\Sales\Order\TaxFactory $orderTaxFactory
61-
* @param \Magento\Sales\Model\Order\Tax\ItemFactory $taxItemFactory
6250
* @param \Magento\Tax\Model\Calculation $calculation
6351
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
6452
* @param \Magento\Tax\Model\Resource\Report\TaxFactory $reportTaxFactory
@@ -67,17 +55,13 @@ class Observer
6755
*/
6856
public function __construct(
6957
\Magento\Tax\Helper\Data $taxData,
70-
\Magento\Tax\Model\Sales\Order\TaxFactory $orderTaxFactory,
71-
\Magento\Sales\Model\Order\Tax\ItemFactory $taxItemFactory,
7258
\Magento\Tax\Model\Calculation $calculation,
7359
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
7460
\Magento\Tax\Model\Resource\Report\TaxFactory $reportTaxFactory,
7561
\Magento\Framework\Locale\ResolverInterface $localeResolver,
7662
\Magento\Framework\Registry $registry
7763
) {
7864
$this->_taxData = $taxData;
79-
$this->_orderTaxFactory = $orderTaxFactory;
80-
$this->_taxItemFactory = $taxItemFactory;
8165
$this->_calculation = $calculation;
8266
$this->_localeDate = $localeDate;
8367
$this->_reportTaxFactory = $reportTaxFactory;
@@ -114,145 +98,6 @@ public function salesEventConvertQuoteAddressToOrder(\Magento\Framework\Event\Ob
11498
}
11599
}
116100

117-
/**
118-
* Save order tax information
119-
*
120-
* @param \Magento\Framework\Event\Observer $observer
121-
* @return void
122-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
123-
* @SuppressWarnings(PHPMD.NPathComplexity)
124-
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
125-
*/
126-
public function salesEventOrderAfterSave(\Magento\Framework\Event\Observer $observer)
127-
{
128-
$order = $observer->getEvent()->getOrder();
129-
130-
if (!$order->getConvertingFromQuote() || $order->getAppliedTaxIsSaved()) {
131-
return;
132-
}
133-
134-
$taxesAttr = $order->getCustomAttribute('applied_taxes');
135-
if (is_null($taxesAttr) || !is_array($taxesAttr->getValue())) {
136-
$taxes = [];
137-
} else {
138-
$taxes = $taxesAttr->getValue();
139-
}
140-
141-
$getTaxesForItemsAttr = $order->getCustomAttribute('item_applied_taxes');
142-
if (is_null($getTaxesForItemsAttr) || !is_array($getTaxesForItemsAttr->getValue())) {
143-
$getTaxesForItems = [];
144-
} else {
145-
$getTaxesForItems = $getTaxesForItemsAttr->getValue();
146-
}
147-
148-
$ratesIdQuoteItemId = [];
149-
foreach ($getTaxesForItems as $taxesArray) {
150-
foreach ($taxesArray as $rates) {
151-
if (count($rates['rates']) == 1) {
152-
$ratesIdQuoteItemId[$rates['id']][] = [
153-
'id' => $rates['item_id'],
154-
'percent' => $rates['percent'],
155-
'code' => $rates['rates'][0]['code'],
156-
'associated_item_id' => $rates['associated_item_id'],
157-
'item_type' => $rates['item_type'],
158-
'amount' => $rates['amount'],
159-
'base_amount' => $rates['base_amount'],
160-
'real_amount' => $rates['amount'],
161-
'real_base_amount' => $rates['base_amount'],
162-
];
163-
} else {
164-
$percentSum = 0;
165-
foreach ($rates['rates'] as $rate) {
166-
$real_amount = $rates['amount'] * $rate['percent'] / $rates['percent'];
167-
$real_base_amount = $rates['base_amount'] * $rate['percent'] / $rates['percent'];
168-
$ratesIdQuoteItemId[$rates['id']][] = [
169-
'id' => $rates['item_id'],
170-
'percent' => $rate['percent'],
171-
'code' => $rate['code'],
172-
'associated_item_id' => $rates['associated_item_id'],
173-
'item_type' => $rates['item_type'],
174-
'amount' => $rates['amount'],
175-
'base_amount' => $rates['base_amount'],
176-
'real_amount' => $real_amount,
177-
'real_base_amount' => $real_base_amount,
178-
];
179-
$percentSum += $rate['percent'];
180-
}
181-
}
182-
}
183-
}
184-
185-
foreach ($taxes as $row) {
186-
$id = $row['id'];
187-
foreach ($row['rates'] as $tax) {
188-
if (is_null($row['percent'])) {
189-
$baseRealAmount = $row['base_amount'];
190-
} else {
191-
if ($row['percent'] == 0 || $tax['percent'] == 0) {
192-
continue;
193-
}
194-
$baseRealAmount = $row['base_amount'] / $row['percent'] * $tax['percent'];
195-
}
196-
$hidden = isset($row['hidden']) ? $row['hidden'] : 0;
197-
$priority = isset($tax['priority']) ? $tax['priority'] : 0;
198-
$position = isset($tax['position']) ? $tax['position'] : 0;
199-
$process = isset($row['process']) ? $row['process'] : 0;
200-
$data = [
201-
'order_id' => $order->getId(),
202-
'code' => $tax['code'],
203-
'title' => $tax['title'],
204-
'hidden' => $hidden,
205-
'percent' => $tax['percent'],
206-
'priority' => $priority,
207-
'position' => $position,
208-
'amount' => $row['amount'],
209-
'base_amount' => $row['base_amount'],
210-
'process' => $process,
211-
'base_real_amount' => $baseRealAmount,
212-
];
213-
214-
/** @var $orderTax \Magento\Tax\Model\Sales\Order\Tax */
215-
$orderTax = $this->_orderTaxFactory->create();
216-
$result = $orderTax->setData($data)->save();
217-
218-
if (isset($ratesIdQuoteItemId[$id])) {
219-
foreach ($ratesIdQuoteItemId[$id] as $quoteItemId) {
220-
if ($quoteItemId['code'] == $tax['code']) {
221-
$itemId = null;
222-
$associatedItemId = null;
223-
if (isset($quoteItemId['id'])) {
224-
//This is a product item
225-
$item = $order->getItemByQuoteItemId($quoteItemId['id']);
226-
$itemId = $item->getId();
227-
} elseif (isset($quoteItemId['associated_item_id'])) {
228-
//This item is associated with a product item
229-
$item = $order->getItemByQuoteItemId($quoteItemId['associated_item_id']);
230-
$associatedItemId = $item->getId();
231-
}
232-
233-
$data = [
234-
'item_id' => $itemId,
235-
'tax_id' => $result->getTaxId(),
236-
'tax_percent' => $quoteItemId['percent'],
237-
'associated_item_id' => $associatedItemId,
238-
'amount' => $quoteItemId['amount'],
239-
'base_amount' => $quoteItemId['base_amount'],
240-
'real_amount' => $quoteItemId['real_amount'],
241-
'real_base_amount' => $quoteItemId['real_base_amount'],
242-
'taxable_item_type' => $quoteItemId['item_type'],
243-
];
244-
/** @var $taxItem \Magento\Sales\Model\Order\Tax\Item */
245-
$taxItem = $this->_taxItemFactory->create();
246-
$taxItem->setData($data)->save();
247-
}
248-
}
249-
}
250-
}
251-
}
252-
253-
$order->setAppliedTaxIsSaved(true);
254-
}
255-
256101
/**
257102
* Refresh sales tax report statistics for last day
258103
*

0 commit comments

Comments
 (0)