| Project: | Ubercart Fee |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
The Ubercart Fee module works great when the cart contains a single product to which a fee is applied or not.
But when I add more products, it starts to behave abnormally (at least in my point of view). Unless I'm using it for something it was never intended for? If so, let me know and please let me know if there are other/better alternatives for my use case (see below for details).
To make things clear, here is my use case.
I have a baseball cap product class. I created a Drupal baseball cap which has a color attribute and 4 options: Red, White, Blue and Black. I want to apply a 5$ fee only to the Red and Blue caps - color is more expensive! :-)
I created a "Fee for Red & Blue caps" fee. The Conditions for this fee are as follows:
[Condition groups:
[Condition group: is baseballcap AND is Red]
OR
[Condition group: is baseballcap AND Blue]
]
- First condition in group: Check an order's products
- Second condition in group: Order has a product with a particular attribute option
My tests & their results:
1. when cart contains 1 Red cap, a $5 fee is added as expected.
2. when cart contains 1 Red cap & 1 Blue cap, a $10 fee is added as expected.
3. but when cart contains 1 Red, 1 Blue and 1 White cap, a $15 fee is added. I was not expecting that.
In test number 3, the total fee should be $10 not $15.
My reasoning. I thought that the total fee was calculated as the sum of fees applied to each product in the cart, recursively. Inother words that the UC_fee module would (A) look and a see a Red cap, evaluate conditions and apply a $5 fee, (B) look and a see a Blue cap, evaluate conditions and apply a $5 fee, (C) look and a see a White cap, evaluate conditions and apply no fee. Total fee: $5 + $5 = $10.
Note: I'm not a programmer - In uc_fee.module, on line 498, the function uc_fee_calculate_fees() loops for each fees. Right? If so, should it not also loop for each product in the cart? Other wise the "Fee for Red & Blue caps" fee is applied to the white cap because their is a Red cap in the cart. Doesn't make sense to me.
Can anybody help me with this one?
| Attachment | Size |
|---|---|
| Fee for Red & Blue caps.png | 237.22 KB |
Comments
#1
Hi,
Did you figure it out in the end please? I'm trying to understand myself how Ubercart works for the selling price.
Thanks
#2
Unfortunately, I got no replies to my issue and I don't currently have the knowhow to check/modify the code. :-(
#3
Hello bisonbleu,
I'm more or less in the same case. I think that customizing Ubercart can get complicated when we're not programmers! Even with all the modules available...
#4
It sounds like you should use the price modifiers in the Options themselves, rather than the uc_fee module for what you're doing.
When you add an option to a product (ie: Red, Blue, White) you can define a price that is added when that option is selected by the user.
#5
mstenta: that would make the product display price more expensive, we're not talking about the product price itself, but the fee that's added on the checkout screen.
if i sell a product that needs $5 per option fee included, that's not the price, its a fee. I know, its all money, but to the people I'm working with its a big deal. they feel like their sales will be increased if the "fee" is shown later, in the checkout process.
i'm also having the same problem when i'm applying a fee by SKU, it adds the fee to all products in the cart.
#6
is this a duplicate of: http://drupal.org/node/977404
also, is there anyone out there willing to fix this?
seems like in uc_fee.module the code that does this is
**
* Calculates the fees for an order based on enabled fee modules.
*
* @param $order
* The full order object for the order want to calculate fees for.
* @return
* An array of fees for the order.
*/
function uc_fee_calculate($order) {
// Find any fees specified by enabled modules.
$fees = module_invoke_all('calculate_fees', $order);
return $fees;
}
/**
* Calculate the amount and types of fees that apply to an order.
*/
function uc_fee_calculate_fees($order) {
global $user;
if (is_numeric($order)) {
$order = uc_order_load($order);
$account = user_load(array('uid' => $order->uid));
}
elseif ((int)$order->uid) {
$account = user_load(array('uid' => intval($order->uid)));
}
else {
$account = $user;
}
if (!is_object($order)) {
return array();
}
if (is_array($order->line_items)) {
foreach ($order->line_items as $i => $line) {
if (substr($line['type'], 0, 4) == 'fee_') {
unset($order->line_items[$i]);
}
}
}
$apply_fees = array();
$applied_exclusive = FALSE;
$fees = uc_fee_get_fees();
$order->fees = array();
$arguments = array(
'order' => array(
'#entity' => 'uc_order',
'#title' => t('Order'),
'#data' => $order,
),
'fee' => array(
'#entity' => 'fee',
'#title' => t('Fee'),
// #data => each $fee in the following foreach() loop;
),
'account' => array(
'#entity' => 'user',
'#title' => t('User'),
'#data' => $account,
),
);
foreach ($fees as $fee) {
// skip fees which may not be applied with other fees
if ($fee->is_exclusive && !empty($apply_fees)) {
continue;
}
$arguments['fee']['#data'] = $fee;
$predicates = ca_load_trigger_predicates('calculate_fees');
if (ca_evaluate_conditions($predicates['uc_fee_'. $fee->fid], $arguments)) {
$line_item = uc_fee_action_apply_fee($order, $fee);
if ($line_item) {
$order->fees[$line_item->id] = $line_item;
// keep a record of which fees we have applied
$apply_fees[$fee->fid] = array(
'description' => check_plain($fee->description),
'amount' => $line_item->amount,
);
// we have just applied an exclusive fee, or one which requests that we stop processing
if ($fee->is_exclusive || $fee->do_end_processing) {
break;
}
}
}
}
return $order->fees;
}
#7
I just added the fee to the product attribute ( This size: (Includes $x.xx fee) : $price ) . Not ideal, but I received no response from anyone here, the module creator, anyone on #drupal or #drupal-ubercart, even with interest in paying someone to fix it.
#8
subscribing
#9
Hi Slavojzizek,
I am interested in fixing that. But currently busy with some already delayed project.
Subscribed to the post, will get back soon.
Best of luck.
#10
Please let me know when you're considering fixing this, its a huge thing for us. :)
#11
Has anyone had any luck with finding a work around for this bug. I have several products that have different fees based on the number of products set in a conditional which are applied to specific SKUs. Adding other items in the cart (not included in that SKU order total conditional) Multiplies the fee using the total number of products in the cart. .
Subscribing.
#12
Ignore the scary help text on the fee editing page for the active checkbox.
If you uncheck the 'active' checkbox and the fee willl only apply to items that have the fee selected on their edit form (rather than apply the fee to every item in the cart if one of these items is present).
There is still a bug here somewhere after spending a day debugging this what I just said makes no sense to me, but if it works, it works....
I also applied the patch from #1250916: Max Applications does not count properly. which might also be necessary for this to work, but I haven't confirmed.
#13
Here is a patch that just adds my comments I made while working on this, might lead someone else to the real solution...
#14
#15
I have found that marking the fee as not active and removing
if (ca_evaluate_conditions($predicates['uc_fee_'. $fee->fid], $arguments)) {and the closing bracket means the multiple fees are applied correctly. Now just need to work out why this is to fix it.