All products in a product_tag are not showing up on collection page - shopify

The issue is odd- on a collection page where we show all products separated by their product types, the page only shows around 80% of the total. There is no limit hit on any page yet, and when we click through to a product_type page, all products are clearly there.
Here's the .liquid theme file we are using now-
{% if collection.handle %}
<!-- basic collection -->
<!-- sorting by product type within collection (with titles) -->
{% assign sorted_by_type = collection.all.products | sort: 'type' %}
{% for product_type in collection.all_types %}
<div class="products clearfix collection">
{% assign the_type = product_type %}
<h2>{{ the_type | link_to_type }}</h2>
{% paginate collections.all.products by 2000 %}
{% for product in collections.all.products %}
{% if product.type == the_type %}
{% include 'product-loop' %}
{% endif %}
{% endfor %}
{% endpaginate %}
</div>
{% endfor %}
{% else %}
<!-- vendor -->
{% assign image_name = collection.title | handleize | append: '.jpg' %}
<div class="banner my-backstretch" data-vendorname="{{ collection.title | handleize }}" data-src="{{ image_name | asset_url }}"></div>
<!-- sorting by product type within vendor (with titles) -->
{% assign sorted_by_type = collection.products | sort: 'type' %}
{% for product_type in collection.all_types %}
<div class="products clearfix collection">
{% assign the_type = product_type %}
<h2>{{ the_type | link_to_type }}</h2>
{% paginate collection.products by 2000 %}
{% for product in collection.products %}
{% if product.type == the_type %}
{% include 'product-loop' %}
{% endif %}
{% endfor %}
{% endpaginate %}
</div>
{% endfor %}
{% endif %}
Any help or assistance pinpointing this error would be great! Not super familiar with Shopify yet.

Even though you're telling it to paginate by 2000 products, you're still going to be limited to 50.
See here in the Shopify docs for more info:
{% paginate collection.products by 9 %}
In the above example, the number is 9 but in your theme, that number could be 6 or 12, or anything else that is smaller or equal to 50. This number corresponds to the number of products showcased per page.
Edit that number to increase or decrease the number of products shown per page. Do not ever paginate by more than 50.

Related

Group Shopify products collections by Vendor in liquid template in Shopify v2

I am using Masonry theme , and I am trying to group the results for products in the collection by (vendor name and and link to the vendor collection).
I tried too many approaches and that the closest I could get due my limitation to using liquid , below is only showing the first set of products and only the vendor names for the rest
"**" that's my initial setup code and the rest is from the template.
<div class="cc-filters-results">
<div class="{% if settings.adv_ratio %}fixedlayout{% else %}blocklayout{% endif %} {% if section.settings.coll_infscr %}do-infinite{% endif %}">
{%- if collection.products != blank and settings.adv_ratio -%}
{%- capture calculated_aspect_ratio -%}{% render 'minmax-image-ratio', products: collection.products, type: settings.prod_thumb_img_ratio %}{%- endcapture -%}
{%- endif -%}
**{%- for vendor in collection.all_vendors -%}
<h2>{{ vendor }}</h2>
{%- assign products = collection.products | where: "vendor", vendor | limit: 1 -%}
{%- for product in products limit:3 -%}
{% render 'product-block', product: product, product_collection: collection, calculated_aspect_ratio: calculated_aspect_ratio %}
{% else %}
<div class="block text no-inf size-large"><div class="main">{{ 'collections.general.no_matches' | t }}</div></div>
{% endfor %}
{% endfor %}**
{% for i in (1..10) %}
<div class="block no-inf product block--flex-placeholder"></div>
{% endfor %}
</div>
{% if paginate.items > 0 %}
<div class="row pagination-row">
{% render 'pagination-control', paginate: paginate %}
</div>
{% endif %}
</div>

How to exclude sold out products from related products section Shopify?

