NEW ARRIVALS COLLECTION

I have asked this question before, and have read quite a bit on it and understand there is a way of coding a new arrivals collection with a date added from tag 

I need to have a "new arrivals" collection which new items automatically go into and after xxx weeks/days , will come out of that collection

I see the following shopify sites have it :

So there MUST be a way to do it - just wish I could work this out :) 

And have also seen this coding for using to add a "new arrivals" icon - so I am thinking that the same idea could be applied to a collection?

{% assign date_published = product.published_at | date:'%s' %}
{% assign date_now = 'now' | date:'%s' %}
{% assign date_difference = date_now | minus: date_published %}

{% if date_difference < 2592000 %}<span class="badge-fresh">FRESH</span>{% endif %}

 

0 Likes
Tourist
7 0 1

+1

I am also looking to create a new arrivals collection, such that it only adds products up to 30 days. Which means as time moves this collection keep getting updated.

1 Like
Shopify Expert
2652 60 649

I'd be looking to create a "New Arrivals" collection to inlclude all products with sort by date, newest to oldest.

Then, reuse that piece of code to modify the collection template along the following lines:

{% for product in collection.products %}
  {% include 'product-grid-item' %}

  {% if collection.title == 'New Arrivals' %}
    {% assign date_published = product.published_at | date:'%s' %}
    {% assign date_now = 'now' | date:'%s' %}
    {% assign date_difference = date_now | minus: date_published %}

    {% if date_difference > 2592000 %}
       {% break %}
    {% endif %}
  {% endif %}
{% endfor %}

This code will basically stop outputting products if current product is older than 30 days (and with that sort order it means that all the following products are older too).

While it is not a true "New arrivals" collection, the site visitors will only see the products published within last 30 days.

((Note however, that since Shopify uses server-side caching,  time-based things done in liquid are not  very precise ))

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes
Shopify Expert
9800 91 1553

I know that Tim mentioned it, but it's worth reiterating.

The concept on "now" won't be what you expect since the page is cached. The now time will be whatever the time was when the cache was created, and not the current time. If you're using {{ now }} be sure to log out of the Admin (or use private browsing modes) to see what a customer would in terms of cache.

The difference between the current time and the cached now values can be many hours.

★ Winning Partner of the Build a Business competition. ★ http://freakdesign.com.au
1 Like

Thanks guys! 

I have tried this, however it doesnt seem to work the way I want it to :(

This is my collection.new.arrivals code 

{% paginate collection.products by 48 %}

<h1 class="desktop-6 desktop-push-3 tablet-3 mobile-3">
  {% if collection.handle == 'all' %}{{ 'collections.general.all_products' | t }}{% else %}{{ collection.title }}{% endif %}
</h1>
{% for product in collection.products %}
  {% if collection.title == 'New Arrivals' %}
    {% assign date_published = product.published_at | date:'%s' %}
    {% assign date_now = 'now' | date:'%s' %}
    {% assign date_difference = date_now | minus: date_published %}

    {% if date_difference > 2592000 %}
       {% break %}
    {% endif %}
  {% endif %}
{% endfor %}


<div class="clear"></div>


<!-- Start Sidebar -->
{% if settings.collection_sidebar %}
{% include 'collection-sidebar' %}
{% endif %}
<!-- End Sidebar -->


<div class="{% if settings.collection_sidebar %}desktop-9 tablet-6{% else %}desktop-12 tablet-6{% endif %} mobile-3">

  {% if settings.collection_sidebar == false %}
  {% if settings.filters %}
  <div id="full-width-filter" class="desktop-12 tablet-6 mobile-3">
    {% include 'filter' %}
  </div>
  {% endif %}  
  {% endif %}

  <div id="product-loop">

    {% for product in collection.products %}{% if product.template_suffix != 'beans' %}
    {% assign products-per-row = settings.products-per-row %}
    <div id="product-listing-{{ product.id }}" class="product-index {% if products-per-row == "6" %}desktop-2{% cycle ' first', '', '', '', '', ' last' %}{% elsif products-per-row == "4" %}desktop-3{% cycle ' first', '', '', ' last' %}{% elsif products-per-row == "3" %}desktop-4{% cycle ' first', '', ' last' %}{% elsif products-per-row == "5" %}desktop-fifth{% cycle ' first', '', '', '', ' last' %}{% elsif products-per-row == "2" %}desktop-6{% cycle ' first', ' last' %}{% endif %} tablet-half mobile-half" data-alpha="{{ product.title }}" data-price="{{ product.price }}">           
      {% include 'product-listing' %}
    </div>

    {% endif %}{% endfor %} 

  </div>
</div>


{% include 'pagination' %}

{% endpaginate %}

<div id="collection-description" class="desktop-12 tablet-6 mobile-3">
  <div class="rte">
    {{ collection.description | remove: "[banner]" }}
  </div>
</div>

 

0 Likes
Shopify Expert
2652 60 649

Ah Susan,

since I have no acces to your theme's code that snippet was just an idea. What you should do is to remove the code you pasted under </h1> tag,  locate this part of the code:

 {% include 'product-listing' %}
    </div>

and paste this part of my snippet right below it:

{% if collection.title == 'New Arrivals' %}
    {% assign date_published = product.published_at | date:'%s' %}
    {% assign date_now = 'now' | date:'%s' %}
    {% assign date_difference = date_now | minus: date_published %}

    {% if date_difference > 2592000 %}
       {% break %}
    {% endif %}
{% endif %}

And you do not have to create and assign a special template for New Arrivals collection -- the code will behave as before for other collections (but it's good to have a backup).

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes

Thanks, I tried this however it resulted in showing 18 pages but 1 product per page? 

My template is "Testement" 

0 Likes
Shopify Expert
2652 60 649

It means the code works, but looks like I've forgotten about the pagination.

I have a dirty hack to overcome it though -- you should paste this modified code right above the {% include 'product-listing' %} line (instead of the old one):

{% if collection.title == 'New Arrivals' %}
    {% assign date_published = product.published_at | date:'%s' %}
    {% assign date_now = 'now' | date:'%s' %}
    {% assign date_difference = date_now | minus: date_published %}

    {% if date_difference > 2592000 %}
    	<style>
          .pagination, #pagination { display:none;}
        </style>
       {% break %}
    {% endif %}
{% endif %}

What it will do is to introduce a <style> clause to hide the pagination  navigation block as soon as you reach the product older then month, so your visitors will be unable to browse past that point.

One can use this <style> block instead to hide only navigation further.

<style>
		#pagination>span.current ~ a, 
        .pagination .current~span {display: none;}
</style>

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes

Thanks for all your help - however it still happened :( It shows 18 pages and only 1 product per page?

0 Likes
Shopify Expert
2652 60 649

Well, it means either you have only one product younger than a month, or you've placed the code in a wrong place (or both :). It's hard to tell without seeng your code, especially since testament is not a free theme.

 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!
0 Likes