How to hide products in Shopify search results based on a vendor name - shopify

I'm in a situation where hiding a certain vendors products in the control panel isn't an options due to an outside POS. For a test in search.liquid, I used search.terms like below. This code works but not everyone will type thevendor exactly the same way and will see the products if they don't type thevendor.
{% for item in search.results %}
{% if search.terms == 'thevendor' %}
{% else %}
{% include 'search-result' %}
{% endif %}
{% endfor %}
I tried to figure out how to write the code to hide these products in a better way. I tried product.vendor like below but when I search for those products individually they are not hidden. The code:
{% for item in search.results %}
{% if product.vendor == 'thevendor' %}
{% else %}
{% include 'search-result' %}
{% endif %}
{% endfor %}
Can someone tell me what I'm missing here? It seems it doesn't know what product.vendor is but when I print out who the vendor is, it displays the vendor. I don't understand why it's not hiding the products that are associated with this vendor.

{% for item in search.results %}
{% if item.product.vendor == 'thevendor' %}
{% else %}
{% include 'search-result' %}
{% endif %}
{% endfor %}
This should work.

Related

In shopify how to display wholesale top link if customer is login in desktop?

I want to display "wholesale" collection link on top menu if customer is login otherwise i do not want to display "wholesale" collection link.
I followed following link instruction but it is not working for desktop menu
https://www.envision.io/blogs/ecommerce-pulse/80312001-how-to-add-a-wholesale-area-to-your-shopify-store-without-an-app
and added bellow code in mobile menu "header.liquid" file
{% assign menu_handle = 'main-menu' %}
{% if customer %}
{% if customer.tags contains 'wholesale' %}
{% assign menu_handle = 'main-menu-wholesale' %}
{% endif %}
{% endif %}
{% for link in linklists[menu_handle].links %}
but when i try to put same code for desktop it is not working i am replacing above code with following code
{% include 'site-nav', linklist: section.settings.main_linklist %}
but it is not working after put following code for desktop nothing display on header before login and after login.
{% assign menu_handle = 'main-menu' %}
{% if customer %}
{% if customer.tags contains 'wholesale' %}
{% assign menu_handle = 'main-menu-wholesale' %}
{% endif %}
{% endif %}
{% for link in linklists[menu_handle].links %}
Thanks
I think you need to try something like this.
{% assign menu_handle = 'main-menu' %}
{% if customer %}
{% if customer.tags contains 'wholesale' %}
{% assign menu_handle = 'main-menu-wholesale' %}
{% endif %}
{% endif %}
{% include 'site-nav', linklist: menu_handle %}

Checking if no compare_price exists in Shopify Liquid

I want to check if there's no compare price, and I cannot get any of the following to work in Shopify:
{% if price > compare_at_price %}
{% if compare_at_price == 0 %}
{% if compare_at_price == "" %}
I want to output some HTML when the compare_price doesn't exist.
You are missing the object here to get its attributes:
{% if product.price > product.compare_at_price %}
Do something
{% endif %}
To check if there is one:
{% if product.compare_at_price %}
Do sthg
{% endif %}
To check if there isn't one:
{% unless product.compare_at_price %}
Do sthg
{% endunless %}
Documentation:
https://shopify.dev/docs/themes/liquid/reference/objects/product

Shopify Liquid - Related products as specific handles from a metafield

I am trying to use a Shopify metafield with a comma separated list of handles (ie: handle1,handle2) to call specific related products. These related products are displayed on individual product pages. My problem is: I cannot figure out how to get the products from the array to iterate and display.
I am using the Boundless theme, so I am trying to call/display the products in the same manner as a collection page. This may be part of my problem.
My current code calls the actual product on the page instead of the related products for some reason.
Here is my current code:
{% if product.metafields.c_f['Shown With'] %}
{% assign shownwith = product.metafields.c_f['Shown With'] | split: ',' %}
{% capture shownwith_items %}
{% for product in shownwith %}
{% include 'product-grid-width' with product_image_type: section.settings.product_image_type, product_image_size: section.settings.product_image_size %}
{% include 'product-grid-item' with product_image_spacing: section.settings.product_image_spacing, vendor_enable: section.settings.vendor_enable %}
{% endfor %}
{% endcapture %}
{% endif %}
{% if product.metafields.c_f['Shown With'] %}
{% assign shownwith = product.metafields.c_f['Shown With'] | split: ',' %}
{% capture shownwith_items %}
{% for relPro in shownwith %}
{% assign product = all_products[srelPro] %}
{% include 'product-grid-width' with product_image_type: section.settings.product_image_type, product_image_size: section.settings.product_image_size %}
{% include 'product-grid-item' with product_image_spacing: section.settings.product_image_spacing, vendor_enable: section.settings.vendor_enable %}
{% endfor %}
{% endcapture %}
{{ shownwith_items}}
{% endif %}

