Overcome limit of 50 in for loop in shopify - pagination

I have paginated a product list over a limit of 50 to fit in the whole page (index.liquid).
But the if condition within for loop doesn't apply over whole paginated items as for loop is limited to 50 items. Any help would be appreciated.
{% paginate collections.all.products by 1000 %}
{% for product in collections.all.products %}
{% if product.metafields.spr.reviews %}
{{ product.metafields.spr.reviews }}
{% endif %}
{% endfor %}
{% endpaginate %}

The 50 items limit per page should be correct and it is documented. Except for the fact that... It is not. Actually, you can circumvent that limit in Shopify by establishing a higher limit of up to 1000 items per page. Just being redundant, here is a sample code:
{% paginate mycollection.products by 250 %}
{% for product in mycollection.products %}
{% include 'my-product-template' %}
{% endfor %}
{% endpaginate %}
Also answered here.

No, you cannot overcome it, You can query up to 50 product per page, Shopify won't allow more than 50 products, in order to maintain server load balance.
quote from shopify documentation : http://docs.shopify.com/manual/configuration/store-customization/page-specific/collections/add-view-all-to-collection-pages
Don't ever paginate a collection by more than 50, that's how many products maximum you should query per page. Be respectful of Shopify's app servers. If you are not using any paginate tags, pagination does kick in behind the scene and you will only receive the first 50 products in said collection.

Related

Render a link field inside a paragraph template drupal 8

I have a paragraph called link. In this paragraph there is a single link field that allows multiple values. In the paragraph-link.html.twig file I want to render all of the links added to the paragraph. Instead I get the same link duplicated as many times as the number of link values. So if I add two links, it renders the first link twice. I also need it to work with external and internal links. Currently it only renders the external links properly (but only ever renders the first one).
{% for item in paragraph.field_link %}
{{ paragraph.field_link.title }}
{% endfor %}
Thanks for the comments, the following is working for external links but not internal ones. Internal link URI renders as "internal:/"
{% for item in paragraph.field_link %}
{{ item.title }}
{% endfor %}
With the help of the comments I was able to get this working as I wanted within the paragraph template. Below is the working code for a Link field that allows multiple values within a paragraph field.
{% for item in paragraph.field_link %}
{{ item.title }}
{% endfor %}

Dump(item) not working in Twig template drupal

I have twig template for default view
{% for item in items %}
{{ item.content }}
{% endfor %}
{{ item.content }} have values but when I tried to print the whole array like
{% for item in items %}
{{ item }}
{% endfor %}
It is not working. I have enabled (service.yml)
debug true
cache false
autoload true
but it's not working. Any help would be appreciated
Try and install the Devel plugin with its Kint extension. Once you have both running you could use: {{kint(item.content)}} to get a full list of all items within the content array.
Below an example of the kint() output.
As both are development plugins, they should only be used for debugging and not be installed on a production website.

Modifiable pagination on Shopify Collection

I was wondering if there was any way to make pagination user modifiable on the front-end? I've been searching for a solution, but can't find anything similar that addresses this specific problem.
I'm aware that at present, you can assign a limit to the pagination, for example:
{% paginate collection.products by 12 %}
What I'm trying to achieve here is the ability for the user to change the number of products viewable, per page, from a dropdown menu. So for example, the user chooses 24, the page refreshes with the revised pagination limit active on the page.
Any help getting started here would be greatly appreciated. Thanks!
You could create 2 alternate templates called 12 collection.12.liquid and 24 collection.24.liquid which would paginate by 12 and 24, respectively. All your templates will be below:
collection.liquid:
{% paginate collection.products by 20 %}
{% include ‘collection-template’ %}
{% endpaginate %}
collection.12.liquid:
{% paginate collection.products by 12 %}
{% include ‘collection-template’ %}
{% endpaginate %}
collection.24.liquid:
{% paginate collection.products by 24 %}
{% include ‘collection-template’ %}
{% endpaginate %}
Then you could create links to those other templates using the view parameter.
<a href=”http://myshop.com/collections/shirts?view=12”>12 per page</a>
<a href=”http://myshop.com/collections/shirts?view=24”>24 per page</a>
More detail, please refer this link here

Paginate Shopify blog with offset? (Liquid)

I'm trying to figure out how to paginate a blog starting at a specific offset. For example, the first page features posts 5-8, the second page 9-12, third page 13-16, and so on. This doesn't seem to work, but I'm looking for something along these lines -
{% paginate blog.articles offset:4 by 4 %}
{% for article in blog.articles
...
{% endfor %}
{% endpaginate %}
Are there any workarounds here?
I was trying to see if there's any way I could find a decent workaround in Liquid but there isn't, since you're offsetting a full page; it'd be perfectly possible to show 5-8 on the first page, but you'd need to show 9-16 on second page and so on and so forth. I'm afraid Shopify paginate won't help you here.
There could be specific workarounds for your situation; please give us more detail and we'll see. For example, if you always want to show the four latest blog articles on every page, and leave pagination handle the rest, a possible way would be to do something as per the following:
{% for article in blogs.news.articles limit: 4 %}
{{ article.title }}
{% endfor %}
{% paginate blog.articles by 4 %}
{% unless paginate.current_page == 1 %}
{% for article in blog.articles %}
{{ article.title }}
{% endfor %}
{% endunless %}
{% include 'pagination' %}
{% endpaginate %}
So outside of any pagination go through the handle to obtain the latest 4 to feature them, and if you're not on page 1, use pagination to print 4 more articles on each page.
If not, this is one of the scenarios where you should consider exposing your own service that internally calls and retrieves articles from the Shopify API as per your needs.
The offset should be specified in your loop parameters, not in pagination.

Membership Level issue in NationBuilder

I have a website built in NationBuilder. There I needed to make another Membership level. I have done that. But the issue is that it is not showing in "Who can view this page" dropdown in page settings. Anyone has any idea how to do that.?
Thanks in advance
It seems you can't control who can view this page via membership levels.
From a NationBuilder FAQ, How do I set up a five-tier membership site:
In NationBuilder... being a member is a binary state: you either are
or you are not a member. While NationBuilder allows you to sell
various membership levels, the database doesn't recognize those
various levels as distinct and different from a permissions level.
That means that if you make a page viewable to "Members" it will be
viewable to all members, equally.
There's really no good workaround for this that's based on membership
level of which I am aware. You can, however, use conditional liquid
tags to display different content on a given page to logged-in users
depending on what tags their NationBuilder profile has. Since each
membership level can be configured to automatically tag people, this
method could be employed to display different content to individuals
who have different membership levels (or none at all).
You can accomplish this by editing the page template. For instance, suppose you wished to restrict a page to only users with MEMBER_A membership.
{% assign hasPagePermission = false %}
{% for membership in request.current_signup.memberships %}
{% if membership.membership_type_name == "MEMBER_A" and (membership.status == "active" or membership.status == "grace period") %}
{% assign hasPagePermission = true %}
{% endif %}
{% endfor %}
{% if hasPagePermission == true %}
{{ page.basic.content }}
{% else %}
{% include 'access_denied' %}
{% endif %}
I realise that your original post was six years ago, however I post this in the hope that it will be helpful to others (or indeed me when I forget how to do this and end up searching for this again!)

Resources