Thanks for the great module! For the most part it works great, except it will sometimes add two zeros to price table when I edit a product. So a price of $45.00 will randomly change to $4500.00. I can go in and edit a product to change the price back to $45.00, but it will not always stick. This is not an issue with checkout or cart, as this happens before a product is even added to a cart. Possibly related to the stock module?

Comments

Bestpoint’s picture

Subscribe! Iv got the same problem.
I also installed the stockmodule..

pompetardo’s picture

I have the same problem, but it multiplies x1000. I think its 10^{# of decimals of the currency}. And happens with the products selected in an order after placing it. Weird shit. I also have the stock module but I don't remember it happened before last update (june 17th).

pompetardo’s picture

Priority: Normal » Major

Aparently this problem is because commerce_price_table_field_presave() which is thought for correcting the value when you save it, is also executed when you place an order. Probably is called when the stock is updated but I'm not sure.

When you place an order "Convert the price amount to an integer based on the currency."* is no longer needed. In fact if you see it doesn't make any sense because "commerce_currency_decimal_to_amount()" converts decimal to amount and the input choosen is an amount so it get multiplied by 10^{# of decimals of the currency}.

So the solution maybe is to put a conditional to avoid it but I don't have a clue how to detect if it has been an order placed. Or somehow avoid calling commerce_price_table_field_presave() when placing an order.

I commented the part of the code that is making the problem but it generates another: if you try to save a product through the gui interface it will save all table prices as 0. But in my case I can live with it because I add and modify all my product programatically so in fact this is not a solution, just a workaround that works for me.

In commerce_price_table.module:

/**
 * Implements hook_field_presave().
 */
function commerce_price_table_field_presave($entity_type, $entity, $field, $instance, $langcode, &$items) {
  // Convert amounts to integers and serialize data arrays before saving.
  foreach ($items as $delta => $item) {
    // Convert the price amount to an integer based on the currency.  (*)   
    $items[$delta]['amount'] = commerce_currency_decimal_to_amount(    //<== Here is the problem
      $items[$delta]['amount'],                                        //     |  (comment
      $items[$delta]['currency_code']                                  //     |   all this to fixit)
    );                                                                 //<== until here 

    // Serialize an existing data array.
    if (isset($item['data']) && is_array($item['data'])) {
      $items[$delta]['data'] = serialize($item['data']);
    }

    if (empty($item['min_qty'])) {
      $items[$delta]['min_qty'] = 0;
    }
    if (empty($item['max_qty'])) {
      $items[$delta]['max_qty'] = 0;
    }
  }
}
pcambra’s picture

Status: Active » Closed (duplicate)

Please use the -dev version #1322714: Odd Pricing Table Issue

I should add a new release, I'll do it asap.

cehfisher’s picture

Thanks for the follow-up. I'll try installing the dev version and report back.