can i use in_array () in Shopify

I am new To Shopify ! i am trying to something like,i want to check that,the ID which i put on Textbox is in array or not !
here is my Product.Liquid
{% if settings.make_an_offer %}
{% for id in product.id %}
{% include 'pricewaiter' %}
{% endfor %}
{% endif %}
in above code,i need to check that settings.make_an_offer is in this array product.id or not..
make_an_offer this is an ID of my Textbox
so how can i do this?
any help please?
Place it like this :
{% for id in product.id %}
{% if settings.make_an_offer === id %}
{% include 'pricewaiter' %}
{% endif %}
{% endfor %}

Django simple-friends templte help!

I have been trying to do this forever it seems.
I don't understand what to put in the templates and can find no guidelines help.
My Profile page
need friends list
something like:
{% for friends in Friendship.objects%}
<li>are_friends: {{ friends.are_friends.user.username}}</li>
<li>is_invited: {{ friends.is_invited}}</li>
{% endfor %}
Well being a bit of newcomer to Django and programming in general this took me ages to work out but I got there in the end so Ill share what I did. First of all though the code might no be exactly what you need but you will get the idea. I also might have made some mistakes here or there is better way to do it so don't assume this is the most correct way but it does work.
First of all I split my code into two templates. One for when I am on the profile page of another user and one for when I am on my "Manage my Friends" page. Please bare in mind this is basically pure template code and there has been no stylings applied. Thats up to you to do.
{% if user|friends %}
{% with user|friends as list %}
Friends List
{% for m in list %}
{{ m }}
{% endfor %}
{% endwith %}
{% else %}
Search for Friends
{% endif %}
{% if user|friendshiprequests %}
{% with user|friendshiprequests as list %}
{% if list.received %}
Friendship Requests Received
{% for m in list.received %}
{{ m }}
Accept Request
Decline Request
Block User
{% endfor %}
{% endif %}
{% if list.sent %}
Pending Friend Requests Sent by You
{% for m in list.sent %}
{% if not user|isblockedby:m.to_user %}
{{ m.to_user }}
Cancel Request
{% endif %}
{% endfor %}
{% endif %}
{% endwith %}
{% endif %}
{% if user|blocks %}
{% with user|blocks as list %}
{% if list.applied %}
List of Blocked Users
{% for m in list.applied %}
{{ m }}
{% endfor %}
{% endif %}
{% endwith %}
{% endif %}
For the profile page of another user I have the following code. Bear i nmind I have a profile application which is passing in the username of the profile I am looking at and want to interact with. You may need to find another way to do it.
{% if not user == profile.user %}
{% if not user|isblockedby:profile.user %}
{% if not profile.user|isblockedby:user %}
{% if not user|isfriendswith:profile.user %}
{% if not profile.user|isfriendshiprequest:user %}
{% if user|isfriendshiprequest:profile.user %}
You have already sent a friend request
Cancel Friend Request
{% else %}
Send Friend Request
Block User
{% endif %}
{% else %}
{% endif %}
{% else %}
You and {{ profile.user}} are friends
trans Unfriend
Block User
{% endif %}
{% else %}
You have blocked this User
Unblock User
{% endif %}
{% else %}
You have been blocked by this user
{% endif %}
{% endif %}
{% if not user == profile.user %}
{% if not user|isblockedby:profile.user %}
{% if not profile.user|isblockedby:user %}
{% if not user|isfriendswith:profile.user %}
{% if profile.user|isfriendshiprequest:user %}
Accept Friendship Request
Accept Request
Decline Request
Block User
{% endif %}
{% endif %}
{% endif %}
{% endif %}
{% endif %}
Hope this helps.
This guide should be a good start:
http://docs.djangoproject.com/en/dev/ref/templates/
Let's analyze the code a little bit:
Friendship.objects would return the default manager on Friendship model. At this point you probably want to call one of the methods that return an iterator on this manager. For example the following template code iterates over all Friendship's:
{% for friendship in Friendship.objects.all %}
But this doesn't make a lot of sense. You probably want to iterate over Friendships for a particular user. The following code iterates over friends of the active user:
{% for friendship in user.friendship.friends.all %}
{{ friendship.user.username }}
{% endfor %}
The code above may not work. I can't remember why. But there is already a tag that gives you friends of a specific user:
{% load friends_tags %}
{% friends_of user %}
{% for friend in friends %}
{{ friend.username }}
{% endfor %}
Rant Section
It seems the app is not usable without reading the source. This is not good at all. The author of this app should have written better documentation. I should allocate some time to work on these issues sometime.