Page 1 of 1
Check if a cart has a voucher (hasVoucher)
Posted: Thu Oct 29, 2020 12:17 am
by xoomit
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
Re: Check if a cart has a voucher (hasVoucher)
Posted: Thu Oct 29, 2020 12:28 am
by straightlight
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.
Re: Check if a cart has a voucher (hasVoucher)
Posted: Thu Oct 29, 2020 12:06 pm
by xoomit
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