Skip to content

Commit

Permalink
Merge pull request #9064 from magento-gl/spartans_pr_04072024
Browse files Browse the repository at this point in the history
[Spartans] Bugfixes Delivery
  • Loading branch information
2 parents ada8d1d + 537ced9 commit 1bafc57
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 88 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,15 +193,17 @@ define([
*/
validateFields: function () {
var addressFlat = addressConverter.formDataProviderToFlatData(
this.collectObservedData(),
'shippingAddress'
this.collectObservedData(),
'shippingAddress'
),
address;

if (this.validateAddressData(addressFlat)) {
addressFlat = uiRegistry.get('checkoutProvider').shippingAddress;
address = addressConverter.formAddressDataToQuoteAddress(addressFlat);
selectShippingAddress(address);
} else {
shippingService.isLoading(false);
}
},

Expand Down
28 changes: 22 additions & 6 deletions app/code/Magento/Sales/Model/Order/Pdf/AbstractPdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Magento\MediaStorage\Helper\File\Storage\Database;
use Magento\Sales\Model\RtlTextHandler;
use Magento\Store\Model\ScopeInterface;
use Magento\Tax\Helper\Data as TaxHelper;

/**
* Sales Order PDF abstract model
Expand Down Expand Up @@ -131,6 +132,11 @@ abstract public function getPdf();
*/
protected $addressRenderer;

/**
* @var Magento\Tax\Helper\Data
*/
private $taxHelper;

/**
* @var array $pageSettings
*/
Expand All @@ -156,6 +162,7 @@ abstract public function getPdf();
* @param Database $fileStorageDatabase
* @param RtlTextHandler|null $rtlTextHandler
* @param Image $image
* @param TaxHelper $taxHelper
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -172,7 +179,8 @@ public function __construct(
array $data = [],
Database $fileStorageDatabase = null,
?RtlTextHandler $rtlTextHandler = null,
?Image $image = null
?Image $image = null,
?TaxHelper $taxHelper = null
) {
$this->addressRenderer = $addressRenderer;
$this->_paymentData = $paymentData;
Expand All @@ -185,6 +193,7 @@ public function __construct(
$this->_pdfTotalFactory = $pdfTotalFactory;
$this->_pdfItemsFactory = $pdfItemsFactory;
$this->inlineTranslation = $inlineTranslation;
$this->taxHelper = $taxHelper ?: ObjectManager::getInstance()->get(TaxHelper::class);
$this->fileStorageDatabase = $fileStorageDatabase ?: ObjectManager::getInstance()->get(Database::class);
$this->rtlTextHandler = $rtlTextHandler ?: ObjectManager::getInstance()->get(RtlTextHandler::class);
$this->image = $image ?: ObjectManager::getInstance()->get(Image::class);
Expand Down Expand Up @@ -604,11 +613,18 @@ protected function insertOrder(&$page, $obj, $putOrderId = true)
}

$yShipments = $this->y;
$totalShippingChargesText = "("
. __('Total Shipping Charges')
. " "
. $order->formatPriceTxt($order->getShippingAmount())
. ")";
$totalShippingChargesText = "(" . __('Total Shipping Charges') . " ";
if ($this->taxHelper->displayShippingPriceIncludingTax()) {
$totalShippingChargesText .= $order->formatPriceTxt($order->getShippingInclTax());
} else {
$totalShippingChargesText .= $order->formatPriceTxt($order->getShippingAmount());
}

if ($this->taxHelper->displayShippingBothPrices()
&& $order->getShippingInclTax() != $order->getShippingAmount()) {
$totalShippingChargesText .= "(Incl. Tax " . $order->getShippingInclTax() . ")";
}
$totalShippingChargesText .= ")";

$page->drawText($totalShippingChargesText, 285, $yShipments - $topMargin, 'UTF-8');
$yShipments -= $topMargin + 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
/**
* Sales transaction resource model
*
* @author Magento Core Team <[email protected]>
*/
class Transaction extends EntityAbstract implements TransactionResourceInterface
{
Expand All @@ -34,7 +33,8 @@ protected function _construct()

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

/**
* Lookup for parent_id in already saved transactions of this payment by the order_id
*
* Also serialize additional information, if any
*
* @param \Magento\Framework\Model\AbstractModel|\Magento\Sales\Model\Order\Payment\Transaction $transaction
* @throws \Magento\Framework\Exception\LocalizedException
* @return $this
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transaction)
{
Expand All @@ -139,16 +142,23 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
$orderId = $transaction->getData('order_id');
$paymentId = $transaction->getData('payment_id');
$idFieldName = $this->getIdFieldName();

$txnType = $transaction->getData('txn_type');
if ($parentTxnId) {
if (!$txnId || !$orderId || !$paymentId) {
throw new \Magento\Framework\Exception\LocalizedException(
__('We don\'t have enough information to save the parent transaction ID.')
);
}
$parentId = (int)$this->_lookupByTxnId($orderId, $paymentId, $parentTxnId, $idFieldName);
if ($parentId) {
if ($parentId && $txnType == 'authorization') {
$transaction->setData('parent_id', $parentId);
$transaction->setData('txn_type', \Magento\Sales\Model\Order\Payment\Transaction::TYPE_CAPTURE);
}
} else {
$result = $this->getParentId($orderId);
if ($result) {
$transaction->setData('parent_id', $result[0]['transaction_id']);
$transaction->setData('parent_txn_id', $result[0]['parent_txn_id']);
}
}

Expand All @@ -169,7 +179,7 @@ protected function _beforeSave(\Magento\Framework\Model\AbstractModel $transacti
* @param int $orderId
* @param int $paymentId
* @param string $txnId
* @param mixed (array|string|object) $columns
* @param mixed $columns (array|string|object) $columns
* @param bool $isRow
* @param string $txnType
* @return array|string
Expand Down Expand Up @@ -211,4 +221,23 @@ private function _getLoadByUniqueKeySelect($orderId, $paymentId, $txnId, $column
$txnId
);
}

/**
* Retrieve transaction by the unique key of order_id
*
* @param int $orderId
* @return array
*/
protected function getParentId(int $orderId): array
{
$connection = $this->getConnection();
$select = $connection->select()->from(
$this->getMainTable(),
['transaction_id','parent_txn_id']
)->where(
'order_id = ?',
$orderId
)->order('transaction_id', 'ASC')->limit(1);
return $connection->fetchAll($select);
}
}
17 changes: 15 additions & 2 deletions app/code/Magento/Sales/Test/Unit/Model/Order/Pdf/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Magento\Sales\Model\Order\Pdf\ItemsFactory;
use Magento\Sales\Model\Order\Pdf\Total\DefaultTotal;
use Magento\Sales\Model\Order\Pdf\Total\Factory;
use Magento\Tax\Helper\Data as TaxHelper;
use PHPUnit\Framework\TestCase;

/**
Expand Down Expand Up @@ -49,6 +50,7 @@ public function testInsertTotals()
$filesystem = $this->createMock(Filesystem::class);
$pdfItemsFactory = $this->createMock(ItemsFactory::class);
$localeMock = $this->getMockForAbstractClass(TimezoneInterface::class);
$taxHelper = $this->createMock(TaxHelper::class);

// Setup config file totals
$configTotals = ['item1' => [''], 'item2' => ['model' => 'custom_class']];
Expand Down Expand Up @@ -98,7 +100,12 @@ public function testInsertTotals()
$pdfItemsFactory,
$localeMock,
$translate,
$addressRenderer
$addressRenderer,
[],
null,
null,
null,
$taxHelper
],
'',
true,
Expand Down Expand Up @@ -134,6 +141,7 @@ public function testDrawLineBlocks()
$localeMock = $this->getMockForAbstractClass(TimezoneInterface::class);
$translate = $this->getMockForAbstractClass(StateInterface::class);
$addressRenderer = $this->createMock(Renderer::class);
$taxHelper = $this->createMock(TaxHelper::class);

$abstractPdfMock = $this->getMockForAbstractClass(
AbstractPdf::class,
Expand All @@ -147,7 +155,12 @@ public function testDrawLineBlocks()
$pdfItemsFactory,
$localeMock,
$translate,
$addressRenderer
$addressRenderer,
[],
null,
null,
null,
$taxHelper
],
'',
true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,66 @@
*/

define([
'Magento_Captcha/js/view/checkout/defaultCaptcha',
'Magento_Captcha/js/model/captchaList',
'Magento_SalesRule/js/action/set-coupon-code',
'Magento_SalesRule/js/action/cancel-coupon',
'Magento_Checkout/js/model/quote',
'ko'
],
function (defaultCaptcha, captchaList, setCouponCodeAction, cancelCouponAction, quote, ko) {
'use strict';
'Magento_Captcha/js/view/checkout/defaultCaptcha',
'Magento_Captcha/js/model/captchaList',
'Magento_SalesRule/js/action/set-coupon-code',
'Magento_SalesRule/js/action/cancel-coupon',
'Magento_Checkout/js/model/quote',
'ko'
], function (defaultCaptcha, captchaList, setCouponCodeAction, cancelCouponAction, quote, ko) {
'use strict';

var totals = quote.getTotals(),
couponCode = ko.observable(null),
isApplied;
return defaultCaptcha.extend({
/** @inheritdoc */
initialize: function () {
var self = this,
currentCaptcha,
totals = quote.getTotals(),
couponCode = ko.observable(null),
couponCodeValue,
isApplied;

if (totals()) {
couponCode(totals()['coupon_code']);
}
//Captcha can only be required for adding a coupon so we need to know if one was added already.
isApplied = ko.observable(couponCode() != null);
if (totals()) {
couponCode(totals()['coupon_code']);
}

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

this._super();
//Getting coupon captcha model.
currentCaptcha = captchaList.getCaptchaByFormId(this.formId);
this._super();
//Getting coupon captcha model.
currentCaptcha = captchaList.getCaptchaByFormId(this.formId);

if (currentCaptcha != null) {
if (!isApplied()) {
//Show captcha if we don't have a coupon applied.
currentCaptcha.setIsVisible(true);
}
this.setCurrentCaptcha(currentCaptcha);
//Add captcha code to coupon-apply request.
setCouponCodeAction.registerDataModifier(function (headers) {
if (self.isRequired()) {
headers['X-Captcha'] = self.captchaValue()();
}
});
//Refresh captcha after failed request.
setCouponCodeAction.registerFailCallback(function () {
if (self.isRequired()) {
self.refresh();
}
});
//Hide captcha when a coupon has been applied.
setCouponCodeAction.registerSuccessCallback(function () {
self.setIsVisible(false);
});
//Show captcha again if it was canceled.
cancelCouponAction.registerSuccessCallback(function () {
if (self.isRequired()) {
self.setIsVisible(true);
}
});
if (currentCaptcha != null) {
if (!isApplied()) {
//Show captcha if we don't have a coupon applied.
currentCaptcha.setIsVisible(true);
}
this.setCurrentCaptcha(currentCaptcha);
//Add captcha code to coupon-apply request.
setCouponCodeAction.registerDataModifier(function (headers) {
if (self.isRequired()) {
headers['X-Captcha'] = self.captchaValue()();
}
});
//Refresh captcha after failed request.
setCouponCodeAction.registerFailCallback(function () {
if (self.isRequired()) {
self.refresh();
}
});
//Hide captcha when a coupon has been applied.
setCouponCodeAction.registerSuccessCallback(function () {
self.setIsVisible(false);
});
//Show captcha again if it was canceled.
cancelCouponAction.registerSuccessCallback(function () {
if (self.isRequired()) {
self.setIsVisible(true);
}
});
}
});
}
});
});
Loading

0 comments on commit 1bafc57

Please sign in to comment.