Announcement

Collapse
No announcement yet.

How do I get a list of all products into a page.

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

    How do I get a list of all products into a page.

    Hi - I am using v9.0.3

    I want to create a list of 4 products similar to a best sellers list, but to populate it with products randomly chosen from the full product listing.

    I believe I can handle the PHP side of what I want to do but I can't see how to get a full listing of product names, their corresponding URL's and the product price.

    Are there any variables I can use to get this information?

    If not, can I use a SQL statement to access the MS Access database directly?
    Regards
    David

    #2
    Use a Block and choose the productlist.

    Comment


      #3
      Untested:
      Code:
      <actinic:block type="EntireSectionList">
        <actinic:block type="ProductList">
          <actinic:block php="true">
            if ( TEST FOR RANDOM )
              {
               $myhtml = <<<ENDOFCODE
      PRODUCT LAYOUT BITS AND VARIABLES HERE
      ENDOFCODE;
               echo $myhtml;
              }
          </actinic:block>
        </actinic:block>
      </actinic:block>
      Note that this will be very inefficient if you intend to display this on every page.

      As for which Variables to use look inside an existing product layout. Or see Help / Variable Reference Guide.
      Norman - www.drillpine.biz
      Edinburgh, U K / Bitez, Turkey

      Comment


        #4
        If you use Fragments in your product pages, then they get included in ProductList. Variable ProductType (see the help) can be used to test for this.
        Norman - www.drillpine.biz
        Edinburgh, U K / Bitez, Turkey

        Comment


          #5
          Here's a better way.

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

          Then later display 4 at random.
          Code:
          <!-- 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 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.
          Norman - www.drillpine.biz
          Edinburgh, U K / Bitez, Turkey

          Comment


            #6
            Cheers Lee - exactly what I wanted.
            Regards
            David

            Comment


              #7
              Cheers Norman - I will take a look at that also
              Regards
              David

              Comment


                #8
                I just amended my post #6 to display using the Mini Best Seller layout. Also tested it OK.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #9
                  Thanks for that Norman - it works a treat !!!
                  Regards
                  David

                  Comment


                    #10
                    I've done a bugfix. The bit in red below was needed.

                    <actinic:variable name="BestSellerItem" value="Mini Best Seller Layout" encoding="perl" />
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment


                      #11
                      Yeah - I must have corrected that myself when I was going along - I remember getting some script errors and checking that all my variables were perl encoded.
                      Regards
                      David

                      Comment


                        #12
                        Hi - I do have one further issue with this.

                        Unless I click on the homepage within Actinic the initial script will not run and hence I get my product pages filled with "Undefined Variables" messages.

                        Is there any where else I can place the code so that it runs every time I open Actinic?
                        Regards
                        David

                        Comment


                          #13
                          That's mainly a cosmetic issue. When you Update or Refresh, the code should run properly.

                          You could try putting the first block on every page but with another Actinic Condition around it:

                          IsPreviewMode OR (PageType == "Brochure")

                          so the code will run when Previewing and on all brochure pages.
                          Norman - www.drillpine.biz
                          Edinburgh, U K / Bitez, Turkey

                          Comment


                            #14
                            Here's a better way. Use this for the first block. The code runs only on the Brochure pages, or if it's never run before.
                            Code:
                            <!-- Here we fill a PHP array with snippets of HTML from all products -->
                            <actinic:block php="true">
                            	if ( (! isset($allproducts)) || ('<actinic:variable name="PageType" encoding="perl" selectable="false" />' == 'Brochure') )
                            		{
                            		unset($allproducts);
                            		<actinic:block type="EntireSectionList">
                              			<actinic:block type="ProductList">
                                			if ( <actinic:variable name="ProductType" /> == 0 )
                                 				{
                                 				$allproducts[] = <<<ENDOFCODE
                            					<actinic:variable name="BestSellerItem" value="Mini Best Seller Layout" encoding="perl" />
                            ENDOFCODE;
                                 				}
                              			</actinic:block>
                            		</actinic:block>
                            		}
                            </actinic:block>
                            Norman - www.drillpine.biz
                            Edinburgh, U K / Bitez, Turkey

                            Comment


                              #15
                              Thanks again Norman - I've decided to leave as is. I was just a bit concerned as to whether it would upload correctly which it does.
                              Regards
                              David

                              Comment

                              Working...
                              X