Access a community of over 900,000 Shopify Merchants and Partners and engage in meaningful conversations with your peers.
Is there any way to fetch the inventory quantity of cart line items on the script editor. I have tried to use item.variant.inventory_quantity but it says undefined method "inventory_quantity".
Hi @anish_soni,
There is a "quantity" method directly on the line_item object. So you would call line_item.quantity
Here is a simple script that will output the variant id and quantity of each line item in the cart:
cart = Input.cart
cart.line_items.each do |line_item|
puts "#{line_item.variant.id}: #{line_item.quantity}"
end
Output.cart = cart
I hope that is helpful!
Matthew
Thanks for your reply but I want to fetch the stock of line item not line item quantity.
Ah, misread that.
It doesn't seem to be included in the variant object.
You might try passing as a line_item property, but it wouldn't necessarily be up-to-date. I imagine it would be the stock quantity of the variant the moment it was added to the cart. So that might not work for your scenario.
User | RANK |
---|---|
3 | |
2 | |
2 | |
1 | |
1 |