I am using Ubercart with the Multiprice module (http://drupal.org/project/uc_multiprice) to offer different prices (and currencies) for our products in different countries. I faced the issue of how to offer discounts of different amounts (and currencies) in these countries. I found a relatively easy way to do this with the UC Discount Framework, so I thought I would document this here.

Our discounts are based on combinations of products: If you order a product from set A and a product from set B together, you get a line item discount on the order. I can define that discount with a set of Check Products conditions - but I want to do this for several countries, with different discount amounts in each country. Other types of discounts (based on quantity, order total, user role, etc.) would face the same problem, if you wanted different discounts for each country.

Multiprice allows you to define different product prices for different countries. It can either let the user select the country via a dropdown list, or determine the country automatically from the IP address; it stores the selection in a session variable. To implement different discounts for each country, I just added one more condition "Check current country" to uc_discount.ca that verifies, at the time the checkout pane is reached, that the session's country ID is a specific numeric value, like 840 for the US, and 826 for the UK:

function uc_discount_ca_condition() {
   ...
  $conditions['uc_discount_condition_country_id'] = array(
    '#title' => t('Check the current country'),
    '#description' => t('Current country from IP address or user selection.'),
    '#category' => t('Order'),
    '#callback' => 'uc_discount_condition_country_id',
    '#arguments' => array(
      'order' => array('#entity' => 'uc_order', '#title' => t('Order')),
    ),
  );
  return $conditions;
}

function uc_discount_condition_country_id_form($form_state, $settings = array()) {
  $form = array();
  $form['country_id'] = array(
    '#type' => 'textfield',
   '#title' => t('Country id'),
    '#default_value' => $_SESSION['country_id'],
    '#description' => t('Country id for which this discount should apply.'),
  );
  return $form;
}

function uc_discount_condition_country_id($order, $settings) {
    return $settings['country_id'] == $_SESSION['country_id'];
}

This uses the country_id $_SESSION variable set by Multiprice. With this, I just had to define one predicate for the US, consisting of my conditions for allowing the discount AND Country ID = 840, and another predicate for the UK, consisting of the same conditions for allowing the discount AND Country ID = 826, and so on. I specified a fixed amount for the discount, and this amount appeared with the right currency symbol in the checkout and order summaries, thanks to UC and Multiprice.

I hope someone else will find this useful. I am actually using a very nice enhancement to the Multiprice module by Bartezz, described at http://drupal.org/node/960884, that adds role-based product prices to Multiprice, in a way that interacts well with its country-based product prices.

Comments

dfylstra’s picture

In the above code example, the line '#default_value' => $_SESSION['country_id'], should be '#default_value' => $settings['country_id'], or else you will always see the current country code, rather than the country code that you saved as part of the condition, when you view the form again.

avpaderno’s picture

Status: Active » Closed (outdated)

I am closing this issue as it's for a Drupal version that isn't supported.