0
votes

I want to group and display products on shopping cart page by category wise. I mean to say that, if we have four products, then it should be shown like below:

Category 1

  • product i
  • product ii

Category 2

  • product i
  • product ii

I also would like to store the total amount of each category value, in an array. I'm trying to implement category wise discount. Thanks.

EDITED:- This is my shopping cart page, where I'm trying to display discount based on the category of products enter image description here

Suppose, if there are two products in the cart and they belong to two different category. Now I want to calculate discount based on the number of quantity of each category. I have created a module in admin section where I'm setting all the required values, and storing it to the table in database.

enter image description here

Now, based on the values set in the admin I'm trying to implement discount on shopping cart page. But I'm not getting any idea, how could i do that ?

That's why I have no code to place here.

please give some idea, so that i can try creating something. thanks!!

Following is my requirement --

  1. Sale and Delivery Terms:

    • for orders exceeding 600 Francs, delivery is free of charge;
    • for orders less than the above, a delivery charge of 20 Francs, will apply;
  2. Discounts and Quantities

    • Red Wines, White Wines:

      • from 36 bottles, each of 750ml, 6% discount;
      • from 60 bottles, each of 750ml, 10% discount;
      • from 84 bottles, each of 750ml, 13% discount.
    • Fortified Wines (sweet):

      • from 12 bottles, each of 750ml, 5% discount.
    • Discount on Pick up:

      • from 24 bottles, each of 750ml, 3% discount.
    • Cash Payment:

      • from 24 bottles, each of 750ml, 3% discount.
    • Cash Payment on Delivery:

      • 3% discount.
1
your php and mysql code???Joke_Sense10
@Joke_Sense10--- that is general page of opencart, on which i'm trying to do above. but i'm not not getting any idea on how to do it ? that's why i have not posted any code here !!Pankaj Singh

1 Answers

1
votes

It can be achieved as following. we can sort all the products based on there category and can then apply any discount easily..

First you should sort all paroducts ---

////////////// Grouping Same category products into one array //////////////

$category_id = $this->model_discount_cdiscount->getcategory($product['product_id']);

$array_key = $category_id[0]['category_id']; 

if (array_key_exists($array_key, $this->data['discount']))
{

    $this->data['discount'][$array_key]['total'] = $this->data['discount'][$array_key]['total']+(preg_replace("/[^0-9.]/","",$total));
    $this->data['discount'][$array_key]['quantity'] = $this->data['discount'][$array_key]['quantity']+$product['quantity'];
}
else
{
    $this->data['discount'][$array_key] = array(
            'category_name' => $category_id[0]['name'],
            'category_id' => $array_key,
            'total' => (preg_replace("/[^0-9.]/","",$total)),
            'quantity' => $product['quantity'],
            'length' => $product['length']
        );
}

and then can apply ---

////////////////////// Get Discount values from Discount table //////////////////////

foreach($this->data['discount'] as $key2 => $value2)
{
    $this->data['product_match'][] = $this->model_discount_cdiscount->matchDiscount($key2);
}


//////////////////////  Calculate Discount //////////////////////
$total_d =0;
foreach($this->data['discount'] as $discounts)
{
    foreach($this->data['product_match'] as $match)
    {
        if(count($match)!=0)
        {
            if ($discounts['category_id']==$match['category'] AND $discounts['quantity']>=$match['quantity'] AND $discounts['length']==$match['class_value'])
            {

                $dt = ($match['discount']/100)*$discounts['total'];
                $total_d += $dt;
            }
        }
    }

}