Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
Comment | File | Size | Author |
---|---|---|---|
#8 | add_product_qty.patch | 387 bytes | Island Usurper |
#1 | ordered_products_price.patch | 917 bytes | Island Usurper |
Comments
Comment #1
Island Usurper CreditAttribution: Island Usurper commentedItems 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.
Comment #2
jantoine CreditAttribution: jantoine commentedThe patch fixes the issue at hand.
Cheers,
Antoine
Comment #3
andreiashu CreditAttribution: andreiashu commentedGreat ! Tested and it seems to do its job.
Thanks !
Comment #4
Island Usurper CreditAttribution: Island Usurper commentedGreat! Committed.
Comment #6
andreiashu CreditAttribution: andreiashu commentedOki, 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
Comment #7
andreiashu CreditAttribution: andreiashu commentedI think the problem is with
because that says that the base price of our product is qty * price which is wrong. So doing this
seems to solve the problem. Any opinions ?
Comment #8
Island Usurper CreditAttribution: Island Usurper commentedHow about a patch to tell us which part to change? I think I found it and it looks like it works.
Comment #9
andreiashu CreditAttribution: andreiashu commentedOh, yes :) That is the part.
Anyone else to test and confirm that it works ?
Comment #10
andreiashu CreditAttribution: andreiashu commentedI think we can RTBC this ?
I've been using your last patch and it seems to work as expected.
Comment #11
Island Usurper CreditAttribution: Island Usurper commentedSounds good to me. Committed.