Currently UC Discounts Framework doesn't work if you try to add products from admin area (ex: 'admin/store/orders/97/edit') - they don't get the discounts applied. The same products if added to Cart as a normal buyer get discounted.
Is there currently a workaround for this ?

Comments

andreiashu’s picture

Priority: Normal » Critical

It seems that in uc_discount_price_handler_alter function the two if s don't validate so the calculate_product_discounts trigger doesn't get pulled.

I'm bumping the priority because this issue renders this module useless on sites that take orders through phone for example...
I still have no idea for now how to solve this.

andreiashu’s picture

I managed to make a workaround for this by implementing a hook_cart_item and pulling the required trigger from here:

/**
 * hook_cart_item
 */
function uc_discount_cart_item($op, &$item) {
  switch ($op) {
    case 'load':
      global $user;
      
      ca_pull_trigger('calculate_product_discounts', $item, $user);
      
      break;
  }
}

Is there another simpler solution for this ?
@Islander: do you have some opinions about this ?

Thanks !

andreiashu’s picture

Title: Adding discounted products from admin area » calculate_product_discounts not triggered when adding products from admin area
Status: Active » Needs review

Changing status and title

jantoine’s picture

andreiashu,

I tried implementing the hook_cart_item() hook as you suggested but I was unable to get this to resolve the issue. I am still unable to get products to reflect discounts when added via the admin area. Was there something else you did to get the hook to fire? It doesn't seem to be firing on my system. I am using Ubercart 6.x-2.x-rc3, the latest development release of uc_discounts and products with attributes (not sure that the last one matters).

Cheers,

Antoine

jantoine’s picture

Status: Needs review » Needs work

Changing Status

andreiashu’s picture

@AntoineSolutions: thanks for testing it out. Indeed it does work only in certain cases... I also use attributes (and I need my discounts to take into consideration the value of the selected attributes).
I will investigate more on this one. I post back some feedback hopefully this next week.

Cheers,
Andrei

andreiashu’s picture

I've been thinking more about this and I think this should be reported as a bug in UC. Why is the $context array different in the admin area from the normal client area ?
I managed to make a workaround for this but it is really nasty: caching discounts for the order in {cache} table until the order is finished and I'm not even sure if it will work in all situations...

andreiashu’s picture

I still think that instead of finding a workaround for this we should fix the core problem that relies in UC.

I opened an issue for UC here: #492090: Admin area has different $context array for hook_uc_price_handler than "client" area.

Island Usurper’s picture

Status: Needs work » Closed (duplicate)

I was going to switch this issue over to the Ubercart queue, but you beat me to it. I guess that's what I get for going to lunch. ;)

I'll just close this one out and deal with the other issue.