Announcement

Collapse
No announcement yet.

How can I generate a random product list on my home page?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How can I generate a random product list on my home page?

    We first store the HTML of the Mini Best Seller layout from all products into an array.

    Then later display 4 at random.

    <!-- Here we fill a PHP array with snippets of HTML from all products -->
    <actinic:block php="true">unset($allproducts);</actinic:block>
    <actinic:block type="EntireSectionList">
    <actinic:block type="ProductList" php="true">
    if ( <actinic:variable name="ProductType" /> == 0 )
    {
    $allproducts[] = <<<ENDOFCODE
    <actinic:variable name="BestSellerItem" value="Mini Best Seller Layout" encoding="perl" />
    ENDOFCODE;
    }
    </actinic:block>
    </actinic:block>

    <!-- Here we output 4 random products -->
    <actinic:block php="true">
    for ( $i=1; $i<=4; $i++ )
    {
    echo '<br clear="all" />' . $allproducts[mt_rand(0, count($allproducts) - 1)];
    }
    </actinic:block>


    You could put the first bit (or all of it) into a layout that's processed only once (like Brochure Home page). The second snippet could be on every page as the PHP array should be populated then.

    Kindly provided by Norman Rouxel from Drillpine

    #2
    This continues to work very well (v16 now) but with large sites can significantly lengthen the time to take snapshots and for uploading the site.

    I have played around with the invariant property and this seems to work to speed upload and snapshot without hindering the generation process:

    Code:
    <actinic:block invariant="true" >
    <!-- Here we fill a PHP array with snippets of HTML from all products -->
    <actinic:block php="true">unset($allproducts);</actinic:block>
    <actinic:block type="EntireSectionList" >
    <actinic:block php="true" type="ProductList" >
    if ( <actinic:variable name="ProductType" /> == 0 )
    {
    $allproducts[] = <<<ENDOFCODE
    <actinic:variable encoding="perl" value="forMMII" name="BestSellerItem" />
    ENDOFCODE;
    }
    </actinic:block>
    </actinic:block>
    </actinic:block>
    An invariant block is wrapped around the whole expression.
    Site in question had some 2000 products and without the invariant block upload was 30mins coming down to five minutes with the block.

    Thanks to Norman
    Jonathan Chappell
    Website Designer
    SellerDeck Website Designer
    Actinic to SellerDeck upgrades
    Graphicz Limited - www.graphicz.co.uk

    Comment

    Working...
    X