Page 1 of 1

How to change handlings fee to percentage?

Posted: Mon Aug 08, 2016 3:37 pm
by yukicyan
How can I set the handling fee to percentage? I would like to have a certain % charges for the total amount of product purchased.

Thanks

Re: How to change handlings fee to percentage?

Posted: Thu Aug 11, 2016 2:37 pm
by knowband.plugins
It can be done easily by modifying following file.

/catalog/model/total/handling.php

Could you plese tell us which version of Opencart are you using so that we can help you.

Re: How to change handlings fee to percentage?

Posted: Fri Aug 12, 2016 9:13 am
by yukicyan
I'm using opencart 2.2.0.0

Re: How to change handlings fee to percentage?

Posted: Fri Aug 12, 2016 3:27 pm
by knowband.plugins
Edit below file

/catalog/model/total/phandling.php

and make changes as shown below

Code: Select all

<?php
class ModelTotalHandling extends Model {
	public function getTotal($total) {
		if (($this->cart->getSubTotal() > $this->config->get('handling_total')) && ($this->cart->getSubTotal() > 0)) {
			$this->load->language('total/handling');
                        $handlingfee=($this->config->get('handling_fee')/100)*$this->cart->getTotal();
			$total['totals'][] = array(
				'code'       => 'handling',
				'title'      => $this->language->get('text_handling'),
				'value'      => $handlingfee,
				'sort_order' => $this->config->get('handling_sort_order')
			);

			if ($this->config->get('handling_tax_class_id')) {
				$tax_rates = $this->tax->getRates($handlingfee, $this->config->get('handling_tax_class_id'));

				foreach ($tax_rates as $tax_rate) {
					if (!isset($total['taxes'][$tax_rate['tax_rate_id']])) {
						$total['taxes'][$tax_rate['tax_rate_id']] = $tax_rate['amount'];
					} else {
						$total['taxes'][$tax_rate['tax_rate_id']] += $tax_rate['amount'];
					}
				}
			}

			$total['total'] += $handlingfee;
		}
	}
}

Re: How to change handlings fee to percentage?

Posted: Fri Aug 12, 2016 3:52 pm
by yukicyan
Well done. Thanks a lot.

Re: How to change handlings fee to percentage?

Posted: Sun Jul 07, 2019 6:32 am
by bless57
hi can you tell me how to do this in opencart 3

Re: How to change handlings fee to percentage?

Posted: Sun Jul 07, 2019 7:01 am
by straightlight
bless57 wrote:
Sun Jul 07, 2019 6:32 am
hi can you tell me how to do this in opencart 3

Code: Select all

<?php
class ModelExtensionTotalHandling extends Model {
	public function getTotal($total) {
		if (($this->cart->getSubTotal() > $this->config->get('total_handling_total')) && ($this->cart->getSubTotal() > 0)) {
			$this->load->language('extension/total/handling');
			
                        $handlingfee = ($this->config->get('total_handling_fee') / 100) * $this->cart->getTotal();
                        
			$total['totals'][] = array(
				'code'       => 'handling',
				'title'      => $this->language->get('text_handling'),
				'value'      => $handlingfee,
				'sort_order' => $this->config->get('total_handling_sort_order')
			);

			if ($this->config->get('total_handling_tax_class_id')) {
				$tax_rates = $this->tax->getRates($handlingfee, $this->config->get('total_handling_tax_class_id'));

				foreach ($tax_rates as $tax_rate) {
					if (!isset($total['taxes'][$tax_rate['tax_rate_id']])) {
						$total['taxes'][$tax_rate['tax_rate_id']] = $tax_rate['amount'];
					} else {
						$total['taxes'][$tax_rate['tax_rate_id']] += $tax_rate['amount'];
					}
				}
			}

			$total['total'] += $handlingfee;
		}
	}
}