makkon
makkon

Reputation: 21

Drupal commerce Sql select max price for current taxonomy

Hello (sorry for broken english). I try to select min and max prices (drupal commerce) for current catalog tag. ATM i put in header php code:

$max = db_query("SELECT MAX(`commerce_price_amount`) FROM {`field_data_commerce_price`}")->fetchField(); 

so I can get max price for all products. same for min. but i need for current tag. my sql tables looks like this:

table field_data_field_product_catalog: http://postimage.org/image/tahrk3y29/

table field_data_commerce_price: http://postimage.org/image/w1yvkh8kn/

some advice plz?

Upvotes: 1

Views: 425

Answers (1)

makkon
makkon

Reputation: 21

$catalog=arg(2);   
$max = db_query("SELECT MAX(`commerce_price_amount`) FROM {`field_data_field_product_catalog`},{`field_data_commerce_price`} 
WHERE {field_data_commerce_price.entity_id}={field_data_field_product_catalog.entity_id} 
AND {field_product_catalog_tid}=:cnid", array(':cnid' => $catalog))->fetchField();
$max=Ceil($max/100);

Upvotes: 1

Related Questions