I’ve created a plugin for my client that adds a layer of automation for products that need to be reordered. The features of my plugin include using the ATUM API to create Purchase Orders, added items to the POs or Removed items from a PO. My plugin successful performs these takes, however there is a bug that I can’t seems to track down.
The issue, sometimes when adding an item to a PO, the quantity and price are incorrect.
For example, using the following item:
Product: Complete Gasket Set
Purchase Price: $15
In the screenshots, using the API add the item with (qty = 4) to a PO. However in the PO the item cost changes to $60 and the qty = 1. I remove that item from the PO and try again. The second atempt, using the same exact API call I did in the first attempt, qty and subtotal are correct. Removing and readding that item a third time results the cost = $60 and the qty = 1.
1st Attempt: Cost = $60; Qty = 1; Total = $60
2nd Attempt: Cost = $15; Qty = 4; Total = $60
3rd Attempt: Cost = $60; Qty = 1; Total = $60
4th Attempt: Cost = $15; Qty = 4; Total = $60
This pattern continues…..
This is what the line items [line_items] in the PUT looks like going into the PO:
Array
(
[0] => Array
(
[id] => 876
[product_id] => 119138
[variation_id] => 0
[quantity] => 4
[subtotal] => 60.00
[total] => 60.00
)
)
When it’s wrong, this is what the line item looks like after it’s saved.
Array
(
[id] => 905
[name] => Complete Gasket Set
[product_id] => 119138
[variation_id] => 0
[quantity] => 4
[tax_class] =>
[subtotal] => 60.00
[subtotal_tax] => 0.00
[total] => 60.00
[total_tax] => 0.00
[taxes] => Array
(
)
[stock_changed] => no
[meta_data] => Array
(
)
[sku] => AL186967
[global_unique_id] =>
[price] => 60
[image] => Array
(
[id] => 119137
[src] => https://dev.alssnowmobile.com/wp-content/uploads/2024/08/AL186967.jpg
)
[parent_name] =>
)
The only difference between when it is correct and when it’s wrong is the price value. Above the price = 60. It should be 15. In your documentation the price value is READ ONLY, so your plugin manages this internally. Again, the purchase price is set to 15. How and why it changes to 60 in the line item array is the question.
This doesn't happen with all products in all POs. The issue does not seem to be specific to the product. If I add the same product to a different PO, changing the qty will behave normally. So the bug seems to be random.
I checked the database for any weirdness in wp_postmeta, wp_atum_order_items, wp_atum_order_itemmeta and wp_atum_product_data. Nothing seemed to be missing or out of place between products that worked and those that didn't.
I confirmed, the change to the qty in the wp_atum_order_itemmeta table is saved correctly. The bug is it does not display in the PO correctly. Reloading the PO page doesn't to fix the issue.
I have the latest versions of Wordpress, WooCommerce, ATUM Inventory Management for WooCommerce and ATUM Purchase Order Pro.