Collection rules

Highlighted
Tourist
3 0 2
Why i show {{collection.rules}} i can see the rules, but can't acces it in liquid? I need rules to implement a development but shopify, but as always, shopify is difficult to extend and implement specific features.
1 Like
Highlighted

The collection object has the following attributes

 
There is no rules attribute inside collection object
CRO Expert at PageFly - Advanced Shopify Page Builder.
- PageFly Page Builder: Website | Facebook | LinkedIn | Group | Youtube
- [Tutorial] Get
more tips on using PageFly to soar sales this season
- [Master Guides]: Get Your Shopify Store Ready for Black Friday
0 Likes
Highlighted
Tourist
3 0 2

Yes, but if you show a json of object collection, you can view rules, anywhere if i need the rules can't acces it? .....

1 Like
Highlighted
Tourist
4 0 1

I too am having this same issue and would be happy about a solution / workaround. How do we get the "rules" array out of the "collection" object, that is output when calling {{ collection | json }} ? Thanks for any help.

0 Likes
Highlighted
Shopify Partner
399 30 51

@Simon_Brandt 

The collection object has the following attributes

There are no rules attribute inside the collection object.

When you use {{ collection | json }} then it will return JSON format data of that particular collection. 

Akshay Vaghasiya

Shopify Expert | Skype: akshayvaghasiya84
 - Like and Mark as an Accepted Solution if my reply helpful
 - Feel free to contact me on akshayvaghasiya84@gmail.com or akshayvaghasiya@lavitastic.com for any queries
 - Want to modify or custom changes on store hire me .
0 Likes
Highlighted
Tourist
4 0 1

Hey, Akshay,

Thanks but I actually looked at the documentation and are still not completely satisfied.

 

{{ collection | json }}

returns

{
   "id":174687682605,
   "handle":"black-pattern",
   "title":"Black Pattern",
   "updated_at":"2020-04-14T11:25:42+02:00",
   "body_html":"",
   "published_at":"2020-02-13T11:28:22+01:00",
   "sort_order":"best-selling",
   "template_suffix":"",
   "disjunctive":false,
   "rules":[
      {
         "column":"variant_title",
         "relation":"contains",
         "condition":"black"
      },
      {
         "column":"variant_title",
         "relation":"contains",
         "condition":"pattern"
      }
   ],
   "published_scope":"web"
}

in my case. While

{{ collection.rules | json }}

returns 

null

I could save the json string in a new variable but would need to parse out all (or most) of the " characters. So this would be a quite messy solution. The problem is that despite not being mentioned in the object documentation and accessing it directly does not work, the "rules" object is present in the template but can not be used. 

0 Likes
Highlighted
Shopify Partner
399 30 51

@Simon_Brandt 

Thank you for sharing the code with me. For your information, Shopify is not giving access to each and every code. Some part of JSON code is used for admin purpose that is not accessible in the frontend or inside theme liquid. However, you can use the below code sample as a supported Collection JSON and its value is accessible for all the places. I hope you got all the information.

{
 "collection":{
  "id":160379633735,
  "title":"collection name",
  "handle":"collection-handle",
  "description":"collection description",
  "published_at":"2020-04-17T05:45:28-04:00",
  "updated_at":"2020-04-17T05:46:06-04:00",
  "image":null,
  "products_count":13
 }
}

 

 

Akshay Vaghasiya

Shopify Expert | Skype: akshayvaghasiya84
 - Like and Mark as an Accepted Solution if my reply helpful
 - Feel free to contact me on akshayvaghasiya84@gmail.com or akshayvaghasiya@lavitastic.com for any queries
 - Want to modify or custom changes on store hire me .
0 Likes
Highlighted
Tourist
4 0 1

Hey Akshay,

 

having certain fields restricted to admin use sounds reasonable. I will try working around this.

 

Thanks for your answers.

0 Likes
Highlighted
Tourist
3 0 2

They don't give you access to rules but if it comes out in {{collection | json}} is stupid. You can always create a mapper by trying {{collection | json}} as a string. :(

0 Likes