Inventory item unit cost for a line item with missing (deleted) product variant

DanielMR
Visitor
2 0 0

I'm trying to fetch the needed information from the Shopify API to calculate historical gross profit per order / line item, and I think I'm missing a piece of the puzzle to get what I need. There are two edge cases where fetching the unit cost from the line item is tricky:

  1. When the product variant inventory item unit cost is edited after the order was placed.
  2. When the product variant (or the whole product) is deleted after the order was placed.

I can't see any field in the line item object where the unit price is provided, which would solve my whole issue. I've noticed tho, in the "Profit by product variant SKU" report in the analytics area, this information seems to be shown correctly. The report's gross profit is correct even if I edit the inventory item unit price, as well as if the product variant is deleted entirely, so the data at the order placement time is available in the reporting system. I can see how Product ID and Variant ID are available in the report too, even if those resources are deleted.

Question, is there a way I could fetch unit cost — and why not also the Variant ID — of line items belonging to product variants that has been deleted?

Replies 4 (4)

CloudlabSam
Shopify Partner
539 43 88

Unfortunately, you cannot. The information has to be stored at the time of the sale. If you are interested, you can read more here.

DanielMR
Visitor
2 0 0

Thanks for the answer. Interesting, in my tests I notice a different behaviour. If I edit the product variant cost per item and I look at the Profit by Product Variant SKU report, the gross profit stays the same. That makes me think the cost per item is frozen in time and Shopify persists it somewhere. Or perhaps the report doesn't reflect the change instantly and it takes a while…

CloudlabSam
Shopify Partner
539 43 88

Interesting. Even if it is stored with the analytics data, that isn't accessible via the API.

BeProfit_App
Shopify Partner
75 1 4

Hi @DanielMR - indeed, it's not possible to pull costs for deleted variants. But the BeProfit Profit Tracker app does help you out by automatically identifying those cases and prompting you to manually define their costs.

While it's not the exact solution you were looking for, BeProfit will absolutely save you time and frustration by doing the 'heavy lifting' for you.

Check it out, let me know if you have any questions - I'm happy to help out. Good luck!