Shopify Order Status using Admin API - api

I need to get status of order using Shopify API. I know the payload and I am able to get the order response but wanted to know the logic to get the status line of the order if some have that handy.
Like I get fulfillment status, payment status, confirmed status, processing_method, cancelled_at so using all these and other attributes, I want to frame a line which will give the end user the complete status.
Like e.g., "your order is confirmed and is ready to ship, it will reach to you by next week. Thanks"
any help?

The example message that you shared will be a result of several Shopify API resources combined. To iterate step by setp, you will need to use the following 3 API resources.
Order
Fulfillment
Fulfillment Event
First from the Order resource, have look at fulfillment_status field. Valid values are
shipped: Show orders that have been shipped.
partial: Show partially shipped orders.
unshipped: Show orders that have not yet been shipped
From the Fulfillment resource, have look at status and shipment_status fields.
From the FulfillmentEvent resource, have look at estimated_delivery_at and status field.
Combined these fields together, you have the information if any of the items are fulfilled, shipment status and estimated delivery date.
You can have a look at code inside Shopify Email templates that are sent on Shipping Confirmation etc.
Sample Code from Shipping Confirmation Email
{% if fulfillment.item_count == item_count %}
{% capture email_title %}Your order is on the way{% endcapture %}
{% capture email_body %}Your order is on the way. Track your shipment to see the delivery status.{% endcapture %}
{% elsif fulfillment.item_count > 1 %}
{% if fulfillment_status == 'fulfilled' %}
{% capture email_title %}The last items in your order are on the way{% endcapture %}
{% capture email_body %}The last items in your order are on the way. Track your shipment to see the delivery status.{% endcapture %}
{% else %}
{% capture email_title %}Some items in your order are on the way{% endcapture %}
{% capture email_body %}Some items in your order are on the way. Track your shipment to see the delivery status.{% endcapture %}
{% endif %}
{% else %}
{% if fulfillment_status == 'fulfilled' %}
{% capture email_title %}The last item in your order is on the way{% endcapture %}
{% capture email_body %}The last item in your order is on the way. Track your shipment to see the delivery status.{% endcapture %}
{% else %}
{% capture email_title %}One item in your order is on the way{% endcapture %}
{% capture email_body %}One item in your order is on the way. Track your shipment to see the delivery status.{% endcapture %}
{% endif %}
{% endif %}
{% capture email_emphasis %}Estimated delivery date: <strong>{{fulfillment.estimated_delivery_at | date: "%B %-d, %Y"}}</strong>{% endcapture %}

Related

Is there an alternate way to display line item prices on a Shopify packing slip?

By default, Shopify's packing slip uses
{% if item.sku == line_item.sku %}
{% assign final_price = line_item.final_price %}
{% endif %}
{% if final_price %}
{{ final_price | money }}
{% endif %}
to display a line item's price on a packing slip. I have a client who needs to use the same sku for multiple products, and this has resulted in the wrong line item prices being displayed on some packing slips. Does anyone know of a way to display the line-item price without referencing an item's sku? I have already tried using product and variant id, title, etc. Variant barcode looks like it may work, but this client does not have barcodes for their products.
These are the liquid objects available to you.
https://help.shopify.com/en/manual/shipping/setting-up-and-managing-your-shipping/packing-slips-variable-list
From that list I'm not sure if you can return the line_item.final_price value here.
But for the condition, i'd run it on variant_title
{% if item.variant_title == line_item.variant_title %}
{% assign final_price = line_item.final_price %}
{% endif %}
{% if final_price %}
{{ final_price | money }}
{% endif %}

Shopify order email template sometimes prints transaction twice

