Skip to content

Commit 1bafc57

Browse files
Merge pull request #9064 from magento-gl/spartans_pr_04072024
[Spartans] Bugfixes Delivery
2 parents ada8d1d + 537ced9 commit 1bafc57

File tree

9 files changed

+154
-88
lines changed

9 files changed

+154
-88
lines changed

app/code/Magento/Checkout/view/frontend/web/js/model/shipping-rates-validator.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,17 @@ define([
193193
*/
194194
validateFields: function () {
195195
var addressFlat = addressConverter.formDataProviderToFlatData(
196-
this.collectObservedData(),
197-
'shippingAddress'
196+
this.collectObservedData(),
197+
'shippingAddress'
198198
),
199199
address;
200200

201201
if (this.validateAddressData(addressFlat)) {
202202
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
203203
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
204204
selectShippingAddress(address);
205+
} else {
206+
shippingService.isLoading(false);
205207
}
206208
},
207209

app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\MediaStorage\Helper\File\Storage\Database;
1313
use Magento\Sales\Model\RtlTextHandler;
1414
use Magento\Store\Model\ScopeInterface;
15+
use Magento\Tax\Helper\Data as TaxHelper;
1516

1617
/**
1718
* Sales Order PDF abstract model
@@ -131,6 +132,11 @@ abstract public function getPdf();
131132
*/
132133
protected $addressRenderer;
133134

135+
/**
136+
* @var Magento\Tax\Helper\Data
137+
*/
138+
private $taxHelper;
139+
134140
/**
135141
* @var array $pageSettings
136142
*/
@@ -156,6 +162,7 @@ abstract public function getPdf();
156162
* @param Database $fileStorageDatabase
157163
* @param RtlTextHandler|null $rtlTextHandler
158164
* @param Image $image
165+
* @param TaxHelper $taxHelper
159166
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
160167
*/
161168
public function __construct(
@@ -172,7 +179,8 @@ public function __construct(
172179
array $data = [],
173180
Database $fileStorageDatabase = null,
174181
?RtlTextHandler $rtlTextHandler = null,
175-
?Image $image = null
182+
?Image $image = null,
183+
?TaxHelper $taxHelper = null
176184
) {
177185
$this->addressRenderer = $addressRenderer;
178186
$this->_paymentData = $paymentData;
@@ -185,6 +193,7 @@ public function __construct(
185193
$this->_pdfTotalFactory = $pdfTotalFactory;
186194
$this->_pdfItemsFactory = $pdfItemsFactory;
187195
$this->inlineTranslation = $inlineTranslation;
196+
$this->taxHelper = $taxHelper ?: ObjectManager::getInstance()->get(TaxHelper::class);
188197
$this->fileStorageDatabase = $fileStorageDatabase ?: ObjectManager::getInstance()->get(Database::class);
189198
$this->rtlTextHandler = $rtlTextHandler ?: ObjectManager::getInstance()->get(RtlTextHandler::class);
190199
$this->image = $image ?: ObjectManager::getInstance()->get(Image::class);
@@ -604,11 +613,18 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
604613
}
605614

606615
$yShipments = $this->y;
607-
$totalShippingChargesText = "("
608-
. __('Total Shipping Charges')
609-
. " "
610-
. $order->formatPriceTxt($order->getShippingAmount())
611-
. ")";
616+
$totalShippingChargesText = "(" . __('Total Shipping Charges') . " ";
617+
if ($this->taxHelper->displayShippingPriceIncludingTax()) {
618+
$totalShippingChargesText .= $order->formatPriceTxt($order->getShippingInclTax());
619+
} else {
620+
$totalShippingChargesText .= $order->formatPriceTxt($order->getShippingAmount());
621+
}
622+
623+
if ($this->taxHelper->displayShippingBothPrices()
624+
&& $order->getShippingInclTax() != $order->getShippingAmount()) {
625+
$totalShippingChargesText .= "(Incl. Tax " . $order->getShippingInclTax() . ")";
626+
}
627+
$totalShippingChargesText .= ")";
612628

613629
$page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
614630
$yShipments -= $topMargin + 10;

app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Transaction.php

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
/**
1212
* Sales transaction resource model
1313
*
14-
* @author Magento Core Team <core@magentocommerce.com>
1514
*/
1615
class Transaction extends EntityAbstract implements TransactionResourceInterface
1716
{
@@ -34,7 +33,8 @@ protected function _construct()
3433

3534
/**
3635
* Update transactions in database using provided transaction as parent for them
37-
* have to repeat the business logic to avoid accidental injection of wrong transactions
36+
*
37+
* Have to repeat the business logic to avoid accidental injection of wrong transactions
3838
*
3939
* @param \Magento\Sales\Model\Order\Payment\Transaction $transaction
4040
* @return void
@@ -126,11 +126,14 @@ public function getOrderWebsiteId($orderId)
126126

127127
/**
128128
* Lookup for parent_id in already saved transactions of this payment by the order_id
129+
*
129130
* Also serialize additional information, if any
130131
*
131132
* @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Model\Order\Payment\Transaction $transaction
132133
* @throws \Magento\Framework\Exception\LocalizedException
133134
* @return $this
135+
*
136+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
134137
*/
135138
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transaction)
136139
{
@@ -139,16 +142,23 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
139142
$orderId = $transaction->getData('order_id');
140143
$paymentId = $transaction->getData('payment_id');
141144
$idFieldName = $this->getIdFieldName();
142-
145+
$txnType = $transaction->getData('txn_type');
143146
if ($parentTxnId) {
144147
if (!$txnId || !$orderId || !$paymentId) {
145148
throw new \Magento\Framework\Exception\LocalizedException(
146149
__('We don\'t have enough information to save the parent transaction ID.')
147150
);
148151
}
149152
$parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
150-
if ($parentId) {
153+
if ($parentId && $txnType == 'authorization') {
151154
$transaction->setData('parent_id', $parentId);
155+
$transaction->setData('txn_type', \Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE);
156+
}
157+
} else {
158+
$result = $this->getParentId($orderId);
159+
if ($result) {
160+
$transaction->setData('parent_id', $result[0]['transaction_id']);
161+
$transaction->setData('parent_txn_id', $result[0]['parent_txn_id']);
152162
}
153163
}
154164

@@ -169,7 +179,7 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
169179
* @param int $orderId
170180
* @param int $paymentId
171181
* @param string $txnId
172-
* @param mixed (array|string|object) $columns
182+
* @param mixed $columns (array|string|object) $columns
173183
* @param bool $isRow
174184
* @param string $txnType
175185
* @return array|string
@@ -211,4 +221,23 @@ private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $column
211221
$txnId
212222
);
213223
}
224+
225+
/**
226+
* Retrieve transaction by the unique key of order_id
227+
*
228+
* @param int $orderId
229+
* @return array
230+
*/
231+
protected function getParentId(int $orderId): array
232+
{
233+
$connection = $this->getConnection();
234+
$select = $connection->select()->from(
235+
$this->getMainTable(),
236+
['transaction_id','parent_txn_id']
237+
)->where(
238+
'order_id = ?',
239+
$orderId
240+
)->order('transaction_id', 'ASC')->limit(1);
241+
return $connection->fetchAll($select);
242+
}
214243
}

app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Magento\Sales\Model\Order\Pdf\ItemsFactory;
2121
use Magento\Sales\Model\Order\Pdf\Total\DefaultTotal;
2222
use Magento\Sales\Model\Order\Pdf\Total\Factory;
23+
use Magento\Tax\Helper\Data as TaxHelper;
2324
use PHPUnit\Framework\TestCase;
2425

2526
/**
@@ -49,6 +50,7 @@ public function testInsertTotals()
4950
$filesystem = $this->createMock(Filesystem::class);
5051
$pdfItemsFactory = $this->createMock(ItemsFactory::class);
5152
$localeMock = $this->getMockForAbstractClass(TimezoneInterface::class);
53+
$taxHelper = $this->createMock(TaxHelper::class);
5254

5355
// Setup config file totals
5456
$configTotals = ['item1' => [''], 'item2' => ['model' => 'custom_class']];
@@ -98,7 +100,12 @@ public function testInsertTotals()
98100
$pdfItemsFactory,
99101
$localeMock,
100102
$translate,
101-
$addressRenderer
103+
$addressRenderer,
104+
[],
105+
null,
106+
null,
107+
null,
108+
$taxHelper
102109
],
103110
'',
104111
true,
@@ -134,6 +141,7 @@ public function testDrawLineBlocks()
134141
$localeMock = $this->getMockForAbstractClass(TimezoneInterface::class);
135142
$translate = $this->getMockForAbstractClass(StateInterface::class);
136143
$addressRenderer = $this->createMock(Renderer::class);
144+
$taxHelper = $this->createMock(TaxHelper::class);
137145

138146
$abstractPdfMock = $this->getMockForAbstractClass(
139147
AbstractPdf::class,
@@ -147,7 +155,12 @@ public function testDrawLineBlocks()
147155
$pdfItemsFactory,
148156
$localeMock,
149157
$translate,
150-
$addressRenderer
158+
$addressRenderer,
159+
[],
160+
null,
161+
null,
162+
null,
163+
$taxHelper
151164
],
152165
'',
153166
true,

app/code/Magento/SalesRule/view/frontend/web/js/view/payment/captcha.js

Lines changed: 55 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,66 @@
44
*/
55

66
define([
7-
'Magento_Captcha/js/view/checkout/defaultCaptcha',
8-
'Magento_Captcha/js/model/captchaList',
9-
'Magento_SalesRule/js/action/set-coupon-code',
10-
'Magento_SalesRule/js/action/cancel-coupon',
11-
'Magento_Checkout/js/model/quote',
12-
'ko'
13-
],
14-
function (defaultCaptcha, captchaList, setCouponCodeAction, cancelCouponAction, quote, ko) {
15-
'use strict';
7+
'Magento_Captcha/js/view/checkout/defaultCaptcha',
8+
'Magento_Captcha/js/model/captchaList',
9+
'Magento_SalesRule/js/action/set-coupon-code',
10+
'Magento_SalesRule/js/action/cancel-coupon',
11+
'Magento_Checkout/js/model/quote',
12+
'ko'
13+
], function (defaultCaptcha, captchaList, setCouponCodeAction, cancelCouponAction, quote, ko) {
14+
'use strict';
1615

17-
var totals = quote.getTotals(),
18-
couponCode = ko.observable(null),
19-
isApplied;
16+
return defaultCaptcha.extend({
17+
/** @inheritdoc */
18+
initialize: function () {
19+
var self = this,
20+
currentCaptcha,
21+
totals = quote.getTotals(),
22+
couponCode = ko.observable(null),
23+
couponCodeValue,
24+
isApplied;
2025

21-
if (totals()) {
22-
couponCode(totals()['coupon_code']);
23-
}
24-
//Captcha can only be required for adding a coupon so we need to know if one was added already.
25-
isApplied = ko.observable(couponCode() != null);
26+
if (totals()) {
27+
couponCode(totals()['coupon_code']);
28+
}
2629

27-
return defaultCaptcha.extend({
28-
/** @inheritdoc */
29-
initialize: function () {
30-
var self = this,
31-
currentCaptcha;
30+
// Captcha can only be required for adding a coupon so we need to know if one was added already.
31+
couponCodeValue = couponCode();
32+
isApplied = ko.observable(typeof couponCodeValue === 'string' && couponCodeValue.length > 0);
3233

33-
this._super();
34-
//Getting coupon captcha model.
35-
currentCaptcha = captchaList.getCaptchaByFormId(this.formId);
34+
this._super();
35+
//Getting coupon captcha model.
36+
currentCaptcha = captchaList.getCaptchaByFormId(this.formId);
3637

37-
if (currentCaptcha != null) {
38-
if (!isApplied()) {
39-
//Show captcha if we don't have a coupon applied.
40-
currentCaptcha.setIsVisible(true);
41-
}
42-
this.setCurrentCaptcha(currentCaptcha);
43-
//Add captcha code to coupon-apply request.
44-
setCouponCodeAction.registerDataModifier(function (headers) {
45-
if (self.isRequired()) {
46-
headers['X-Captcha'] = self.captchaValue()();
47-
}
48-
});
49-
//Refresh captcha after failed request.
50-
setCouponCodeAction.registerFailCallback(function () {
51-
if (self.isRequired()) {
52-
self.refresh();
53-
}
54-
});
55-
//Hide captcha when a coupon has been applied.
56-
setCouponCodeAction.registerSuccessCallback(function () {
57-
self.setIsVisible(false);
58-
});
59-
//Show captcha again if it was canceled.
60-
cancelCouponAction.registerSuccessCallback(function () {
61-
if (self.isRequired()) {
62-
self.setIsVisible(true);
63-
}
64-
});
38+
if (currentCaptcha != null) {
39+
if (!isApplied()) {
40+
//Show captcha if we don't have a coupon applied.
41+
currentCaptcha.setIsVisible(true);
6542
}
43+
this.setCurrentCaptcha(currentCaptcha);
44+
//Add captcha code to coupon-apply request.
45+
setCouponCodeAction.registerDataModifier(function (headers) {
46+
if (self.isRequired()) {
47+
headers['X-Captcha'] = self.captchaValue()();
48+
}
49+
});
50+
//Refresh captcha after failed request.
51+
setCouponCodeAction.registerFailCallback(function () {
52+
if (self.isRequired()) {
53+
self.refresh();
54+
}
55+
});
56+
//Hide captcha when a coupon has been applied.
57+
setCouponCodeAction.registerSuccessCallback(function () {
58+
self.setIsVisible(false);
59+
});
60+
//Show captcha again if it was canceled.
61+
cancelCouponAction.registerSuccessCallback(function () {
62+
if (self.isRequired()) {
63+
self.setIsVisible(true);
64+
}
65+
});
6666
}
67-
});
67+
}
6868
});
69+
});

0 commit comments

Comments
 (0)