Online stores can be overwhelming to maintain. LemonStand Cart requires that you set related products on each of your products. Clients with large numbers of products prefer automation where possible.

If the client does not specify related products, the below partial code will show related products from the database. The script grabs products from parent categories to ensure that the output remains relevant.
Partial Code
The partial is formatted for a theme based on Foundation 3 responsive framework. You may have to tweak the output to work for your LemonStand site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
<?php /** * Automatic Related Products * © Copyright 2013, Christopher Stevens * * * Variables: * $auto = Activates automatic related products for a product without related products set. * $limit = Limits the list length. Default is unlimited, 0 will set unlimited. * $levels = Limits the parent category levels to get products from. Default is unlimited, 0 will set unlimited. * * To use this, just render the partial on a page or partial that creates a product page, $product is required. * Example: $this->render_partial('shop:related_products', array('auto'=>true,'limit'=>4)); * */ $related_products = $product->list_related_products()->find_all(); if (!isset($auto) || !is_bool($auto)) $auto = false; if (!isset($limit) || !is_int($limit) || $limit < 1) $limit = 256; if (!isset($levels) || !is_int($levels)) $levels = 256; if (!count($related_products) && $auto) { $categories = $product->category_list->get_parents(true); // Find all parent categories. foreach (array_reverse($categories) as $key=>$category) { $related_products = $category->list_products(array('sorting'=>array('rand()')))->where('id != ?', $product->id)->limit($limit)->find_all(); if (count($related_products)) { $display_products = $related_products; if ($key + 1 == $levels) break; // Break the loop at chosen level. } } } elseif (count($related_products)) { foreach ($related_products as $key=>$product) { if ($key < $limit) $display_products = $related_products; } } ?> <?php if (isset($display_products)): ?> <section class="related-products bottom block"> <div class="row"> <div class="twelve columns"> <div class="title-block"> <h5 class="display">Related Products</h5> </div> </div> </div> <div class="row"> <?php $this->render_partial('shop:product_list', array( 'products' => $display_products, 'class' => 'no-border three' )); ?> </div> </section> <?php endif; ?> |