Sometimes (often, but randomly), the order confirmation prints out the payment gateway twice:
Payment
Credit card – 36.90
Credit card – 36.90
I've confirmed that real money is not being transferred twice. But could the transaction count be higher anyways? I'm not so sure about how the transaction_count works, and I don't really know how to debug this.
This part is the problem (I don't see where else it could be):
{% assign transaction_count = transactions | size %}
{% if transaction_count > 0 %}
<h4>Payment</h4>
{% for transaction in transactions %}
{% if transaction.status == "success" or transaction.status == "pending" %}
{% if transaction.kind == "authorization" or transaction.kind == "sale" %}
<p>
{{ transaction.gateway | replace: "_", " " | capitalize }}
—
<strong>{{ transaction.amount | money }}</strong>
</p>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
I've custom built the whole shop, but I can't seem to understand why this is happening.
I'm stumped, I've reached out to Shopify support but they don't want to help because I have added some custom html in the Order Notification email.
A huge thanks for anybody that could help me with this!
There is no other explanation than to assume that in
transactions there are more than one transactions. You can double check the transaction variable and see where the double identical transactions are coming from.

How can filter orders made after a certain date in liquid/ Shopify?

{% for orders in checkout.customer.orders %}
//count the orders
{% endfor %}
I need to count orders made only after a certain date?
How can I do this in Liquid / Shopify?
All Orders have a created_at date that you can output in various formats using the Liquid date filter — you would loop thru the Orders as above and compare that with whatever the "threshold date" in question is, using unix-format dates for comparison:
{% assign ordersThresholdUnix = '2019-01-01' | date: '%s' %}
{% assign ordersCount = 0 %}
{% for orders in checkout.customer.orders %}
{% assign orderDateUnix = order.created_at | date: '%s' %}
{% if orderDateUnix > ordersThresholdUnix %}
{% assign ordersCount = 0 %}
{% endif %}
{% endfor %}
You can then output {{ ordersCount }}.
Note: that I don't think Shopify will allow you to paginate further back than 50 Orders.

Shopify Inventory Display Output on Product Page

I've spent much of the day setting up a new shopify site - my first experience with shopify. Most of it has been pretty straightfoward, but I've found myself somewhat stumped when it comes to showing inventory on the product pages. I'm using the debut theme, and using the editor to update 'product-template.liquid'
After browsing the docs, I've added the following;
{% comment %} Inventory tracking on product page {% endcomment %}
<div id="variant-inventory" class="{% unless current_variant.available %} hide {% endunless %}">
{% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
{% else %}
Out of Stock
{% endif %}
</div>
However, this is currently returning 'out of stock' for items that are in fact, in stock. In addition, what I am hoping to achieve but haven't been able to find documentation for is;
'Items in stock' = We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
'No inventory, but customer allowed to order' = Order now for delivery within 7 days
'No inventory, customer not allowed to order' = Out of Stock
Any pointers much appreciated!
You have:
{% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
{% else %}
Out of Stock
{% endif %}
This will show the 'Out-of-Stock' message for either of the following conditions:
inventory_management is blank (which is the default value)
inventory_policy is continue
What you probably wanted was something like this:
{% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
{% comment %}
We care about inventory on this product - is there any in stock?
{% endcomment %}
(% if current_variant.inventory_quantity > 0 %}
We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.
{% else %}
Out of Stock
{% endif %}
{% else %}
{% comment %}
Any code/messages we might want for products where we don't care about inventory
{% endcomment %}
{% endif %}
I'm a little puzzled by this line of code:
{% if current_variant.inventory_management == "shopify" and current_variant.inventory_policy != "continue" %}
What you are checking is if you are using shopify to track inventory and if the variant options command to allow people to order even if it is out of stock is checked in the admin panel. I would assume that the latter is checked so it is always returning the else.
If it wasn't in stock nothing would show due to this line:
div id="variant-inventory" class="{% unless current_variant.available %} hide {% endunless %}">
As I am unsure how you plan to differentiate between the out of stock and the out of stock can order in 7 days. As there is nothing in the inventory tracker that allows you to enter incoming product (As far as I know). If you were so inclined to enter this manually you could go to product.template.liquid find Ctrl + F
{% unless current_variant.available %}
The Second one down is where to sold-out code takes place
and edit it through adding and removing tags (Using noOrder and noStockCanOrder as example tags)
{% if product.tags contains 'noOrder' %}
<div>No inventory, customer not allowed to order' = Out of Stock</div>
-Insert Current out of stock code here-
{% elsif product.tags contains 'noStockCanOrder' %}
<div>No inventory, but customer allowed to order' = Order now for delivery within 7 days</div>
-Insert Current in stock code here-
{% else %}
<div>Items in stock' = We have {{ current_variant.inventory_quantity }} in stock for next-day delivery when you order by 2pm.</div>
-Insert Current in stock code here-
{% endif %}
You may have to play around with this a little bit as I have never done exactly what you are asking but the theory should be sound and it should get you close to what you want and you can edit it from there.

Show item quantity in shopping cart for a product when on the collections page

I'm in need of some help, what I'd like to do is best described as follows:
When on the collections page
If Product X is added 2 times to the cart
Then add the number 2 next to that product
So the customer knows what products are already inside the cart
So basically, if taking a look at the collections page, I want to be able to see what products are already added into the cart.
I've tried this:
<!-- From 'product-grid-item.liquid' of the default Supply theme -->
{% assign count = 0 %}
{% for item in cart.items %}
{% if product.variants.first.id == item.id %}
{% assign count = count | plus: 1 %}
{% endif %}
{% endfor %}
{% if count > 0 %}<span>{{ count }}</span>{% endif %}
But it simply returns a 1 for Product X. It should return a 2 since it's added twice.
What am I doing wrong?
Here's the working code:
{% assign count = 0 %}
{% for item in cart.items %}
{% if product.id == item.product.id %}
{% assign count = count | plus: item.quantity %}
{% endif %}
{% endfor %}
{% if count > 0 %}<span>{{ count }}</span>{% endif %}
This is because cart.items returns the line items. So it will only return once per unique item id. If you want to count the total item quantity for any item id you need to look at line_item.quantity. Reference docs.shopify.com/themes/liquid-documentation/objects/cart