Hello pcambra,

I just installed Coupon + Coupon_pct on a kickstart to test it. I'm not sure this is the intented behavior, but when i create a 20% discount coupon, and use it on an order, the "Coupon Granted Amount" column remains empty.

I'd like to know if this is the intended behavior (as it's "normal" that it's empty, as the discount amount is variable), or it should be calculated ?

So basically, the "Coupon granted amount" column should be filled with:
1/ Nothing, because the amount is variable
2/ Display the discount rate of the coupon (say 20%)
3/ The calculated amount based on the order and the coupon discount rate

What do you think ?

Pascal

Comments

liupascal’s picture

Forgot to attach a screenshot

pcambra’s picture

Yes, this is a known problem, working on it

liupascal’s picture

Ok thanks - Then what will be the behavior of it ?

pcambra’s picture

As I see it, it should insert a given amount on redeem and then update it with line item or order refresh hooks, that's my intented approach for this.

nicola.peluchetti’s picture

I'm giving a look at this, what hooks are responsible for the behaviour?If i fix this i submit a patch

muschpusch’s picture

As I see it, it should insert a given amount on redeem and then update it with line item or order refresh hooks

@pcambra: sorry i don't really get your answer. I think this rules action in commerce_coupon.rules.inc is where the magic happens (or not). The problem is that afaik the percentage coupon alters the product line items in a loop so there is no way (i know) who to pass the reductions into a variable and save them to the log.

  $actions['commerce_coupon_action_set_granted_amount'] = array(
    'label' => t('Set granted coupon amount'),
    'parameter' => array(
      'commerce_coupon_log' => array(
        'type' => 'commerce_coupon_log',
        'label' => t('Commerce Coupon Log'),
      ),
      'amount' => array(
        'type' => 'decimal',
        'label' => t('Granted Amount'),
      ),
      'currency_code' => array(
        'type' => 'text',
        'label' => t('Currency Code'),
      ),
    ),
    'group' => t('Commerce Coupon'),
    'base' => 'commerce_coupon_action_is_invalid_coupon',
    'callbacks' => array(
      'execute' => 'commerce_coupon_action_set_granted_amount',
    ),
  );

[...]

function commerce_coupon_action_set_granted_amount($commerce_coupon_log, $amount, $currency_code) {
  if (!($commerce_coupon_log instanceof EntityMetadataWrapper)) {
    $commerce_coupon_log = entity_metadata_wrapper('commerce_coupon_log', $commerce_coupon_log);
  }

  $coupon = $commerce_coupon_log->coupon;

  // Get the price component to use in this price.
  $price_component_name = 'commerce_coupon_' . $coupon->type;
  drupal_alter('commerce_coupon_price_component_name', $price_component_name, $coupon);

  // Set the unit price on the line item object.
  $commerce_coupon_log->commerce_granted_amount->amount = $amount;
  $commerce_coupon_log->commerce_granted_amount->currency_code = $currency_code;


  // Add the base price to the components array.
  if (!commerce_price_component_load($commerce_coupon_log->commerce_granted_amount->value(), $price_component_name)) {
    $commerce_coupon_log->commerce_granted_amount->data = commerce_price_component_add(
      $commerce_coupon_log->commerce_granted_amount->value(),
      $price_component_name,
      $commerce_coupon_log->commerce_granted_amount->value(),
      TRUE,
      FALSE
    );
  }

  commerce_coupon_log_save($commerce_coupon_log->value());


}


pcambra’s picture

Status: Active » Fixed

Marking this as fixed as the coupon log reflects the correct amount now.

nicola.peluchetti’s picture

@pcambra is there a new version?
With the old version it's still not working

pcambra’s picture

It's committed to -dev, so you either grab it from git directly or wait until the -dev version gets populated (the process runs each 12h)

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.