I'm trying to prevent that sold out products will be shown on related products section in my Shopify store. I tried to use {% if product.available %} in the beginning of the code but without success.
Here is the code of this section -
{% if collection and collection.all_products_count > 1 %}
{% assign col = collection.handle %}
{% else %}
{% assign col = product.collections.last.handle %}
{% endif %}
{% for tag in product.tags %}
{% if tag contains 'meta-related-collection-' %}
{% assign related_collection_handle = tag | remove: 'meta-related-collection-' %}
{% if collections[related_collection_handle].all_products_count > 0 %}
{% assign col = related_collection_handle %}
{% assign collection = collections[col] %}
{% endif %}
{% endif %}
{% endfor %}
{% if col %}
{% if collections[col].all_products_count != 1 or collections[col].products.first.id != product.id %}
{% assign skip_product = product %}
{% assign products = collections[col].products %}
{% unless sidebar %} <div class="container"> {% endunless %}
<div class="related-products__title {% unless section.settings.related_products_style == 'slider' %}{% if sidebar %}twelve columns{% else %}sixteen columns{% endif %}{% endunless %}">
<h4 class="title center">{{ 'products.product.related_items' | t }}</h4>
<div class="feature_divider"></div>
</div>
<div class="clear"></div>
{% unless sidebar %} </div> {% endunless %}
{% if section.settings.related_products_style == 'slider' %}
{% assign limit = section.settings.related_products_limit %}
<div class="related-products related-products--slider js-related-products-slider">
{% if col and collections[col].all_products_count > 0 and product.available %}
{% include 'product-slider', related_products: true %}
{% endif %}
</div>
{% else %}
{% assign limit = section.settings.related_products_limit | plus: 1 %}
{% assign products_per_row = section.settings.products_per %}
{% if col and collections[col].all_products_count > 0 and product.available %}
{% unless sidebar %}<div class="container related-products--grid">{% endunless %}
<div class="{% if sidebar %}twelve{% else %}sixteen{% endif %} columns">
{% include 'product-loop', related_products: true %}
</div>
{% unless sidebar %}</div>{% endunless %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
Hope to get some help, thank you!
Your related collection assignment looks a little bit complicated but should do the trick.
The issue comes with the second part. Once your collection is defined. This kind of code should work:
{% if col %}
<!-- First, memorize your current product handle -->
{% assign current_product_handle = product.handle %}
<!-- Then open the loop to get products inside related collection -->
{% for product in col.products %}
<!-- Filter your results to avoid identic product and out of stock products -->
{% unless product.handle == current_product_handle %}
{% if product.available %}
{{ product.title }} and other things you might want to display about related products.
{% endif %}
{% endunless %}
{% endfor %}
{% endif %}

Hiding products based on customer tag Shopify search.liquid

I hope someone may be able to help with this.
I am currently setting up my store with shopify and have duplicated my products for retail and wholesale customers.
The only issue I am faced with is that the retail products are still showing when a customer with the 'wholesale' tag uses the search box.
I was wondering if I add a 'retail' tag to the relevant products, can add any code in search.liquid so that if the customer.tag contains 'wholesale' do not show products with product.tags 'retail' or something along those lines?
My current search.liquid looks like:
<!-- /templates/search.liquid -->
{% comment %}
To return only products or pages in results:
- http://docs.shopify.com/manual/configuration/store-customization/return-only-product-in-storefront-search-results
- Or manually add type=product or type=page to the search URL as a parameter
{% endcomment %}
{% comment %}
Check to enforce respond.js
{% endcomment %}
{% assign respond_js_secret_key = shop.domain | md5 %}
{% unless search.terms == respond_js_secret_key %}
{% comment %}
Avoid accessing search.results before the opening paginate tag.
If you do, the pagination of results will be broken.
{% endcomment %}
{% paginate search.results by 12 %}
<div class="grid">
<div class="grid__item">
<header class="section-header text-center">
{% if search.performed %}
{% if search.results_count == 0 %}
<h1 class="text-center">{{ 'general.search.no_results_html' | t: terms: search.terms }}</h1>
{% else %}
<h1 class="text-center">{{ 'general.search.results_for_html' | t: terms: search.terms }}</h1>
{% endif %}
{% else %}
<h1 class="text-center">{{ 'general.search.title' | t }}</h1>
{% endif %}
<hr class="hr--small">
</header>
{% include 'search-bar', search_btn_style: 'btn', search_bar_location: 'search-bar--page' %}
{% if search.performed %}
<hr class="hr--medium hr--clear">
<div class="grid-uniform">
{% for item in search.results %}
{% assign itemIswholesale = false %}
{% if item.tags contains 'wholesale' or item.title contains 'wholesale' %}
{% assign itemIswholesale = true %}
{% endif %}
{% if itemIswholesale and customer and customer.tags contains 'wholesale' %}
{% if item.object_type == 'product' %}
{% assign product = item %}
{% include 'product-grid-item' %}
{% else %}
<div>
<div>
<a href="{{ item.url }}">
<span>
<span>{{ item.title }}</span>
{{ item.content | strip_html | truncatewords: 60 }}
</span>
</a>
</div>
</div>
{% endif %}
{% else %}
{% unless itemIswholesale %}
{% if item.object_type == 'product' %}
{% assign product = item %}
{% include 'product-grid-item' %}
{% else %}
<div>
<div>
<a href="{{ item.url }}">
<span>
<span>{{ item.title }}</span>
{{ item.content | strip_html | truncatewords: 60 }}
</span>
</a>
</div>
</div>
{% endif %}
{% endunless %}
{% endif %}
{% endfor %}
</div>
{% if paginate.pages > 1 %}
{% include 'pagination' %}
{% endif %}
{% endif %}
</div>
</div>
{% endpaginate %}
{% else %}
{% include 'respond' %}
{% layout none %}
{% endunless %}
I am a complete novice and have managed to get by this far following help and tutorials online so any help would be very much appreciated.
I can't afford to subscribe to an additional app at present, such as locksmith and would really like to keep control so I can continue administration in future,
Thanks in advance,
You may try doing something like that inside the
{% if search.performed %}
condition.
First get some information about user and store it:
{% assign wholesale = false %}
{% if customer %}
{% assign customer_tags = customer.tags | split: "," %}
{% if customer_tags contains 'wholesale' %}
{% assign wholesale = true %}
{% endif %}
{% endif %}
Explanations : first you assign a false statement to the wholesale status. Then you check if it is customer ( no need to go further if user is not connected). If he is, then you check if he has a wholesale tag. If he is you assign a true statement.
Then you are able to display something different this way:
{% for result in search.results %}
{% if wholesale %}
Do something
{% else %}
Do something else
{% endif %}
{% endfor %}
Please not that you may have some issues with pagination.

shopify Liquid error: Memory limits exceeded

I was trying to display all the product types of my site in one page , 2 days back it was listing all the all the product type.
But now when that page is loads its giving error like "shopify Liquid error: Memory limits exceeded"
Here is my code
<div class="rte">
{{ page.content }}
<ul class="vendor-list block-grid three-up mobile one-up">
{% for product_type in shop.types %}
{% assign its_a_match = false %}
{% capture my_collection_handle %} {{ type | handleize | strip | escape }} {% endcapture %}
{% assign my_collection_handle_stripped = my_collection_handle | strip | escape %}
{% for collection in collections %}
{% if my_collection_handle_stripped == collection.handle %}
{% assign its_a_match = true %}
{% endif %}
{% endfor %}
{% if its_a_match %}
<li class="vendor-list-item">{{ product_type }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
how can i overcome this problem ?
Try the following. It's faster and more efficient.
<div class="rte">
{{ page.content }}
<ul class="vendor-list block-grid three-up mobile one-up">
{% for product_type in shop.types %}
{% assign type = product_type | strip | escape | handleize %}
{% assign collection = collections[type] %}
{% if collection.handle != '' %}
<li class="vendor-list-item">{{ product_type }}</li>
{% endif %}
{% endfor %}
</ul>
</div>

Shopify - How to exclude a collection in paginate?

I need to exclude a collection inside the paginate loop. But if I use the conditional statement, it will still be counted in paginate count.
So If I paginate by 10 and there are 2 products from the excluded collection in first page, I will only see 8 products in first page.
Any solution for this? Here's my snippet:
{% paginate collection.products by 10 %}
<ul>
{% for product in collection.products %}
<!-- Check for collection -->
{% assign is_treatment = false %}
{% for c in product.collections %}
{% if c.handle == "salon-treatment" %}
{% assign is_treatment = true %}
{% endif %}
{% endfor %}
{% unless is_treatment %}
<li>{{ product.title }}</li>
{% endunless %}
{% endfor %}
</ul>
{% endpaginate %}
Note: This question is duplicated from the one I posted in Shopify forum.
What I did for something like this was first load in all the desired products into a collection of my own (basically an array of objects), and then paginate THAT array... so, if you write a function called exclude_some_products which returns all the unexcluded products, do this:
{% assign my_smaller_collection = exclude_some_products collection %}
{% paginate my_smaller_collection.products by 10 %}
<ul>
{% for product in my_smaller_collection.products %}
<!-- Check for collection -->
{% assign is_treatment = false %}
{% for c in product.collections %}
{% if c.handle == "salon-treatment" %}
{% assign is_treatment = true %}
{% endif %}
{% endfor %}
{% unless is_treatment %}
<li>{{ product.title }}</li>
{% endunless %}
{% endfor %}
</ul>
{% endpaginate %}
p.s. pardon my code, I'm not even sure what language this is!