Jump to content

Reduction amount - discount with both amount and %?


Recommended Posts

Hello,

is it possible to make a reduction on amount + %? instead of the current amount or %?

The reason is becuase I have configured our site to use the Pre-tax retail price: as a crossed over, recommended selling price, and enter reduction amount on every products :( at first I thought this will be very useful to help to sell the products, but it became a problem now when we need to clear older stocks... please advice if you have any idea on how to do both together at the same time. Hope someone can please help to point out what to change to make it both work at the same time!

Link to comment
Share on other sites

It is not possible with Prestashop at the moment. In v1.3 final, you'll be able to apply a quantity discount to an amount of 1 and then enter a reduction amount to do this, but it doesn't work in v1.3 beta 1 or v1.2.5. The only way to do it at the moment is to modify the getReductionValue function in classes/Product.php. Try changing the following:

// make the reduction
if ($reduction_price AND $reduction_price > 0)
{
   if ($reduction_price >= $product_price)
       $ret = $product_price;
   else
       $ret = $reduction_price;
}
elseif ($reduction_percent AND $reduction_percent > 0)
{
   if ($reduction_percent >= 100)
       $ret = $product_price;
   else
       $ret = $product_price * $reduction_percent / 100;
}
return isset($ret) ? $ret : 0;



to:

$ret = 0;
// make the reduction
if ($reduction_price AND $reduction_price > 0)
{
   if ($reduction_price >= $product_price)
       $ret = $product_price;
   else
       $ret += $reduction_price;
}
if ($reduction_percent AND $reduction_percent > 0)
{
   if ($reduction_percent >= 100)
       $ret = $product_price;
   else
       $ret += $product_price * $reduction_percent / 100;
}
if ($ret > $product_price)
   $ret = $product_price;
return $ret;

Link to comment
Share on other sites

Hi,

I am unable to try whether the changes works or not, as the prestashop default "add a new product" page still does not allow me to add 2 values at the same time. for example once I enter a value in the discount amount, and when I try to enter a value on discount percentage, it will erase the discount amount entered everytime I try to enter a second value. It only allows me to enter either "discount value" or "discount percentage" in the back office.

I have tried to figure out what is the reason that is not allowing me to enter 2 value at the same time, and I suspect it may be somewhere around here? I may be wrong, as I am not a programmer... it will be great if you could please point out where should I change for prestashop to allow me to enter 2 value at the same time (both discount value, and discount percentage), so that I could test out the changes recommeded on the 2nd post? thanks in advance.

   static public function getRandomSpecial($id_lang, $beginning = false, $ending = false)
   {
       global    $link, $cookie;

       $currentDate = date('Y-m-d');
       $row = Db::getInstance()->getRow('
       SELECT p.*, pl.`description`, pl.`description_short`, pl.`link_rewrite`, pl.`meta_description`, pl.`meta_keywords`, pl.`meta_title`, pl.`name`, p.`ean13`,
           i.`id_image`, il.`legend`, t.`rate`
       FROM `'._DB_PREFIX_.'product` p
       LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'image` i ON (i.`id_product` = p.`id_product` AND i.`cover` = 1)
       LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.intval($id_lang).')
       LEFT JOIN `'._DB_PREFIX_.'tax` t ON t.`id_tax` = p.`id_tax`
       WHERE (`reduction_price` > 0 OR `reduction_percent` > 0)
       '.((!$beginning AND !$ending) ?
           'AND (`reduction_from` = `reduction_to` OR (`reduction_from` <= \''.pSQL($currentDate).'\' AND `reduction_to` >= \''.pSQL($currentDate).'\'))'
       :
           ($beginning ? 'AND `reduction_from` <= \''.pSQL($beginning).'\'' : '').($ending ? 'AND `reduction_to` >= \''.pSQL($ending).'\'' : '')).'
       AND p.`active` = 1
       AND p.`id_product` IN (
           SELECT cp.`id_product`
           FROM `'._DB_PREFIX_.'category_group` cg
           LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`)
           WHERE cg.`id_group` '.(!$cookie->id_customer ?  '= 1' : 'IN (SELECT id_group FROM '._DB_PREFIX_.'customer_group WHERE id_customer = '.intval($cookie->id_customer).')').'
       )
       ORDER BY RAND()');

       if ($row)
           return Product::getProductProperties($id_lang, $row);

       return $row;
   }

Link to comment
Share on other sites

You're looking in the wrong place. It is Javascript that is used to replace the values. Change lines 48-73 of js/price.js from:

function reductionPrice()
{
   var price = document.getElementById('priceTI');
   var newprice = document.getElementById('finalPrice');
   var rprice = document.getElementById('reduction_price');
   document.getElementById('reduction_percent').value = 0;
   if (parseFloat(price.value) <= parseFloat(rprice.value))
       rprice.value = price.value;
   if (parseFloat(rprice.value) < 0 || isNaN(parseFloat(price.value)))
       rprice.value = 0;
   newprice[removed] = (price.value - rprice.value).toFixed(2);
}

function reductionPercent()
{
   var price = document.getElementById('priceTI');
   var newprice = document.getElementById('finalPrice');
   var rpercent = document.getElementById('reduction_percent');
   document.getElementById('reduction_price').value = 0;
   if (parseFloat(rpercent.value) >= 100)
       rpercent.value = 100;
   if (parseFloat(rpercent.value) < 0)
       rpercent.value = 0;
   newprice[removed] = (price.value * (1 - (rpercent.value / 100))).toFixed(2);

}



to:

function reductionPrice()
{
   var price = document.getElementById('priceTI');
   var newprice = document.getElementById('finalPrice');
   var rprice = document.getElementById('reduction_price');
//    document.getElementById('reduction_percent').value = 0;
   if (parseFloat(price.value) <= parseFloat(rprice.value))
       rprice.value = price.value;
   if (parseFloat(rprice.value) < 0 || isNaN(parseFloat(price.value)))
       rprice.value = 0;
   newprice[removed] = (price.value - rprice.value).toFixed(2);
}

function reductionPercent()
{
   var price = document.getElementById('priceTI');
   var newprice = document.getElementById('finalPrice');
   var rpercent = document.getElementById('reduction_percent');
//    document.getElementById('reduction_price').value = 0;
   if (parseFloat(rpercent.value) >= 100)
       rpercent.value = 100;
   if (parseFloat(rpercent.value) < 0)
       rpercent.value = 0;
   newprice[removed] = (price.value * (1 - (rpercent.value / 100))).toFixed(2);

}

Link to comment
Share on other sites

Dear Rocky,

Thank you for your assistance, I really appreciated it. I have tried to make it works, it seems to be closer to be working now.... but for now it appears that by changing the codes that you have suggested, the backoffice allows me to add two value at the same time, but with error on page, it says line 58 and 71 undefined, and when two value is entered, e.g. both amount and percentage, it will only deduct the discount amount, the percentage is not deducted in the calculation on the final price(back office) and price (front office), but it does show thats for e.g. 20% discount on front office beside the price just that the price is not right/deducted on percentage wise. Maybe prestashop at the moment will only choose the first value to use when 2 value is entered... hope you have some clue on how to make prestashop detect, thanks a million :)

Link to comment
Share on other sites

Dear Rocky, thanks for looking into this issue, thank you very much. I am sorry for reporting late, have been quite busy on some business trip recently. I have tried your recommendation, and at least, it does not show error anymore for now, and it appears to allow additing value in both column at the same time, but, discount mechnism will only take the last entered value. So for example if I entered:

Reduction 10% then Reduction $5
it will only reduce $5

and if I enter Reduction $5 first, then Reduction 10%
it will only reduce 10%

it is unable to reduce both at the same time... do you have any idea on how to make the calculation correct? Thanks again and have a nice day.

Link to comment
Share on other sites

  • 2 months later...

Hi Rocky
I have upgrade prestashop to 1.3.1 (ITA) from 1.2.5 (ITA) and I have found an error with discount .
From BO in the product's page ,when I apply a discount ,the final price changes in the right mode, but after that change ,when I look the product's price in catalog (BO) and in all FO's pages the final price doesn't change.
Can you help me please?
what files to edit?

Thanks ,bye bye

Link to comment
Share on other sites

Hi
I'd like to participate in the resolution of the problem, but still do not know its internal structure.
There is another problem with the editor when I add an image with the URL, if the image appears in the editor (with img/photo.jpg) ,it doesn't appear in the FO and if it appears in the FO (with ../img/photo.jpg) ,it doesn't appear in the editor .With the 1.2.5 I used /img/photo.jpg
OK I'll post in the bug tracker (there are alot problem with upgrade in that section )
:grrr:
Bye

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