Post by alibags » Fri May 29, 2015 3:25 pm

Hi, I need a discount only if customer buy items from a specific different category, ex:
items from cat. A + cat. B = no discount
items from cat. A + cat. C= no discount
Items from cat. A + cat. D= discount
Items from cat. B + cat. D= discount

Do you know something to works in this way?
Thanks

Simone

New member

Posts

Joined
Wed Apr 22, 2015 8:03 pm


Post by chulcha » Fri May 29, 2015 6:21 pm

Creaate total, category_discount

and in model total/category_discount.php describe rules for discount

Active Member

Posts

Joined
Fri Jul 18, 2014 4:39 pm

Post by alibags » Fri May 29, 2015 6:59 pm

unfortunately I'm not able to create this :(

New member

Posts

Joined
Wed Apr 22, 2015 8:03 pm


Post by chulcha » Sat May 30, 2015 2:22 am

for example

Code: Select all

<?php
class ModelTotalCategoryDiscount extends Model {
	public function getTotal(&$total_data, &$total, &$taxes) {
		$discount = 0;
AB = 0;  //tems from cat. A + cat. B = no discount
AC = 0;  //items from cat. A + cat. C= no discount
AD = NNN;//Items from cat. A + cat. D= discount
BD = MMM;//Items from cat. B + cat. D= discount
		$this->load->model('catalog/product');
		$cat = array();
		foreach ($this->cart->getProducts() as $product) {
			$categories = $this->model_catalog_product->getCategories($product['product_id']);
			foreach ($categories as $category) {
				$cat[$category] = $category;
			}
		}
		$discount = 0;
		if (isset($cat[A]) && isset($cat[B])) {
			$discount = AB;
		} elseif  (isset($cat[A]) && isset($cat[C])){
			$discount = AC;
		} elseif  (isset($cat[A]) && isset($cat[D])){
			$discount = AD;
		} elseif  (isset($cat[B]) && isset($cat[D])){
			$discount = BD;
		}
		
		if ($discount) {
			$total_data[] = array(
					'code'       => 'categorydiscount',
					'title'      => 'categorydiscount',
					'value'      => -$discount,
					'sort_order' => 0
				);

			$total -= $discount;
		}
	}
}

Active Member

Posts

Joined
Fri Jul 18, 2014 4:39 pm

Post by alibags » Sat May 30, 2015 5:20 pm

Thank you chulcha! I'll try to work on this code! :)

New member

Posts

Joined
Wed Apr 22, 2015 8:03 pm


Post by alibags » Wed Jun 03, 2015 2:41 pm

I bought this extension and it works fine for what I need!
http://www.opencart.com/index.php?route ... unt&page=2

New member

Posts

Joined
Wed Apr 22, 2015 8:03 pm

Who is online

Users browsing this forum: No registered users and 7 guests