If a shipping or payment method uses the weight calculator and a variant being checked out has variant unit different from weight (items for example) and has the unit value set to zero by the user. The checkout button wont work and will not show an error to the user.
Checkout works and the product is included in the order.
The shipping method cost is calculated in some default way: what does zero unit_value mean? "zero items", "zero kilos", "zero liters" is a bit non-sense. The cost should probably default to zero in these cases.
Final checkout button does nothing. No error is shown.
Setup a shipping method with a weight based calculator.
Create a product with variant_unit items and unit_value 0.
Add to OC
Checkout the product.
Bang.
Change the shipping method to something else.
Change the product unit value to something else.
This was S2 until we discovered what it was. It's now an S3 I think. I got two cases in Katuma where users are setting unit value to zero. And weight based calculators are very common. This will happen again for sure.
Katuma
Bugsnag - https://app.bugsnag.com/katuma/katuma/errors/5de6470bd3c5fe001a1ae122?filters[event.since][0]=30d&filters[error.status][0]=open
this happened again in Portugal. This time the user sent the farmer a screenshot with the new error from #4699
If the variant_unit is set to items there's no way we can calculate weight on them whether the unit_value is 0 or not, right? So we can just skip those variants when doing weight calculations?
That sounds right to me...
I dont think that's correct Matt, if you read the code of the weight calculator you see that if variant_unit is not weight (for example items), the variant.weight field is used instead.
I think this issue is as simple as making weight calculator a bit more resilient by handling this particular data situation without blowing up.
the variant.weight field is used instead
That's probably nil by default though, right?
yeah, but method weight_per_variant is taking care of that with the || 0
in the case:
product.variant_unit = items
variant.weight = not zero
variant.unit_value = nil
I think it makes sense if the weight calculator to use variant.weight * line_item.quantity instead of zero.