Display only certain Shopify line items - line

This is for a Shopify site. Is there a way to display only certain line item properties in the cart? I have several and it looks messy so only want to display a chosen two or three.

I am assuming you have set up your line item properties similar to how it suggests on the Shopify wiki (Line Item Properties).
You will have something like this in product.liquid:
<div>
<p><label for="property1">Property 1:</label></p>
<p><input type="text" id="property1" name="properties[Property1]" /></p>
</div>
Then put this code in cart.liquid, beneath the cart item's title:
{% for p in item.properties %}
{% if p.first == 'Property2' or p.first == 'Property5' %}
{% unless p.last == blank %}
{{ p.first }}:
{% if p.last contains '/uploads/' %}
<a class="lightbox" href="{{ p.last }}">{{ p.last | split: '/' | last }}</a>
{% else %}
{{ p.last }}
{% endif %}
<br />
{% endunless %}
{% endif %}
{% endfor %}
The code above is straight from the Line Item Properties article on the Shopify wiki (section 3.1 Displaying line item properties on the cart page). I've just added the if statement on the second line to only display the properties I want:
{% for p in item.properties %}
{% if p.first == 'Property2' or p.first == 'Property5' %}
...
{% endif %}
{% endfor %}
Or, if you want to display several properties in a row (e.g. the first 3 properties), you could do it like this (without the if statement):
{% for p in item.properties limit:3 %}
...
{% endfor %}

Related

How to get all tags of all collections products with tag link

I need to fetch all the tags on my collection page and display it within tag link.
I use this below code :
{% assign collection = collections.all %}
{% paginate collection.products by 1000 %}
<h3>All Tags</h3>
<div id="tags">
{% if collection.tags.size == 0 %}
No tags found.{% else %}
{% for tag in collection.tags %}
<a href="{{ collection.url }}/{{ tag | handle }}">
{{ tag }}
</a>
{% unless forloop.last %}, {% endunless %}
{% endfor %}
{% endif %}
</div>
{% endpaginate %}
Please help me to solve my problem.
I think you need to use a built-in solution rather than paginate
use like it
<h3>All Tags</h3>
<div id="tags">
{% if collection.all_tags.size == 0 %}
No tags found.
{% else %}
{% for tag in collection.all_tags %}
{{ tag | link_to_tag: tag }}
{% unless forloop.last %}, {% endunless %}
{% endfor %}
{% endif %}
</div>
please replace below code :
{{ tag }}
To this :
{{ tag | link_to_tag: tag }}

How can I exclude a vendor type using a ternary or unless?

In a page.[].liquid template there are numerous 'vendor' products to be listed. Some with and some without a collection association.
How can I exclude a specific vendor in a for loop using 'unless' or a ternary?
Neither of the following generate any output within the parent container.
<div style="height: 50px;" class="ptest">
{% assign collection = product.available %}
{% for product in collection.all_vendors %}
{% if product.collection != "acme" %}
<div>yes</div>
{{ product.name }}
{% else %}
<div>no</div>
{{ product.name }}
{% endif %}
{% endfor %}
{% for product in collection.all_vendors %}
{% unless product.vendor contains "acme" %}
<div>yes</div>
{{ product.name }}
{% else %}
<div>no</div>
{{ product.name }}
{% endunless %}
{% endfor %}
</div>
List all vendors except "acme":
{%- for vendor in collection.all_vendors -%}
{%- if vendor == "acme" -%}
{%- continue -%}
{%- endif -%}
{{ vendor }} is definitely not "acme"<br>
{%- endfor %}
List collection products except those with vendor "acme":
{%- for product in collection.products -%}
{%- if product.vendor == "acme" -%}
{%- continue -%}
{%- endif -%}
{{ product.name }} vendor is {{ product.vendor }}.<br>
{%- endfor -%}
Sorry, but your code is a mess:
{% assign collection = product.available %} - the collection is now boolean, either true or false
{% for product in collection.all_vendors %} - as of the above collection doesn't have all_vendors attribute.
{% if product.collection != "acme" %} - as of the above, this code will never be reached, but even if it will - the product object doesn't have collection attribute.
{{ product.name }} - where did you get this code? product doesn't have name attribute, you have to use title instead.
{% for product in collection.all_vendors %} - you go through vendors, why do you call them products?
{% unless product.vendor contains "acme" %} - as this is the next line after the above one, the product would be a vendor, not a product object, so you should use it as a string i.e. {% unless product contains "acme" %}
After a lot of searching, it looks like the only solution to displaying products that A. are 'all except' a single vendor and B. are not part of any collection, is to use a more simple if-math.
{% for product in collections.all.products %}
{% if product.collections.size < 1 && product.vendor != "acme" %}
<h3>
<a href="{{ product.url }}">
{{ product.title }}
</a>
</h3>
{% endif %}
{% endfor %}
Running through all products to loop those that are not part of a collection, generates the proper result.

Adding custom data in shopify order confirmation

I'm currently trying to find away to pass some custom data to each one of my shopify order confirmations. Specifically I need to pass a custom URL that will be displayed in the order confirmation email. According to the shopify documentation I can receive a property from a product and pass it to my confirmation form like so.
{% assign property_size = item.properties | size %}
{% if property_size > 0 %}
{% for p in item.properties %}
{% assign first_character_in_key = p.first | truncate: 1, '' %}
{% unless p.last == blank or first_character_in_key == '_' %}
{{ p.first }}:
{% if p.last contains '/uploads/' %}
<a class="lightbox" href="{{ p.last }}">{{ p.last | split: '/' | last }}</a>
{% else %}
{{ p.last }}
{% endif %}
<br>
{% endunless %}
{% endfor %}
{% endif %}
Using this I figure I can pass a custom url by doing something like this:
mycustomurl.com/linepropertyitem
My problem is that each line property includes the tittle of the line property item and the input value. So my url using this method would be
mycustomurl.com/linepropertyitem = linepropertyitemtext
Any ideas or pointers how this can be done?
which wouldn't work in a URL.
You could do it like this:
{% assign property_size = item.properties | size %}
{% if property_size > 0 %}
{% for p in item.properties %}
{% assign first_character_in_key = p.first | truncate: 1, '' %}
{% unless p.last == blank or first_character_in_key == '_' %}
{% if p.last contains '/uploads/' %}
<a class="lightbox" href="{{ p.last }}">{{ p.last | split: '/' | last }}</a>
{% else %}
{{ p.first }}:
{{ p.last }}
{% endif %}
<br>
{% endunless %}
{% endfor %}
{% endif %}
But the best thing you could do would be to analyze the code from Shopify and understand what is going on. That way you'll be able to do a lot more on your own.

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.

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

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.