Skip to content

Commit

Permalink
admin order creation multistore fix
Browse files Browse the repository at this point in the history
  • Loading branch information
mareknaujas committed Aug 16, 2023
1 parent e41ec7d commit 5b06c4d
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Controller/Payment/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function _getCheckout()
public function execute()
{
$area = $this->getRequest()->getParam('area');
if($area == 'admin'){
if($area == \Magento\Framework\App\Area::AREA_ADMINHTML){
$this->messageManager->addSuccess(__('Your order has been canceled.'));
}

Expand Down
2 changes: 1 addition & 1 deletion Controller/Payment/Returns.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function execute()
{
$area = $this->getRequest()->getParam('area');
$order = $this->getOrder();
if($area == 'admin'){
if($area == \Magento\Framework\App\Area::AREA_ADMINHTML){
$this->messageManager->addSuccess(__('Thank you for your purchase. You will soon receive a confirmation by email.'));
}

Expand Down
3 changes: 2 additions & 1 deletion Cron/AutomaticallyOrderCancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function execute(): void
'state',
['in' => [Order::STATE_PENDING_PAYMENT, Order::STATE_NEW]]
)
->addFieldToFilter('created_at', ['lteq' => $period]);
->addFieldToFilter('created_at', ['lteq' => $period])
->addFieldToFilter('remote_ip', ['neq' => 'NULL']);

$collection->getSelect()
->join(
Expand Down
23 changes: 17 additions & 6 deletions Model/Adapter/QuickPayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use QuickPay\QuickPay;
use Magento\Directory\Model\CountryFactory;
use Magento\Sales\Model\ResourceModel\Order\Tax\Item;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class QuickPayAdapter
Expand Down Expand Up @@ -100,6 +101,11 @@ class QuickPayAdapter
*/
protected $countryFactory;

/**
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;

/**
* @param LoggerInterface $logger
* @param UrlInterface $url
Expand All @@ -112,6 +118,7 @@ class QuickPayAdapter
* @param DirectoryList $dir
* @param Item $taxItem
* @param CountryFactory $countryFactory
* @param StoreManagerInterface $storeManager
*/
public function __construct(
LoggerInterface $logger,
Expand All @@ -124,7 +131,8 @@ public function __construct(
ResourceInterface $moduleResource,
DirectoryList $dir,
Item $taxItem,
CountryFactory $countryFactory
CountryFactory $countryFactory,
StoreManagerInterface $storeManager
)
{
$this->logger = $logger;
Expand All @@ -138,6 +146,7 @@ public function __construct(
$this->dir = $dir;
$this->taxItem = $taxItem;
$this->countryFactory = $countryFactory;
$this->storeManager=$storeManager;
}

/**
Expand Down Expand Up @@ -167,11 +176,13 @@ protected function _generateErrorMessageLine($paymentArray){
* @param array $attributes
* @return array|bool
*/
public function CreatePaymentLink($order, $area = 'frontend')
public function CreatePaymentLink($order, $area = \Magento\Framework\App\Area::AREA_FRONTEND)
{
try {

$response = [];
$storeId = $order->getStoreId();

$this->logger->debug('CREATE PAYMENT');

$api_key = $this->scopeConfig->getValue(self::PUBLIC_KEY_XML_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId);
Expand Down Expand Up @@ -315,10 +326,10 @@ public function CreatePaymentLink($order, $area = 'frontend')
"testmode" => $this->scopeConfig->isSetFlag(self::TEST_MODE_XML_PATH, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
];

if($area == 'adminhtml'){
$parameters['continueurl'] = $this->url->getBaseUrl().'quickpaygateway/payment/returns?area=admin';
$parameters['cancelurl'] = $this->url->getBaseUrl().'quickpaygateway/payment/cancel?area=admin';
$parameters['callbackurl'] = $this->url->getBaseUrl().'quickpaygateway/payment/callback';
if($area == \Magento\Framework\App\Area::AREA_ADMINHTML){
$parameters['continueurl'] = $this->storeManager->getStore($storeId)->getBaseUrl().'quickpaygateway/payment/returns?area='.$area;
$parameters['cancelurl'] = $this->storeManager->getStore($storeId)->getBaseUrl().'quickpaygateway/payment/cancel?area='.$area;
$parameters['callbackurl'] = $this->storeManager->getStore($storeId)->getBaseUrl().'quickpaygateway/payment/callback';
}

//Create payment link and return payment id
Expand Down
2 changes: 1 addition & 1 deletion Observer/SendPaymentEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
}

public function savePaymentLink($order){
$response = $this->adapter->CreatePaymentLink($order, 'adminhtml');
$response = $this->adapter->CreatePaymentLink($order, \Magento\Framework\App\Area::AREA_ADMINHTML);

if(isset($response['url'])){
$payment = $order->getPayment();
Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="QuickPay_Gateway" setup_version="2.3.9">
<module name="QuickPay_Gateway" setup_version="2.4.0">
<sequence>
<module name="Magento_Payment"/>
<module name="Magento_Checkout"/>
Expand Down

0 comments on commit 5b06c4d

Please sign in to comment.