How do I hide unavailable variants in search results in Shopify? (Debut theme) - search

When I search for products, the result shows that a product is sold out when the first variant (option from the product dropdown) is sold out even though other variants are available.
For example, if a product has colours red & blue (red being the first option), once the red is sold out, the product shows "sold out" in the search result. Only when you click it then you'll see the blue colour is available.
I tried adding a conditional in my search.liquid file, just after looping through the search results before rendering the results, to check if the item is available.
{% for item in search.results %}
{% if item.object_type == 'product' and item.available == true %}
// then rendered the products...
But what that does is hide products that have all the variants (options) sold out.
I can also hide variants that are sold out (like a particular colour or size of a product for example) on the product details page so it doesn't even show up as an option.
But the challenge is with the search results. It still shows sold out for any product that the first option is unavailable. Any help, please?

I have resolved this!
I was inspecting the page on the browser and realised I was trying to modify the wrong file (search.liquid). The file to be changed is the one that renders the cards for the products after search which is the product-card-list.liquid
I set the price to show the first available option using the first_available_variant method
{% if product.available %}
{% include 'product-price', variant: product.first_available_variant %}
{% endif %}
That solved my search results issue.

Related

Can I prevent a filter option from appearing on the 'Search More' view in Odoo 13

In Odoo 13 I have inherited the 'product_template_search_view' record and added a few custom filters. This all works as expected when configuring a product.
Then on a quotation when adding a product, the 'Search More' option is available, which displays all the same filters. There is however one of the filters that I don't want to appear on the 'Search More' view.
Is there a way to prevent this?

Drupal 8 Commerce 2: Placing an "Add to Cart" button in a custom product template

I've written a custom Twig product template 'commerce-product.html.twig', which uses fields such as {{product_entity.body.value}} and {{product_entity.field_picture.entity.uri.value}} to pull out specific data from my Product type and display them in a Drupal view.
I can't find any way of inserting an "add to cart" button into my template though. How is this done?
In your display settings for the product type, have Variations visible and set the format to "Add to cart form".
Then, include {{ product.variations }} in your template.
You can also pull in the product variation fields. For example: {{ product.variation_price }}

How to count the number of grouped attachments for a page in kentico 9?

I want to show a list of attachments, but only if there are any. If not, hide the containing div. How do I do this?
Thanks!
Assuming that you are showing a list of attachments on the current document, you can get the number of grouped attachments with a macro:
{% CurrentDocument.GroupedAttachments["DocumentsAttached"].Count %}
DocumentsAttached would be the name of the field that contains the attachments.
On your attachments list webpart, you can set the value of the visibility field to the following macro:
{% CurrentDocument.GroupedAttachments["DocumentsAttached"].Count > 0 %}
I ended up accomplishing this with a custom query and function.

Kentico - Display first/one value of checked values (boxes)

Not sure how to write a short but meaningful title for the question but I'd like to know if there's a way to display the first (or the second or third etc.) value through Eval or in the macro with Where Condition in the sample code below.
Eval ("PracticeAreas[FIRST ITEM]")
PracticeAreas = '{%CurrentDocument.PracticeAreas[FIRST ITEM]#%}'
PracticeAreas is an item in a Page type, and it has Multiple Choice form control.
Thanks for your input!
Multiple Choice form control saves values as string 'value1|value2|...'. So you just need to split this field by | character.
K#:
{% CurrentDocument.PracticeAreas.Split("|")[0] %}
C#:
<%# Eval("PracticeAreas").ToString().Split('|')[0] %>
CurrentDocument.PracticeAreas will contain the value selected not the options.
This blog post might help you get what you want.

Kentico 9 form macros and different notification recipient based on dropdown value

I have a form field as a drop down (ReasonForMessage) with the data like this:
email1#test.com;Reason One
email2#test.com;Reason Two
So user can select a reason, and then the notification would be send to address attached to that reason. If the Email Notification, for the recipient emails, how do i grab just them email portion with a macro.
Is this correct?
{% ReasonForMessage %}
And how do i get the second part of the data, the actual Reason?
I'm basing this on this article (https://devnet.kentico.com/articles/how-to-send-form-notifications-to-different-emails-based-on-field-values) just not sure it's still valid with Kentico 9.
Try this.
You can try using a delimiter to store both the email and display text, like the colon below...
info#company.com:General;General
sales#company.com:Sales;Sales
support#company.com:Support;Support
Then, to get the individual stored values use Split() to get the email and display text respectively...
{% category.Split(":")[0] %}
{% category.Split(":")[1] %}

Resources