Needs review
Project:
Ubercart
Version:
6.x-2.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
18 Aug 2012 at 04:43 UTC
Updated:
29 Dec 2012 at 23:29 UTC
Jump to comment: Most recent file
Comments
Comment #1
damienmckennaThis resolves the problem by first checking if the object property exists, and fixes a similar problem in line 253.
Comment #2
tr commentedHow can you have an order with no products?
This to me seems like a classic case of covering up the symptoms rather than finding the cause. $order->products should *always* have something in it on the checkout page. If it doesn't, there's a more fundamental problem - perhaps with some contributed module. Those same conditionals are in Ubercart 7.x-3.x, but I've never seen this PHP notice in either version, nor has it been reported previously in the issue queue.
Comment #3
damienmckennaI cannot deny that there may be a problem elsewhere, I'll dig into it further and see what I can find.
Comment #4
damienmckennaDigging into it a little, I've found that when uc_line_item_tax_subtotal() is executed with $op='load' that the $order has turned into a StdClass instead of a UcOrder.
Comment #5
damienmckennaAh. When $op == 'cart-preview' it seems to be passed the $order->products array rather than the $order object itself.
Comment #6
damienmckennaWhen the checkout page loads it executes _line_item_list() and then searches the line items for any elements with a callback. With my site's current setup there are five callbacks: uc_line_item_subtotal, uc_line_item_generic, uc_line_item_tax_subtotal, uc_line_item_tax and uc_line_item_total; of these, the uc_line_item_generic function doesn't exist. This array is ran through the following:
This is what uc_line_item_total() looks like:
For comparison, here's uc_line_item_tax():
Here's the function prototype for uc_line_item_tax_subtotal():
You'll notice that uc_line_item_total() calls the second argument $arg1, whereas uc_line_item_tax() and uc_line_item_tax_subtotal() call it $order. I think this is the key problem, the second argument should be called $arg1 and handled differently depending on $op because clearly the value passed to it is different based on $op.
Comment #7
damienmckennaReading into it further, I think this may be a symptom of the problem identified in #1281346: tax_subtotal line item no longer alterable -- breaks compatibility with uc_coupon.
Comment #8
damienmckennaUpdating the title.
Comment #9
damienmckennaRelated: #1740944: Use error_level=2 for all local development
Comment #10
damienmckennaI reviewed the code in 7.x-3.x and it seems the API is quite different than in 6.x-2.x, so I'm dragging this back to the world of "a legacy D6 problem".
Just to reiterate the core problem - Ubercart's API was changed but uc_line_item_tax() and uc_line_item_tax_subtotal() were not properly updated to match.
Comment #11
damienmckennaFood for thought.
Comment #12
damienmckennaAn alternative patch that bundles all of the logic into the switch() statement - I'm not familiar enough with the codebase to know which is the correct path.
Comment #13
longwaveIn the current code, the cart-preview case is not used as $different is always FALSE, and therefore seems like it can be safely removed, which would simplify this even further.
#644840: subtotal excluding tax line item logic is wrong is also related to this function.