Post by Skorr » Fri Feb 21, 2014 3:40 pm

Hello there,

I am currently doing a job for someone and he wants to set a percentage discount for orders with "Pickup From Store" shipping method selected.

How can I make such a module to enable this?

I could not find anything on Google that could help me with this. There are some modules related to payment method fees but this is completely different + I don't need any options in this module except to set the discount percentage and that's it.

I've been trying something and thought that this code might work but it actually doesn't.
Please help me, I need to get this done today :/

Code: Select all

class ModelTotalPickupDiscount extends Model {
	public function getTotal(&$total_data, &$total, &$taxes) {
		$this->load->language('total/pickup_discount');
	
		if((isset($this->session->data['shipping_method']) && ($this->session->data['shipping_method']['code'] == 'pickup')) || (isset($this->request->post['shipping']) && ($this->request->post['shipping']=='pickup'))) {
	
            $subTotal = $total;
			$perc = (float)10/100; // 10 is the percentage
            $remove = $subTotal-($subTotal*(1-$perc));			
			
	
			$total_data[] = array( 
				'code'       => 'pickup_discount',
				'title'      => $this->language->get('text_pickup_discount'),
				'text'       => $this->currency->format(-$remove),
				'value'      => -$remove,
				'sort_order' => 5
			);
			
			$total -= $remove;
		
		}
	}
}	

Newbie

Posts

Joined
Fri Feb 21, 2014 3:29 pm

Post by Johnathan » Wed Feb 26, 2014 2:38 am

I have a Shipping-Based Fee/Discount extension that does this.

Your code looks correct, but you'll need to create the back-end of the extension as well, so it installs into the database and shows as "enabled" to OpenCart. When OpenCart then pulls the list of Order Totals, it will be included in the list. If you just have front-end code, it won't ever be loaded.

Image Image Image Image Image


User avatar
Administrator

Posts

Joined
Fri Dec 18, 2009 3:08 am

Who is online

Users browsing this forum: No registered users and 1 guest