Post by xoomit » Thu Oct 29, 2020 12:17 am

Dear OC community,

I would like to have free shipping on all carts that have a voucher. My idea was to edit

Code: Select all

if ($this->cart->getSubTotal() < $this->config->get('shipping_free_total')) {
  $status = false;
}
in "/catalog/model/extension/shipping/free.php" to something like

Code: Select all

if (!$this->cart->hasVoucher() {
  $status = false;
}
However, I neither have a real clue of PHP nor of the OC cart system. So the question is: How could I check if a cart has a voucher applied at this point and set the status to true?

Help would really be appreciated!

Thanks & best,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by straightlight » Thu Oct 29, 2020 12:28 am

xoomit wrote:
Thu Oct 29, 2020 12:17 am
Dear OC community,

I would like to have free shipping on all carts that have a voucher. My idea was to edit

Code: Select all

if ($this->cart->getSubTotal() < $this->config->get('shipping_free_total')) {
  $status = false;
}
in "/catalog/model/extension/shipping/free.php" to something like

Code: Select all

if (!$this->cart->hasVoucher() {
  $status = false;
}
However, I neither have a real clue of PHP nor of the OC cart system. So the question is: How could I check if a cart has a voucher applied at this point and set the status to true?

Help would really be appreciated!

Thanks & best,
Torge
By relying on its session data since vouchers are validated through the cart page before proceeding to checkout page.

In catalog/controller/extension/total/voucher.php file, you could see an e.g.

In your specific scenario, you could use:

Code: Select all

if (isset($this->session->data['voucher'])) {
	$this->load->model('extension/total/voucher');
	
	$voucher_info = $this->model_extension_total_voucher->getVoucher($this->session->data['voucher']);
	
	if ($voucher_info) {
		$status = false;
	}
}
This should resolved the issue.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by xoomit » Thu Oct 29, 2020 12:06 pm

Dear Straightlight,

thanks a lot for the quick reply. I adapted the code a little and it works like a charm!
Thank you so much for your help.

Have a great day,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am
Who is online

Users browsing this forum: No registered users and 77 guests