Forum

Thread tagged as: Question, Shop, Runway

View All using URL parameter

Last one for today. I now have the following on my products list page:

if (perch_get('price')) {
  perch_shop_products([
  'template' => 'products/paginated-list.html',
  'paginate'=>true,
  'count'=>18,
  'sort'=>'price',
  'sort-order'=>perch_get('price'),
  'sort-type'=>'numeric',
  'category' => 'products/' . perch_get('family'),
]);
}

else {
  perch_shop_products([
  'template' => 'products/paginated-list.html',
  'paginate'=>true,
  'count'=>18,
  'sort'=>'priority',
  'sort-order'=>'ASC',
  'sort-type'=>'numeric',
  'category' => 'products/' . perch_get('family'),
]);
}

Using your method of adding a hidden input on the form, I can now output another parameter called view. This gives a URL like:

https://mysite.com/?family=something&price=asc&view=all

When view is set to all, I need to switch pagination to false, and I guess remove the count too. What is the best way of going about this? I can do it but with loads of elseifs and && which seems a bit clumsy

Mike Harrison

Mike Harrison 37 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to do:

'paginate' => !(perch_get('view')=='all'),

Hi Drew,

Thanks for the pointer. I have it working now, though it could possibly be a bit cleaner. Do I need to do the variable setting or is there a better way?

if ((perch_get('view'))=='all') {
  $count = null;
}

else {
  $count = 18;
}

if (perch_get('price')) {
  perch_shop_products([
  'template' => 'products/paginated-list.html',
  'paginate' => !(perch_get('view')=='all'),
  'count'=>$count,
  'sort'=>'price',
  'sort-order'=>perch_get('price'),
  'sort-type'=>'numeric',
  'category' => 'products/' . perch_get('family'),
]);
}

else {
  perch_shop_products([
  'template' => 'products/paginated-list.html',
  'paginate' => !(perch_get('view')=='all'),
  'count'=>$count,
  'sort'=>'priority',
  'sort-order'=>'ASC',
  'sort-type'=>'numeric',
  'category' => 'products/' . perch_get('family'),
]);
}
Drew McLellan

Drew McLellan 2638 points
Perch Support

If it's working then I think you're probably good.