Post by josesoares » Mon Jun 19, 2023 5:42 pm

Hi.
I am making a payment method for opencart4, and while setting the validations for min/max order total and country, I hit a wall.
The situation is the following:
When clicking the "payment method" choose button in the checkout page, it calls the getMethods() function inside my extension, but the argument for $address is empty, so is $total.
I went and step-debugged for the example payment method that comes with opencart 4 and its $address is also empty (note that i did register a consumer user and filled in the address)
I expected the $address and $total arguments to be passed automaticaly like in opencart 3, am I missing something?

Here is an excerpt of the opencar 4 example payment extension for reference (the $address variable should be passed in line 4 of this excerpt):

Code: Select all

<?php
namespace Opencart\Catalog\Model\Extension\OcPaymentExample\Payment;
class CreditCard extends \Opencart\System\Engine\Model {
	public function getMethods(array $address): array {
		$this->load->language('extension/oc_payment_example/payment/credit_card');

		if (!$this->config->get('config_checkout_payment_address')) {
			$status = true;
		} elseif (!$this->config->get('payment_credit_card_geo_zone_id')) {
			$status = true;
		} else {
			$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "zone_to_geo_zone` WHERE `geo_zone_id` = '" . (int)$this->config->get('payment_credit_card_geo_zone_id') . "' AND `country_id` = '" . (int)$address['country_id'] . "' AND (`zone_id` = '" . (int)$address['zone_id'] . "' OR `zone_id` = '0')");

			if ($query->num_rows) {
				$status = true;
			} else {
				$status = false;
			}
		}
Thank you for your help.

New member

Posts

Joined
Mon Jan 23, 2023 5:27 pm

Post by ADD Creative » Mon Jun 19, 2023 6:21 pm

The address should be passed. What is Billing Address required set to in your settings?

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by josesoares » Mon Jun 19, 2023 6:50 pm

Oh, thanks to you pointing that out, I went to the settings and found that option and set it to true.
Now I can get the $address in the getMethods() function.
Is there also an option for being able to get the total amount in getMethods(), like:

Code: Select all

	public function getMethods(array $address = array(), float $total = 0.0): array
	{

New member

Posts

Joined
Mon Jan 23, 2023 5:27 pm

Post by ADD Creative » Mon Jun 19, 2023 7:49 pm

If you look at free_checkout.php as an example, you need to use the following.

Code: Select all

$total = $this->cart->getTotal();

www.add-creative.co.uk


Guru Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by josesoares » Mon Jun 19, 2023 9:38 pm

That did the trick.
That was dumb of me to not check that payment method for reference.
Thank you very much ADD Creative.

New member

Posts

Joined
Mon Jan 23, 2023 5:27 pm

Post by augustkt » Wed Jun 21, 2023 1:44 pm

starting OC 4.0.2.X opencart has replaced getMethod($address) with getMethods(array $address[]),some lower opencart 4.x are still using getMethod($address).
You need to check versions to make sure its compatible with different OpenCart versions

OpenCart module developer.
Email: aug.kutswa@gmail.com
My Extensions


Newbie

Posts

Joined
Mon Apr 17, 2023 7:22 pm
Who is online

Users browsing this forum: No registered users and 3 guests