diff -r 89cb89a1e805 -r ba9aa74de595 commerce_price_table.module --- a/commerce_price_table.module Sat Jan 19 20:24:04 2013 +0100 +++ b/commerce_price_table.module Sat Jan 19 20:41:19 2013 +0100 @@ -457,18 +457,7 @@ /** * Get the price for the min qty possible in a product. */ -function commerce_price_table_get_amount_qty($product, $quantity = 1) { - $items = array(); - $product_wrapper = entity_metadata_wrapper('commerce_product', $product); - $fields = commerce_info_fields('commerce_price_table', 'commerce_product'); - foreach ($fields as $field) { - if (!empty($product->{$field['field_name']})) { - foreach ($product_wrapper->{$field['field_name']}->value() as $item) { - $items[] = $item; - } - } - } - +function commerce_price_table_get_amount_qty($product, $quantity = 1, $items = array()) { // Sort the items by quantity and return the matching one. $result = false; uasort($items, 'commerce_price_table_sort_by_qty'); diff -r 89cb89a1e805 -r ba9aa74de595 commerce_price_table.rules.inc --- a/commerce_price_table.rules.inc Sat Jan 19 20:24:04 2013 +0100 +++ b/commerce_price_table.rules.inc Sat Jan 19 20:41:19 2013 +0100 @@ -17,6 +17,10 @@ 'label' => t('Quantity'), 'type' => 'decimal', ), + 'price_table' => array( + 'label' => t('Price table'), + 'type' => 'list', + ), ), 'group' => t('Commerce price table'), ); @@ -24,13 +28,13 @@ return $actions; } -function commerce_price_table_set_price($line_item, $quantity) { +function commerce_price_table_set_price($line_item, $quantity, $price_table) { // If the line item contains a product, we set the price according to the // quantity. if (commerce_line_items_quantity(array($line_item), commerce_product_line_item_types())) { $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item); $product = commerce_product_load($line_item_wrapper->commerce_product->product_id->value()); - $item = commerce_price_table_get_amount_qty($product, $quantity); + $item = commerce_price_table_get_amount_qty($product, $quantity, $price_table); if (!empty($item)) { // Empty the price components to recalculate them. $line_item->commerce_unit_price[LANGUAGE_NONE][0]['data']['components'] = array(); diff -r 89cb89a1e805 -r ba9aa74de595 commerce_price_table.rules_defaults.inc --- a/commerce_price_table.rules_defaults.inc Sat Jan 19 20:24:04 2013 +0100 +++ b/commerce_price_table.rules_defaults.inc Sat Jan 19 20:41:19 2013 +0100 @@ -20,9 +20,18 @@ $rule ->event('commerce_product_calculate_sell_price') + ->condition('entity_has_field', array( + 'entity:select' => 'commerce-line-item', + 'field' => 'commerce_product', + )) + ->condition('entity_has_field', array( + 'entity:select' => 'commerce-line-item:commerce-product', + 'field' => 'field_price_table', + )) ->action('commerce_price_table_set_price', array( 'commerce_line_item:select' => 'commerce-line-item', 'quantity:select' => 'commerce-line-item:quantity', + 'price_table:select' => 'commerce-line-item:commerce-product:field-price-table', )); $rule->weight = -10;