Upgrade Your Drupal Skills
We trained 1,000+ Drupal Developers over the last decade.
See Advanced Courses NAH, I know EnoughCreating an action to update the prices of your commerce products
Parent Feed:
/** * Implements hook_action_info(). */ function mymodule_action_info() { return array( 'mymodule_update_products' => array( 'type' => 'entity', 'label' => t('Update products by 2%'), 'configurable' => FALSE, 'triggers' => array('any'), 'pass rows' => TRUE, ), ); } function mymodule_update_products(&$entity, $context) { $product_id = $entity->product_id; //dsm($product_id); $price = $entity->commerce_price[LANGUAGE_NONE][0]['amount']; //dsm($price); $updated_price = 1.02 * $price; $affected_rows = db_update('field_data_commerce_price') ->fields(array('commerce_price_amount' => $updated_price)) ->condition('entity_id', $product_id) ->execute(); //dsm($affected_rows); } function mymodule_round_up_line_item_price($line_item_id) { $line_item = commerce_line_item_load($line_item_id); return round($line_item->commerce_unit_price[LANGUAGE_NONE][0]['amount'],-2); }
About Drupal Sun
Drupal Sun is an Evolving Web project. It allows you to:
- Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
- Facet based on tags, author, or feed
- Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
- View the entire article text inline, or in the context of the site where it was created
See the blog post at Evolving Web