Skip to content

Commit

Permalink
Merge pull request #138 from bold-commerce/Q1-504
Browse files Browse the repository at this point in the history
Incorrect price after placing order using non default currency
  • Loading branch information
nmalevanec authored Sep 14, 2023
2 parents d2d3456 + 6adc28b commit ef99acf
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 42 deletions.
13 changes: 12 additions & 1 deletion Model/Order/PlaceOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Exception;
use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Place magento order with bold payment service.
Expand Down Expand Up @@ -68,6 +69,11 @@ class PlaceOrder implements PlaceOrderInterface
*/
private $progress;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param ShopIdValidator $shopIdValidator
* @param OrderPayloadValidator $orderPayloadValidator
Expand All @@ -78,6 +84,7 @@ class PlaceOrder implements PlaceOrderInterface
* @param CreateOrderFromPayload $createOrderFromPayload
* @param ProcessOrder $processOrder
* @param Progress $progress
* @param StoreManagerInterface $storeManager
*/
public function __construct(
ShopIdValidator $shopIdValidator,
Expand All @@ -88,7 +95,8 @@ public function __construct(
ConfigInterface $config,
CreateOrderFromPayload $createOrderFromPayload,
ProcessOrder $processOrder,
Progress $progress
Progress $progress,
StoreManagerInterface $storeManager
) {
$this->responseFactory = $responseFactory;
$this->errorFactory = $errorFactory;
Expand All @@ -99,6 +107,7 @@ public function __construct(
$this->createOrderFromPayload = $createOrderFromPayload;
$this->processOrder = $processOrder;
$this->progress = $progress;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -116,6 +125,8 @@ public function place(string $shopId, OrderDataInterface $order): ResultInterfac
$this->orderPayloadValidator->validate($order);
$quote = $this->cartRepository->get($order->getQuoteId());
$this->shopIdValidator->validate($shopId, $quote->getStoreId());
$this->storeManager->setCurrentStore($quote->getStoreId());
$this->storeManager->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode());
} catch (LocalizedException $e) {
$this->progress->stop($order);
return $this->getValidationErrorResponse($e->getMessage());
Expand Down
36 changes: 0 additions & 36 deletions Model/Order/PlaceOrder/ProcessOrderPayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,42 +53,6 @@ public function process(
): void {
$orderPayment = $order->getPayment();
$orderPayment->addData($payment->getData());
$baseAmountOrdered = $payment->getBaseAmountOrdered()
?: $order->getOrderCurrency()->convert(
$payment->getAmountOrdered(),
$order->getBaseCurrency()
);
$amountOrdered = $payment->getAmountOrdered()
?: $order->getBaseCurrency()->convert(
$baseAmountOrdered,
$order->getOrderCurrency()
);
$baseAmountAuthorized = $payment->getBaseAmountAuthorized()
?: $order->getOrderCurrency()->convert(
$payment->getAmountAuthorized(),
$order->getBaseCurrency()
);
$amountAuthorized = $payment->getAmountAuthorized()
?: $order->getBaseCurrency()->convert(
$baseAmountAuthorized,
$order->getOrderCurrency()
);
$baseAmountPaid = $payment->getBaseAmountPaid()
?: $order->getOrderCurrency()->convert(
$payment->getAmountPaid(),
$order->getBaseCurrency()
);
$amountPaid = $payment->getAmountPaid()
?: $order->getBaseCurrency()->convert(
$baseAmountPaid,
$order->getOrderCurrency()
);
$orderPayment->setBaseAmountOrdered($baseAmountOrdered);
$orderPayment->setAmountOrdered($amountOrdered);
$orderPayment->setBaseAmountAuthorized($baseAmountAuthorized);
$orderPayment->setAmountAuthorized($amountAuthorized ?: $amountOrdered);
$orderPayment->setBaseAmountPaid($baseAmountPaid);
$orderPayment->setAmountPaid($amountPaid);
$orderPayment->setAdditionalInformation(
array_merge(
$orderPayment->getAdditionalInformation() ?: [],
Expand Down
13 changes: 12 additions & 1 deletion Model/Quote/GetQuote.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Magento\Checkout\Model\Cart;
use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Set quote addresses service.
Expand All @@ -36,22 +37,30 @@ class GetQuote implements GetQuoteInterface
*/
private $cart;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param CartRepositoryInterface $cartRepository
* @param ShopIdValidator $shopIdValidator
* @param Builder $quoteResultBuilder
* @param Cart $cart used for the backward compatibility with earlier versions of Magento.
* @param StoreManagerInterface $storeManager
*/
public function __construct(
CartRepositoryInterface $cartRepository,
ShopIdValidator $shopIdValidator,
Builder $quoteResultBuilder,
Cart $cart
Cart $cart,
StoreManagerInterface $storeManager
) {
$this->cartRepository = $cartRepository;
$this->shopIdValidator = $shopIdValidator;
$this->quoteResultBuilder = $quoteResultBuilder;
$this->cart = $cart;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -64,6 +73,8 @@ public function getQuote(
try {
$quote = $this->cartRepository->getActive($cartId);
$this->shopIdValidator->validate($shopId, $quote->getStoreId());
$this->storeManager->setCurrentStore($quote->getStoreId());
$this->storeManager->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode());
} catch (LocalizedException $e) {
return $this->quoteResultBuilder->createErrorResult($e->getMessage());
}
Expand Down
2 changes: 2 additions & 0 deletions Model/Quote/GetQuoteInventoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ public function getInventory(string $shopId, int $cartId): ResultInterface
try {
$quote = $this->cartRepository->getActive($cartId);
$this->shopIdValidator->validate($shopId, $quote->getStoreId());
$this->storeManager->setCurrentStore($quote->getStoreId());
$this->storeManager->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode());
} catch (LocalizedException $e) {
return $this->buildErrorResponse($e->getMessage());
}
Expand Down
13 changes: 12 additions & 1 deletion Model/Quote/RemoveQuoteCouponCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Exception;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\CouponManagementInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Remove quote coupon code service.
Expand All @@ -36,22 +37,30 @@ class RemoveQuoteCouponCode implements RemoveQuoteCouponCodeInterface
*/
private $shopIdValidator;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param ShopIdValidator $shopIdValidator
* @param CouponManagementInterface $couponService
* @param CartRepositoryInterface $cartRepository
* @param Builder $quoteResultBuilder
* @param StoreManagerInterface $storeManager
*/
public function __construct(
ShopIdValidator $shopIdValidator,
CouponManagementInterface $couponService,
CartRepositoryInterface $cartRepository,
Builder $quoteResultBuilder
Builder $quoteResultBuilder,
StoreManagerInterface $storeManager
) {
$this->couponService = $couponService;
$this->quoteResultBuilder = $quoteResultBuilder;
$this->cartRepository = $cartRepository;
$this->shopIdValidator = $shopIdValidator;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -62,6 +71,8 @@ public function removeCoupon(string $shopId, int $cartId): ResultInterface
try {
$quote = $this->cartRepository->getActive($cartId);
$this->shopIdValidator->validate($shopId, $quote->getStoreId());
$this->storeManager->setCurrentStore($quote->getStoreId());
$this->storeManager->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode());
$this->couponService->remove($cartId);
} catch (Exception $e) {
return $this->quoteResultBuilder->createErrorResult($e->getMessage());
Expand Down
13 changes: 12 additions & 1 deletion Model/Quote/SetQuoteAddresses.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Quote\Api\Data\AddressInterface;
use Magento\Quote\Api\Data\CartInterface;
use Magento\Quote\Model\Quote\ShippingAssignment\ShippingAssignmentProcessor;
use Magento\Store\Model\StoreManagerInterface;

/**
* Set quote addresses service.
Expand Down Expand Up @@ -44,25 +45,33 @@ class SetQuoteAddresses implements SetQuoteAddressesInterface
*/
private $cart;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param CartRepositoryInterface $cartRepository
* @param ShopIdValidator $shopIdValidator
* @param ShippingAssignmentProcessor $shippingAssignmentProcessor
* @param Builder $quoteResultBuilder
* @param Cart $cart used for the backward compatibility with earlier versions of Magento.
* @param StoreManagerInterface $storeManager
*/
public function __construct(
CartRepositoryInterface $cartRepository,
ShopIdValidator $shopIdValidator,
ShippingAssignmentProcessor $shippingAssignmentProcessor,
Builder $quoteResultBuilder,
Cart $cart
Cart $cart,
StoreManagerInterface $storeManager
) {
$this->cartRepository = $cartRepository;
$this->shopIdValidator = $shopIdValidator;
$this->shippingAssignmentProcessor = $shippingAssignmentProcessor;
$this->quoteResultBuilder = $quoteResultBuilder;
$this->cart = $cart;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -77,6 +86,8 @@ public function setAddresses(
try {
$quote = $this->cartRepository->getActive($cartId);
$this->shopIdValidator->validate($shopId, $quote->getStoreId());
$this->storeManager->setCurrentStore($quote->getStoreId());
$this->storeManager->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode());
} catch (LocalizedException $e) {
return $this->quoteResultBuilder->createErrorResult($e->getMessage());
}
Expand Down
13 changes: 12 additions & 1 deletion Model/Quote/SetQuoteCouponCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Exception;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Quote\Api\CouponManagementInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Set quote coupon code service.
Expand Down Expand Up @@ -42,25 +43,33 @@ class SetQuoteCouponCode implements SetQuoteCouponCodeInterface
*/
private $config;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param ShopIdValidator $shopIdValidator
* @param CouponManagementInterface $couponService
* @param CartRepositoryInterface $cartRepository
* @param Builder $quoteResultBuilder
* @param ConfigInterface $config
* @param StoreManagerInterface $storeManager
*/
public function __construct(
ShopIdValidator $shopIdValidator,
CouponManagementInterface $couponService,
CartRepositoryInterface $cartRepository,
Builder $quoteResultBuilder,
ConfigInterface $config
ConfigInterface $config,
StoreManagerInterface $storeManager
) {
$this->couponService = $couponService;
$this->quoteResultBuilder = $quoteResultBuilder;
$this->cartRepository = $cartRepository;
$this->shopIdValidator = $shopIdValidator;
$this->config = $config;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -70,6 +79,8 @@ public function setCoupon(string $shopId, int $cartId, string $couponCode): Resu
{
try {
$quote = $this->cartRepository->getActive($cartId);
$this->storeManager->setCurrentStore($quote->getStoreId());
$this->storeManager->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode());
if ($this->config->isCheckoutTypeSelfHosted((int)$quote->getStore()->getWebsiteId())) {
return $this->quoteResultBuilder->createSuccessResult($quote);
}
Expand Down
13 changes: 12 additions & 1 deletion Model/Quote/SetQuoteShippingMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Checkout\Model\Cart;
use Magento\Framework\Exception\LocalizedException;
use Magento\Quote\Api\CartRepositoryInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Set quote shipping method service.
Expand Down Expand Up @@ -59,6 +60,11 @@ class SetQuoteShippingMethod implements SetQuoteShippingMethodInterface
*/
private $cart;

/**
* @var StoreManagerInterface
*/
private $storeManager;

/**
* @param ShippingInformationManagementInterface $shippingInformationManagement
* @param ShippingInformationInterfaceFactory $shippingInformationFactory
Expand All @@ -67,6 +73,7 @@ class SetQuoteShippingMethod implements SetQuoteShippingMethodInterface
* @param Builder $quoteResultBuilder
* @param ConfigInterface $config
* @param Cart $cart used for the backward compatibility with earlier versions of Magento.
* @param StoreManagerInterface $storeManager
*/
public function __construct(
ShippingInformationManagementInterface $shippingInformationManagement,
Expand All @@ -75,7 +82,8 @@ public function __construct(
ShopIdValidator $shopIdValidator,
Builder $quoteResultBuilder,
ConfigInterface $config,
Cart $cart
Cart $cart,
StoreManagerInterface $storeManager
) {
$this->shippingInformationManagement = $shippingInformationManagement;
$this->shippingInformationFactory = $shippingInformationFactory;
Expand All @@ -84,6 +92,7 @@ public function __construct(
$this->shopIdValidator = $shopIdValidator;
$this->config = $config;
$this->cart = $cart;
$this->storeManager = $storeManager;
}

/**
Expand All @@ -98,6 +107,8 @@ public function setShippingMethod(
try {
$quote = $this->cartRepository->getActive($cartId);
$this->shopIdValidator->validate($shopId, $quote->getStoreId());
$this->storeManager->setCurrentStore($quote->getStoreId());
$this->storeManager->getStore()->setCurrentCurrencyCode($quote->getQuoteCurrencyCode());
} catch (LocalizedException $e) {
return $this->quoteResultBuilder->createErrorResult($e->getMessage());
}
Expand Down

0 comments on commit ef99acf

Please sign in to comment.