Jump to content

If Condition for reference


Recommended Posts

It is not possible to do in classes/Tools.php since you don't have access to the product. I suggest that you instead modify the getPriceStatic function in classes/Product.php. Change line 1247 from:

SELECT p.`price`, p.`reduction_price`, p.`reduction_percent`, p.`reduction_from`, p.`reduction_to`, p.`id_tax`, t.`rate`, 



to:

SELECT p.`reference`, p.`price`, p.`reduction_price`, p.`reduction_percent`, p.`reduction_from`, p.`reduction_to`, p.`id_tax`, t.`rate`, 



to get the reference and then add the following code further down in the function depending on the order you want the discounts to be made:

if ($result['reference'] == '1')
   $price *= 0.2;



This code will take 20% off the price if the reference is '1'. Change 0.2 to whatever percentage discount you want to apply.

Link to comment
Share on other sites

Sorry, but I don't understand what you mean by "static conversion rate". Do you want to disable the currency conversion for products with reference "1"? My code above is discounting the product by 20% when the reference is "1".

Link to comment
Share on other sites

Try changing the contents of the convertPrice function in classes/Product.php to the following:

$currency = $smarty->ps_currency;

if ($reference == '1')
   $currency->conversion_rate = 1;

return Tools::displayPrice($params['price'], $currency);

Link to comment
Share on other sites

This is my convert price function

    static function convertPrice($reference, $currency, $params, &$smarty)
   {
       $currency = $smarty->ps_currency;

       if ($reference == '1')
           $currency->conversion_rate = 1;

       return Tools::displayPrice($params['price'], $currency);
   }


It doesn't work, all my price going to zero.

Link to comment
Share on other sites

Sorry, this is just too difficult to do. The price conversion functions are static functions, so they don't have access to the product reference. It might be possible to do by passing the product reference into the convertPrice function, but it would require much messing around with code. I don't think it is worth the effort.

Link to comment
Share on other sites

Sorry, I don't understand what it is that you want. You can use code like the following to check the ID of the current currency and do something different for each in a PHP file.

if ($smarty->ps_currency->id == 1)
{
  ...
}
elseif ($smarty->ps_currency->id == 2)
{
  ...
}

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