Hi,
I'm trying to achieve a rather simple task?

I have this:
- if total order price is below $100 then add $10 to total price.
- I do not use shipment module.
- I do not use payment module.

How can I do this using Rules? Or do I have to code it by my self?

Comments

amfis’s picture

Found this: #1307108: Add a fixed Price Component which is similar.. so I guess for now I can't do this?

Or can I hook into cart display and alter the data there? I need a simple and quick solution for this.

rszrama’s picture

Status: Active » Closed (duplicate)

You'll have to have some sort of custom line item type that you use to add the $10 fee to the order. See the write-up about ioby.org for more information:

http://www.newsignature.com/blog/2011/05/06/drupal-7-commerce-in-action-...

amfis’s picture

Okay... found solution in case anyone is also interested in this.

I've installed commerce_shipping 7x-2.x-dev module and edited commerce_shipping_example module to fit my needs:

/**
 * Shipping service callback: returns a base price array for a shipping service
 * calculated for the given order.
 */
function commerce_shipping_example_service_rate($shipping_service, $order) {
  
  if ($order->commerce_order_total['und'][0]['amount'] <= 10000) {
    return array(
      'amount' => 1040,
      'currency_code' => 'LTL',
      'data' => array(),
    );
  } else {
    return array(
      'amount' => 0000,
      'currency_code' => 'LTL',
      'data' => array(),
    );
  }
}

/**
 * Shipping service callback: returns the example shipping service details form.
 */
function commerce_shipping_example_service_details_form($pane_form, $pane_values, $checkout_pane, $order, $shipping_service) {
  $form = array();
  
  if ($order->commerce_order_total['und'][0]['amount'] <= 10000) {
    $amount_now = 10000 - $order->commerce_order_total['und'][0]['amount'];
    
    $currency_code = $order->commerce_order_total['und'][0]['currency_code'];
    $amount = number_format(commerce_currency_amount_to_decimal($amount_now), 2);
    
    
    $form['extra_pay'] = array(
      '#type' => 'item',
      '#markup' => 'You need additional ' . $amount . ' ' . $currency_code .' until you can get free delivery.',
    );    
  }

  return $form;
}
amfis’s picture

Category: support » feature
Status: Closed (duplicate) » Needs review

I think it wouldn't be too difficult to implement such action into Commerce module it self.

It would look like a few rules:
- commerce cart: on cart update
- condition: if cart total is less than X
- action: add shipping component with a price of Z

rszrama’s picture

Status: Needs review » Closed (duplicate)

Remember, the philosophy of Drupal Commerce is to provide a framework where you can build those sorts of things yourself without trying to include every possible feature in core. That's one of the reasons Commerce Shipping didn't even make it into core for 1.x. I don't think we'll be adding any sort of Rules like that to the core, but what's great is that it's fairly trivial to configure yourself if you need it on a site.

One thing you might consider is saving these configurations in Features modules for you to reuse on future sites. You'll basically build a library of configurations that make your job easier on subsequent Drupal Commerce site builds.

amfis’s picture

Thanks Ryan.

candelas’s picture

thanks a lot @amfis for putting the example.
i was very confused about the module way and rules and with your example, i was able to understand!
i had to change this line of your code

$amount = number_format(commerce_currency_amount_to_decimal($amount_now), 2);

for this because i was getting an error, because the currency was not given

$amount = number_format(commerce_currency_amount_to_decimal($amount_now,$currency_code), 2);

thanks a lot :)