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 error arises when viewing the checkout page:
Notice: Trying to get property of non-object in uc_line_item_tax_subtotal() (line 246 of uc_taxes.module).
Comment | File | Size | Author |
---|---|---|---|
#12 | ubercart-n1737442-12.patch | 2.71 KB | DamienMcKenna |
#11 | ubercart-n1737442-11.patch | 2.23 KB | DamienMcKenna |
#1 | ubercart-n1737442.patch | 709 bytes | DamienMcKenna |
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 CreditAttribution: 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.