Jump to content

[SOLVED] how to change discount policies


Recommended Posts

Hi everybody,
How can I change the default " discount behaviour " in prestashop,
this is the case:

- I have customers in certain groups with special discounts and

- I have products in promotion with special discounts

Currently prestashop is applying the discount on the product based on the special reduction on the catalog and applying at the same time the discount based on the group of the customer.
I dont want these customers with already special discounts to access these special discounts when they are buying products in promotion.

is there a way to acomplish this ?

thanks

Hugo

Link to comment
Share on other sites

Change lines 1451-1452 of classes/Product.php (in PrestaShop v1.3.1) from:

// Group reduction
$price *= ((100 - Group::getReduction(((isset($id_customer) AND $id_customer) ? $id_customer : 0))) / 100);



to:

if (!$reduc)
  // Group reduction
  $price *= ((100 - Group::getReduction(((isset($id_customer) AND $id_customer) ? $id_customer : 0))) / 100);



This code will ignore the group reduction if a product reduction has already been applied.

Link to comment
Share on other sites

Hi ,

making that modification to the code solves the problem, but in the store it still displays the price with the product reduction + the group reduction, but the prices are correct when you add the products to the cart
I have also checked the product.php (ps 1.2.5.0) and found this at line 186:

       $smarty->assign(array(

           'quantity_discounts' => QuantityDiscount::getQuantityDiscounts(intval($product->id),

           $product->getPriceWithoutReduct()),

           'product' => $product,

           'jqZoomEnabled' => $jqZoomEnabled,

           'product_manufacturer' => new Manufacturer(intval($product->id_manufacturer)),

           'token' => Tools::getToken(false),

           'productPriceWithoutEcoTax' => floatval($productPriceWithoutEcoTax),

           'features' => $features,

           'attachments' => $attachments,

           'allow_oosp' => $product->isAvailableWhenOutOfStock(intval($product->out_of_stock)),

           'last_qties' =>  intval($configs['PS_LAST_QTIES']),

           'group_reduction' => (100 - Group::getReduction(intval($cookie->id_customer))) / 100,

           'col_img_dir' => _PS_COL_IMG_DIR_,

           'HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'),

           'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'),

           'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($product),

           'HOOK_PRODUCT_FOOTER' => Hook::productFooter($product, $category),

           'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'),

           'HOOK_PRODUCT_TAB' =>  Module::hookExec('productTab'),

           'HOOK_PRODUCT_TAB_CONTENT' =>  Module::hookExec('productTabContent')));



i think there is something to modify here too, the group_reduction part but i dont know exactly how to procede.

I'd appreciate if you could give another hint

thanks in advance

Hugo

Link to comment
Share on other sites

I didn't realise that there is code that wasn't using the getPriceStatic function. If you upgrade to PrestaShop v1.3, you'll need add the following code:

$now = date('Y-m-d H:M:S');



but since you are using PrestaShop v1.2.5, you should add following code instead:

$now = date('Y-m-d');



Then change:

'group_reduction' => (100 - Group::getReduction(intval($cookie->id_customer))) / 100,



to:

'group_reduction' => ((($product->reduction_percent > 0 OR $product->reduction_price > 0) AND ($now >= $product->reduction_from AND $now <= $product->reduction_to)) ? 1 : (100 - Group::getReduction(intval($cookie->id_customer))) / 100),

Link to comment
Share on other sites

Hi the next code

 
'group_reduction' => ((($product->reduction_percent > 0 OR $product->reduction_price > 0) AND ($now >= $product->reduction_from AND $now <= $product->reduction_to)) ? 0 : (100 - Group::getReduction(intval($cookie->id_customer))) / 100),


should be

'group_reduction' => ((($product->reduction_percent > 0 OR $product->reduction_price > 0) AND ($now >= $product->reduction_from AND $now <= $product->reduction_to)) ? 1 : (100 - Group::getReduction(intval($cookie->id_customer))) / 100),


this solved the issue

thanks a lot !

Hugo

Link to comment
Share on other sites

  • 2 weeks later...

In that case, add the following code on line 1429 of classes/Product.php in PrestaShop v1.3.1 (before // Only reduction):

// Ignore price reduction if there is a group reduction
if (Group::getReduction((isset($id_customer) AND $id_customer) ? $id_customer : 0) > 0)
   $reduc = 0;

Link to comment
Share on other sites

Thanks for the quick reply. Worked for me.
To ignore product discount if there is already a group discount applied let me add me some inputs for PS 1.2.5 users.

The code below should be added before line 1271 for PS v. 1.2.5. of classes/Product.php (before //only reduction)

// Ignore price reduction if there is a group reduction
if (Group::getReduction((isset($id_customer) AND $id_customer) ? $id_customer : 0) > 0)
   $reduc = 0; 



And for the product pages, the code below (in product.php of root folder)

'group_reduction' => (100 - Group::getReduction(intval($cookie->id_customer))) / 100,



should be changed by

'group_reduction' => ((($product->reduction_percent = 0 AND $product->reduction_price = 0)) ? 1 : (100 - Group::getReduction(intval($cookie->id_customer))) / 100),



Hope this works.

Link to comment
Share on other sites

  • 2 weeks later...
  • 2 months later...
  • 1 month later...

hi, I've done this, let me check my code to see what needs to be changed, i did it a long time ago, so I am not quite sure wich files you must change, but i think basically it is the /classes/product.php /product.php and /themes/yourtheme/js/product.js and /themes/yourtheme/product.tpl

let me check it

Link to comment
Share on other sites

  • 4 months later...

Hello,

Great update, but have 1 problem. Invoice product price is wrong.
I had update this:

'group_reduction' => ((($product->reduction_percent > 0 OR $product->reduction_price > 0)) ? 1 : (100 - Group::getReduction(intval($cookie->id_customer))) / 100),


if (!$reduc)
  // Group reduction
  $price *= ((100 - Group::getReduction(((isset($id_customer) AND $id_customer) ? $id_customer : 0))) / 100); 



After that work perfect. But in invoice Group discount not working. Maybe have somebody solution?

Thanks

Link to comment
Share on other sites

  • 6 months later...

In order to solve the invoicing problem, you need to change additionaly the file:

 

classes/PaymentModule.php

 

e.g: Prestashop 1.3.7, around line 223

 

change:

 

',
'.floatval(Group::getReduction(intval($order->id_customer))).',

 

to:

 

',
' . ((floatval($reduction_percent) > 0 || floatval($reduction_amount) > 0) ? 0.00 : floatval(Group::getReduction(intval($order->id_customer)))) . ',

 

in order to not apply the group discount when the product has a price reduction.

Link to comment
Share on other sites

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...