Page 1 of 1

Bank transfer variable that shows order total ?

Posted: Sat Nov 28, 2020 4:02 am
by algis789
Hi,
Please help.

Iam using bank transfer method at the checkout. (OC 3.0.3.6) and I would like to show a message like :

"Please transfer $48 to bank account 123456. "

But What varriable do I need to display the total amount ($48) the customer should pay me?

Thanks a lot for helping!
Image

Re: Bank transfer variable that shows order total ?

Posted: Sat Nov 28, 2020 4:29 am
by straightlight
An event could easily achieve this. From the core, in your catalog/controller/extension/payment/bank_transfer.php file:

Code: Select all

<?php
class ControllerExtensionPaymentBankTransfer extends Controller {
	public function index() {
		$this->load->language('extension/payment/bank_transfer');

		if (isset($this->session->data['order_id'])) {
			$this->load->model('checkout/order');
			
			$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
			
			if ($order_info) {
				$data['text_description'] = sprintf($this->language->get('text_description'), $this->currency->format($order_info['total'], $this->config->get('config_currency')));
				
				$data['bank'] = nl2br($this->config->get('payment_bank_transfer_bank' . $this->config->get('config_language_id')));
			}
		}

		return $this->load->view('extension/payment/bank_transfer', $data);
	}

	public function confirm() {
		$json = array();
		
		if ($this->session->data['payment_method']['code'] == 'bank_transfer') {
			$this->load->language('extension/payment/bank_transfer');

			$this->load->model('checkout/order');

			$comment  = $this->language->get('text_instruction') . "\n\n";
			$comment .= $this->config->get('payment_bank_transfer_bank' . $this->config->get('config_language_id')) . "\n\n";
			$comment .= $this->language->get('text_payment');

			$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_bank_transfer_order_status_id'), $comment, true);
		
			$json['redirect'] = $this->url->link('checkout/success');
		}
		
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));		
	}
}
Then, in your catalog/language/<your_language>/extension/payment/bank_transfer.php file,

replace:

Code: Select all

$_['text_description'] = 'Please transfer the total amount to the following bank account.';
with:

Code: Select all

$_['text_description'] = 'Please transfer the total amount of %s to the following bank account.';
This should resolve the issue.

Re: Bank transfer variable that shows order total ?

Posted: Sat Nov 28, 2020 11:19 pm
by algis789
straightlight wrote:
Sat Nov 28, 2020 4:29 am
An event could easily achieve this. From the core, in your catalog/controller/extension/payment/bank_transfer.php file:

Code: Select all

<?php
class ControllerExtensionPaymentBankTransfer extends Controller {
	public function index() {
		$this->load->language('extension/payment/bank_transfer');

		if (isset($this->session->data['order_id'])) {
			$this->load->model('checkout/order');
			
			$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
			
			if ($order_info) {
				$data['text_description'] = sprintf($this->language->get('text_description'), $this->currency->format($order_info['total'], $this->config->get('config_currency')));
				
				$data['bank'] = nl2br($this->config->get('payment_bank_transfer_bank' . $this->config->get('config_language_id')));
			}
		}

		return $this->load->view('extension/payment/bank_transfer', $data);
	}

	public function confirm() {
		$json = array();
		
		if ($this->session->data['payment_method']['code'] == 'bank_transfer') {
			$this->load->language('extension/payment/bank_transfer');

			$this->load->model('checkout/order');

			$comment  = $this->language->get('text_instruction') . "\n\n";
			$comment .= $this->config->get('payment_bank_transfer_bank' . $this->config->get('config_language_id')) . "\n\n";
			$comment .= $this->language->get('text_payment');

			$this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('payment_bank_transfer_order_status_id'), $comment, true);
		
			$json['redirect'] = $this->url->link('checkout/success');
		}
		
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));		
	}
}
Then, in your catalog/language/<your_language>/extension/payment/bank_transfer.php file,

replace:

Code: Select all

$_['text_description'] = 'Please transfer the total amount to the following bank account.';
with:

Code: Select all

$_['text_description'] = 'Please transfer the total amount of %s to the following bank account.';
This should resolve the issue.
Thanks, I would be very grateful if you could explain how to work with% ORDER_TOTAL% in the bank-transfer description, I made it to show% ORDER_ID%, but it doesn't get ORDER_TOTAL. help please.

Image

Image

Re: Bank transfer variable that shows order total ?

Posted: Sun Nov 29, 2020 1:41 am
by straightlight
Use sprintf, not str_replace. It's not good practice with the scenario you're showing. Use my e.g above with sprintf and add another %s in the text definition. You could also create another language key in the same language file and use sprintf on that controller separately. Both works.