Skip to content

Commit

Permalink
Merge pull request #59 from two-inc/brtkwr-two/cet-537-fix-issue-with…
Browse files Browse the repository at this point in the history
…-saving-address-for-logged-in-customers

CET-537/fix: Issue with saving address for logged in customers
  • Loading branch information
brtkwr authored Dec 5, 2024
2 parents 25cc13b + c452cb8 commit 5041345
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ repos:
- -l
language: system
files: '\.(php)$'
- repo: git@github.com:two-inc/git-hooks
rev: 24.07.26
- repo: https://github.com/two-inc/git-hooks
rev: 24.11.29
hooks:
- id: commit-msg
stages: [commit-msg]
Expand Down
31 changes: 17 additions & 14 deletions Controller/Payment/Confirm.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
*/
class Confirm extends Action
{
public const STATE_CONFIRMED = 'CONFIRMED';
public const STATE_VERIFIED = 'VERIFIED';

/**
* @var ConfigRepository
*/
Expand Down Expand Up @@ -76,10 +73,10 @@ public function execute()
try {
$order = $this->orderService->getOrderByReference();
$twoOrder = $this->orderService->getTwoOrderFromApi($order);
if (isset($twoOrder['state']) &&
(($twoOrder['state'] == self::STATE_VERIFIED) || ($twoOrder['state'] == self::STATE_CONFIRMED))
) {
$this->orderService->confirmOrder($order);
if (isset($twoOrder['state']) && $twoOrder['state'] != 'UNVERIFIED') {
if (in_array($twoOrder['state'], ['VERIFIED', 'CONFIRMED'])) {
$this->orderService->confirmOrder($order);
}
$this->orderSender->send($order);
if ($order->getCustomerId()) {
if ($order->getBillingAddress()->getCustomerAddressId()) {
Expand All @@ -97,20 +94,27 @@ public function execute()
$customerAddress = $customerAddressCollection[0] ?? null;
}
if ($customerAddress && $customerAddress->getId()) {
$this->saveAddressMetadata(
$this->copyMetadataToAddress(
$twoOrder,
$customerAddress
);
$this->addressRepository->save($customerAddress);
}
} else {
$this->saveAddressMetadata(
// Save metadata to shipping address
$shippingAddress = $order->getShippingAddress();
$this->copyMetadataToAddress(
$twoOrder,
$order->getShippingAddress()
$shippingAddress
);
$this->saveAddressMetadata(
$shippingAddress->save();
// Save metadata to billing address
$billingAddress = $order->getBillingAddress();
$this->copyMetadataToAddress(
$twoOrder,
$order->getBillingAddress()
$billingAddress
);
$billingAddress->save();
}
$this->orderService->processOrder($order, $twoOrder['id']);
return $this->getResponse()->setRedirect($this->_url->getUrl('checkout/onepage/success'));
Expand Down Expand Up @@ -145,7 +149,7 @@ public function execute()
*
* @throws Exception
*/
public function saveAddressMetadata(array $twoOrder, $address)
public function copyMetadataToAddress(array $twoOrder, $address)
{
if (isset($twoOrder['buyer']['company']['organization_number'])) {
$address->setData('company_id', $twoOrder['buyer']['company']['organization_number']);
Expand All @@ -159,6 +163,5 @@ public function saveAddressMetadata(array $twoOrder, $address)
if (isset($twoOrder['buyer_project'])) {
$address->setData('project', $twoOrder['buyer_project']);
}
$address->save();
}
}
38 changes: 20 additions & 18 deletions Service/Payment/OrderService.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,25 +301,27 @@ public function processOrder(Order $order, string $transactionId)
$order->setState(Order::STATE_PROCESSING);
$order->setStatus(Order::STATE_PROCESSING);
$invoice = $this->invoiceService->prepareInvoice($order);
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE);
$invoice->register();
$this->addOrderComment(
$order,
sprintf(
'%s order payment has been verified',
$this->configRepository::PROVIDER
)
);
$transactionSave = $this->transaction
->addObject(
$payment
)->addObject(
$invoice
)->addObject(
$invoice->getOrder()
if ($invoice->getGrandTotal() > 0) {
$invoice->setRequestedCaptureCase(Invoice::CAPTURE_ONLINE);
$invoice->register();
$this->addOrderComment(
$order,
sprintf(
'%s order payment has been verified',
$this->configRepository::PROVIDER
)
);
$transactionSave->save();
$this->addAuthorizationTransaction($order, $transactionId);
$transactionSave = $this->transaction
->addObject(
$payment
)->addObject(
$invoice
)->addObject(
$invoice->getOrder()
);
$transactionSave->save();
$this->addAuthorizationTransaction($order, $transactionId);
}
}
return $this;
}
Expand Down
11 changes: 6 additions & 5 deletions view/frontend/web/js/view/payment/method-renderer/two_payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,6 @@ define([
},
fillCustomerData: function () {
const self = this;
quote.shippingAddress.subscribe((address) => self.updateShippingAddress(address));
this.updateShippingAddress(quote.shippingAddress());

quote.billingAddress.subscribe((address) => self.updateBillingAddress(address));
this.updateBillingAddress(quote.billingAddress());

customerData
.get('companyData')
Expand All @@ -198,6 +193,12 @@ define([
.get('countryCode')
.subscribe((countryCode) => self.fillCountryCode(countryCode));
this.fillCountryCode(customerData.get('countryCode')());

quote.shippingAddress.subscribe((address) => self.updateShippingAddress(address));
this.updateShippingAddress(quote.shippingAddress());

quote.billingAddress.subscribe((address) => self.updateBillingAddress(address));
this.updateBillingAddress(quote.billingAddress());
},
afterPlaceOrder: function () {
const url = $.mage.cookies.get(config.redirectUrlCookieCode);
Expand Down

0 comments on commit 5041345

Please sign in to comment.