Drupal 7 Commerce: Dynamically calculate line item price based on rules and individual product configuration

We've got some experience on individual product calculators based on Drupal Commerce. Today I'd like to share a bit of that with you: Individual line item price calculation based on rules.

We're for example using these methods in custom calculations for product. I was searching for the API methods to use for a period of time and these are they:

  1. rules_invoke_event('commerce_product_calculate_sell_price', $line_item);
  2.     commerce_line_item_rebase_unit_price($line_item);
  4.     // Line item total = unit price because quantity is always 1 in our case
  5.     $line_item->commerce_total = $line_item->commerce_unit_price;
  7.     $line_item_total_price_array = commerce_line_items_total(array($line_item));
  9. // Format the price
  10. $price_formatted = commerce_currency_format($line_item_total_price_array['amount'], $line_item_total_price_array['currency_code'], $line_item)

Furthermore you will need line item price calculation rules and a bit more stuff to make the magic happen :)


Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.

Weitere Informationen über Formatierungsoptionen