0

What is the best approach to go through all products PRICES (price, final price, promo price, group price ...) and round them to 2 decimal places. for example:

28,1200 -> 28,1200
28,1255 -> 28,1300
28,1261 -> 28,1300
0
\ceil( round($value,2));

This will round up, meaning 1.555 is rounded up to 1.65 !

Let me know if you need any further assistance and don't forget to up vote and mark as answer if this solved your problem :)

1
  • I need to round product prices in the database
    – Anass Hl
    Jul 15 '20 at 18:55
0

I've got an extension that will get you 95% there

https://github.com/DominicWatts/ClearAttribute/

This wipes values for supplied attribute code

https://github.com/DominicWatts/ClearAttribute/blob/master/Console/Command/NullAttribute.php#L176

Instead of nulling value you want the mysql round function. So it should look something like this

['value' => new \Zend_Db_Expr('round(value, 2)')],

The extension will work out what table and attribute ID value to update.

Obviously try on dev db first as of this goes wrong you could wipe your prices

0
UPDATE catalog_product_entity_decimal val
  SET  val.value = ROUND(val.value,2)
  WHERE  val.attribute_id = (
     SELECT attribute_id FROM eav_attribute eav
     WHERE eav.entity_type_id = 4 
       AND eav.attribute_code = 'price'
    );

and dont forget to reindex product prices from admin :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.