Shopify check how many orders a product has - shopify

Is possible to check how many orders/purchases a product has?
For example if a product has 3 orders/purchases, I want to hide it.
{% for product in collection.products %}
// if ( product sells != 3 )
<h2 class="title">{{ 'product.title' | t }}</h2>
{% endfor %}

In the product details, you can add a Metafield resource to it that is a number.
Edit that metafield so that it contains a 3 for example
in your theme, when you are examing the product details to decide whether to render the product or not, check the value of the metafield resource assigned to the product.
profit.

Related

Shopify get lowest price product if available in product having same title

I have duplicate products which offer same size or different size products with same title but vendors is different. I want to display products which ever cheaper in my website. So my website will always display products from one vendor only ( Which ever cheaper ). In product details page i want to check this logic to find the same title products from different vendors. I tried the below code . When i given the handle statically then it is showing other vendor products finely. I want to make it dynamic. Can anybody help me on this.
Now i want to display the lowest price product if available.
Product is having different sku,handle, price but title is same.
Please help me to show lowest price product.
{% assign some_handle = product.handle %}
{% assign custom_product = all_products[some_handle] %}
{{ product.title }} is {{ product.price | money }}, but {{ custom_product.title }} is {{ custom_product.price | money }}
i tried this code in product_template.liquid file but it is not working as expected.

Display collection metafield in product page (Shopify)

there is a way to display a collection metafield in the porduct page?
Each product have a product type that matches the collection, so in the product page of this product I want to display the metafield of that product.
{{ collection.metafields.custom.metafield1 }} doesn't work because of course I'm not in the collection page, so I need to link collection.metafields.custom.metafield1 and product.type, but I don't know how.
Hope I was clear, thank you.
Each product have a product type that matches the collection, so in the product page of this product I want to display the metafield of that product.
I solved with the following code
{% assign collectionHandle = product.type %}
{% assign the_collection = collections[collectionHandle] %}
{% assign my_metafield = the_collection.metafields.custom.categoria_1 %}
{{ my_metafield.value }}
As you suggest it was fun to solve the problem :-D
Hard to understand your question, but it would probably go like this. In Liquid, every product has a type. So you would use that on the collections object to get just the collection you want, and from that, the special metafield assigned.
{% assign the_collection = collections['{{ product.type }}'] %}
That assigns some collection, assuming it exists, based on the current product type, to your variable. Now you would ask for your special metafield that may or may not exist in that collection's metafields.
{% assign my_metafield = the_collection.metafields.some_namespace.some_key %}
And with that, you could get the value and splash it out there as you please.
<h1> {{ my_metafield.value }} </h1>
yes I understand your point, and I figure out your code and I tried to use it:
{% assign the_collection = collections['{{ product.type }}'] %}
{% assign my_metafield = the_collection.metafields.custom.categoria_1 %}
<span>{{ my_metafield.value }}</span>
and I don't understand why it does not work.
The product type exists and is "Piatti"
The collection "Piatti" exists and has the metafield custom categoria_1
I attach a sceenshot of the metafield in order to be more cleare.
metafield structure

How can I display specific Collection on a product or list page

I have a shopify store with new, used and refurbished amplifiers & speakers.
This condition is stored in a manual collection (four of them). The others collections being automated.
I would like to display the condition of the product on the product page or the products list.
So basically I need to get all the collections and filter to display one of the four :
If the product belongs to collection "used" display collection "used"
If the product belongs to collection "new" display collection "new"
etc...
The closest to what I want to do has been made trough this code :
{% assign product_collection = product.collections.first %}
{% if product_collection %}
This product is part of my {{ product_collection.title | link_to: product_collection.url }} Collection
{% endif %}
Found here : https://community.shopify.com/c/Shopify-Design/RESOLVED-Display-Collection-on-Product-Page/td-p/230899
With this I am not able to filter on the four collections.
I have spent the day on this...If somebody can help, that would save my day :)
You can add all collections(title or handle value) on the product-grid-item.liquid.
<div class= "grid-item
{% for product_collection in product.collections %}
{{product_collection.title | handle }}
{% endfor %}
">
...
</div>
And then you can filter them with JavaScript on the frontend.
Hope this could help you

Shopify products' collection empty in collection context

I'm trying to filter my related products by collections.
Every product belongs to two collections: One for the material, one for the room.
The Material one is an automatic collection which get products with a certain tag.
The Room one is populated manually.
When I get to the product page I load the related products like this (the related product must share both collections with the current product) :
{% for related_product in collection.products %}
{% if product.collections[0].handle ==
related_product.collections[0].handle and product.collections[1].handle
== related_product.collections[1].handle and related_product.handle !=
product.handle %}
<div class="Carousel__Cell">
{% include 'product-item', product: related_product,
show_product_info:
section.settings.show_product_info, show_labels: true %}
</div>
{% endif %}
{% endfor %}
Strangely this work only for some products. In some of them product.collection seems null, which makes no sense!
All of the products appear properly in the correct collection.
The problem is happening in the context of a collection (but we will need to make it work in all contexts)
We found out it was an import/sync problem. We had to remove all existing products and re-import them. It fixed the issue.

How to display best seller products on front-page using Shopify

I have a dev theme for a shopify store. Basically it's a child theme. I would like to get how to display the best selling products on the front page. I tried something like this but no luck maybe because the sample is outdated.
<div class="row">
{% for product in collections["all"].products | limit:12 | sort_by: 'best-seller' %}
{% include 'product-grid-item' with "all" %}
{% endfor %}
</div>
Is there any way we can create something like this? Thanks in advance.
An easy way of doing it, as sort on Shopify won't work with the value best-seller, is to create a new Collection called (for example) Best Sellers where you have all your products (you could set as the sole condition for product price to be greater than $0 if it applies on your store).
Then, set that collection sorting to By best selling on your admin dashboard.
Finally, use Liquid in a similar way as per the following:
<div class="row">
{% for product in collections.best-sellers.products | limit:12 %}
{% include 'product-grid-item' with "all" %}
{% endfor %}
</div>