Page 1 of 1
Category discount
Posted: Fri May 29, 2015 3:25 pm
by alibags
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
Re: Category discount
Posted: Fri May 29, 2015 6:21 pm
by chulcha
Creaate total, category_discount
and in model total/category_discount.php describe rules for discount
Re: Category discount
Posted: Fri May 29, 2015 6:59 pm
by alibags
unfortunately I'm not able to create this

Re: Category discount
Posted: Sat May 30, 2015 2:22 am
by chulcha
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;
}
}
}
Re: Category discount
Posted: Sat May 30, 2015 5:20 pm
by alibags
Thank you chulcha! I'll try to work on this code!

Re: Category discount
Posted: Wed Jun 03, 2015 2:41 pm
by alibags
I bought this extension and it works fine for what I need!
http://www.opencart.com/index.php?route ... unt&page=2