Skip to content

Commit

Permalink
compatible osc
Browse files Browse the repository at this point in the history
  • Loading branch information
bdtrung committed Jun 18, 2021
1 parent fd59302 commit 47e9868
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Api/CheckoutManagementInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ interface CheckoutManagementInterface
/**
* @param string $cartId
* @param string $address
* @param boolean $isOsc
*
* @return bool
*/
public function updateOrder($cartId, $address);
public function updateOrder($cartId, $address, $isOsc);
}
18 changes: 13 additions & 5 deletions Helper/EmailMarketing.php
Original file line number Diff line number Diff line change
Expand Up @@ -710,12 +710,14 @@ public function getOrderViewUrl($storeId, $orderId, $path = 'sales/order/view')

/**
* @param Quote $quote
* @param array|null $address
* @param boolean $isOsc
*
* @return array
* @throws NoSuchEntityException
* @throws LocalizedException
* @throws NoSuchEntityException
*/
public function getACEData($quote, $address = null)
public function getACEData($quote, array $address = null, $isOsc = false)
{
$isActive = (bool) $quote->getIsActive();
$quoteCompletedAt = null;
Expand Down Expand Up @@ -755,7 +757,7 @@ public function getACEData($quote, $address = null)
'total_tax' => !$quote->isVirtual() ? $quote->getShippingAddress()->getBaseTaxAmount() : 0,
'customer_locale' => null,
'shipping_address' => $this->getShippingAddress($quote, $address),
'billing_address' => $this->getBillingAddress($quote, $address)
'billing_address' => $this->getBillingAddress($quote, $address, $isOsc)
];
}

Expand All @@ -773,15 +775,21 @@ public function getShippingAddress(Quote $quote, $address = null)
/**
* @param Quote $quote
* @param array|null $address
* @param boolean $isOsc
*
* @return array
*/
public function getBillingAddress(Quote $quote, $address = null)
public function getBillingAddress(Quote $quote, $address = null, $isOsc = false)
{
$field = 'billingAddress';
$paymentMethod = $quote->getPayment()->getMethod();

if ($paymentMethod) {
return $this->getAddress($quote, $quote->getBillingAddress(), $address, 'billingAddress' . $paymentMethod);
if (!$isOsc) {
$field .= $paymentMethod;
}

return $this->getAddress($quote, $quote->getBillingAddress(), $address, $field);
}

return [];
Expand Down
6 changes: 3 additions & 3 deletions Model/CheckoutManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function __construct(
/**
* {@inheritDoc}
*/
public function updateOrder($cartId, $address)
public function updateOrder($cartId, $address, $isOsc)
{
if ($this->helperEmailMarketing->isEnableEmailMarketing() &&
$this->helperEmailMarketing->getSecretKey() &&
Expand All @@ -77,8 +77,8 @@ public function updateOrder($cartId, $address)
$quoteIdMask = $this->quoteIdMaskFactory->create()->load($cartId, 'masked_id');
/** @var Quote $quote */
$quote = $this->cartRepository->getActive($quoteIdMask->getQuoteId());
$shippingAddress = EmailMarketing::jsonDecode($address);
$ACEData = $this->helperEmailMarketing->getACEData($quote, $shippingAddress);
$newAddress = EmailMarketing::jsonDecode($address);
$ACEData = $this->helperEmailMarketing->getACEData($quote, $newAddress, $isOsc);

$this->helperEmailMarketing->sendRequestWithoutWaitResponse(
$ACEData,
Expand Down
5 changes: 3 additions & 2 deletions view/frontend/web/js/action/send-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ define([
], function (storage, resourceUrlManager, quote) {
'use strict';

return function (address) {
return function (address, isOsc) {
return storage.post(
resourceUrlManager.getUrlForUpdateOrder(quote),
JSON.stringify({
address: address
address: address,
isOsc: isOsc
}),
false
);
Expand Down
5 changes: 4 additions & 1 deletion view/frontend/web/js/model/billing-address-on-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ define([
element.on('value', function () {
clearTimeout(self.validateAddressTimeout);
self.validateAddressTimeout = setTimeout(function () {
sendAddress(JSON.stringify(self.collectObservedData()));
sendAddress(JSON.stringify(self.collectObservedData()), self.isOsc());
}, delay);
});

Expand All @@ -87,6 +87,9 @@ define([
});

return observedValues;
},
isOsc: function () {
return !!window.checkoutConfig.oscConfig;
}
};
});
2 changes: 1 addition & 1 deletion view/frontend/web/js/model/shipping-address-on-change.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ define([
element.on('value', function () {
clearTimeout(self.validateAddressTimeout);
self.validateAddressTimeout = setTimeout(function () {
sendAddress(JSON.stringify(self.collectObservedData()));
sendAddress(JSON.stringify(self.collectObservedData()), false);
}, delay);
});

Expand Down
11 changes: 10 additions & 1 deletion view/frontend/web/js/view/billing-address-mixins.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,17 @@ define(

var mixin = {
initialize: function () {
var fieldset;

this._super();
billingAddressOnChange.initFields(this.get('name') + '.form-fields')

if (window.checkoutConfig.oscConfig) {
fieldset = this.get('name') + '.billing-address-fieldset';
} else {
fieldset = this.get('name') + '.form-fields';
}

billingAddressOnChange.initFields(fieldset);
},
};

Expand Down

0 comments on commit 47e9868

Please sign in to comment.