This issue is related to this one #488652: calculate_product_discounts not triggered when adding products from admin area in UC Discount Framework module. It might also be related to #475474: Price alterer contexts and VAT support.
The problem is that when adding an order from the Admin area you can't get a $node from the $context array of the hook_uc_price_handler callback function.
For example when adding an order from the admin area the following code (copy-pasted from UC Discount Framework) will always get to the 3rd if ("// Nothing to do." bit):

/**
 * Implementation of hook_uc_price_handler().
 */
function uc_discount_uc_price_handler() {
  return array(
    'alter' => array(
      'title' => t('Discount price handler'),
      'description' => t('Adds discounts to product prices.'),
      'callback' => 'uc_discount_price_handler_alter',
    ),
  );
}

function uc_discount_price_handler_alter(&$price_info, &$context, &$options) {
  global $user;
  static $prices = array('node_prices' => array(), 'cart_prices' => array());

  if (isset($context['subject']['node']) && (!isset($context['subject']['field']) || $context['subject']['field'] == 'sell_price')) {
    $node = $context['subject']['node'];
    $cache = 'node_prices';
  }
  else if (isset($context['extras']['node']) && isset($context['subject']['cart_item'])) {
    $node = clone $context['extras']['node'];
    $item = $context['subject']['cart_item'];
    if (isset($context['subject']['field']) && isset($item->{$context['subject']['field']})) {
      $node->sell_price = $item->{$context['subject']['field']};
    }
    else {
      $node->sell_price = $item->price;
    }
    $cache = 'cart_prices';
  }
  else {
    // Nothing to do.
    return;
  }
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Island Usurper’s picture

Status: Active » Needs review
FileSize
917 bytes

Items in the cart have their prices changed with uc_price() on the checkout form and when they are displayed on the cart page and block. Similarly, products added by the admin to an order should be changed before they are saved.

jantoine’s picture

Version: 6.x-2.0-rc3 » 6.x-2.x-dev
Status: Needs review » Reviewed & tested by the community

The patch fixes the issue at hand.

Cheers,

Antoine

andreiashu’s picture

Great ! Tested and it seems to do its job.

Thanks !

Island Usurper’s picture

Status: Reviewed & tested by the community » Fixed

Great! Committed.

Status: Fixed » Closed (fixed)

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

andreiashu’s picture

Priority: Normal » Critical
Status: Closed (fixed) » Active

Oki, I found a bug that seems to be having its roots into this patch :/
To replicate:
1. go admin area to edit/create an order
2. Add product -> Select your product -> Set qty to 2
3. Add to order
4. You'll see that in fact the price of the product is Qty * Product's price, when it should in fact be Product's price

andreiashu’s picture

I think the problem is with

$price_info = array(
  'price' => $product->price,
  'qty' => $product->qty,
);

because that says that the base price of our product is qty * price which is wrong. So doing this

$price_info = array(
  'price' => $product->price,
  'qty' => 1,
);

seems to solve the problem. Any opinions ?

Island Usurper’s picture

Status: Active » Needs review
FileSize
387 bytes

How about a patch to tell us which part to change? I think I found it and it looks like it works.

andreiashu’s picture

Oh, yes :) That is the part.
Anyone else to test and confirm that it works ?

andreiashu’s picture

Status: Needs review » Reviewed & tested by the community

I think we can RTBC this ?
I've been using your last patch and it seems to work as expected.

Island Usurper’s picture

Status: Reviewed & tested by the community » Fixed

Sounds good to me. Committed.

Status: Fixed » Closed (fixed)

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