Jump to content

[SOLVED] Customer/category groups and reduction


Recommended Posts

Good day to you all!

I have the following data:

group 1, the default group
group 1010, 25% reduction
group 1020, 10% reduction

customer A belongs to group 1010 only (and 1 ofcourse).

category X is connected to both groups 1 and 1010
category Y is connected to group 1 and 1020.

I expect customer A to get 0% reduction on products from category Y because he does not belong to group 1020 and 25% on products from category X (due to the membership of group 1010).
But as I noticed, customer A gets 25% reduction on both categories.

What am I doing wrong?

Greetz,

Sooi

Link to comment
Share on other sites

SOLVED!

I solved the problem myself.

I added a function to the Group class to filter the groups which are common to categories and customers
The order it by reduction descending and you have the appropriate reduction for products from that category for a specific customer.

For who is interested:

static public function getProductReduction($id_product, $id_customer)
{
 $result = Db::getInstance()->getRow('
 SELECT 
   g.`reduction`
 FROM 
   `'._DB_PREFIX_.'group` g
   INNER JOIN `'._DB_PREFIX_.'customer_group` cug ON (cug.`id_group` = g.`id_group`)
   INNER JOIN `'._DB_PREFIX_.'category_group` cag ON (cag.`id_group` = g.`id_group`)
   INNER JOIN`'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cag.`id_category`)
 WHERE 
   g.`reduction` > 0 AND 
   cug.`id_customer` = '.intval($id_customer).' AND 
   cp.`id_product` = '.intval($id_product).'
 ORDER BY 
   g.`reduction` DESC');

 return $result['reduction'];
}



The modify the file product.php (from the Prestashop base folder) by changing

Group::getReduction(intval($cookie->id_customer))



into

Group::getProductReduction(intval($product->id_product), intval($cookie->id_customer))



and classes\Product.php

Group::getReduction($id_customer))



into

Group::getProductReduction($id_product, $id_customer))

Link to comment
Share on other sites

  • 2 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...