Announcement

Collapse
No announcement yet.

Is it possible to show number of products per section / sub-section

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

    #16
    it would be really useful to have a looping structure that TRULY loops down the PRODUCTS ONLY.
    we make extensive use of fragments to apply formatting to bits of products (technical, features, etc) and have struggled to come up with a solution.

    perhaps thats one for the wish-list/essential bits of code from actinic towers

    Comment


      #17
      Separating the way fragments are 'managed' as 'products' I think is the key.

      Comment


        #18
        Sorted!

        Thanks Norman, that's fab! Looks just perfect, we're really pleased. Feel free to delete the other version as I'm sure others will want to add this little feature too.

        Anyway, thank you for your time - and brain!

        Kindest regards,

        Amy

        musthave : the natural skincare store
        http://www.musthave.co.uk

        Comment


          #19
          Separating the way fragments are 'managed' as 'products' I think is the key.
          don't disagree with that

          Comment


            #20
            Originally posted by NormanRouxel
            It turns out that there's an Actinic Variable ListCount that will do this and is a lot simpler.

            So remove the above patch and instead do this (it also puts the info at the top of the page as per your original request).

            Click on a Product in Design View and use the up arrow to get to the Product List layout (named something like Product List With Horizontal Dividers)

            Click the Click here to edit list layout settings and put the following at the beginning of Start of List.
            Code:
            <actinic:variable name="ListCount" /> products on this page
            Could this figure be added to the end of a Section Title?
            Football Heaven

            For all kinds of football souvenirs and memorabilia.

            Comment


              #21
              ...mmmm... sorry to resurrect an old thread.

              I'm still looking for a way of showing the number of products at the end of a section title in navigation menus.

              There were issues with ListCount not working correctly. Having looked at the release notes for v9 - and tested it on 9.0.2 and 9.0.3 - I think that these issues have not been resolved.

              Has anyone managed to automatically show the product count against a section in navigation? Or, is it possible to use PHP to populate the value of a UDV?

              (I realise that everytime there are products added or removed then all pages will need to be uploaded again.)
              Elysium:Online - Official Accredited SellerDeck Partner
              SellerDeck Design, Build, Hosting & Promotion
              Based in rural Northants

              Comment


                #22
                ListCount is still untrustworthy. What would work would be this. Assume you're in a bit of Section code
                Code:
                <actinic:block type="ProductList"><actinic:block php="true">$itemcount = <actinic:variable name="ListIndex" />;</actinic:block></actinic:block>
                <actinic:block php="true">
                  echo $itemcount;
                </actinic:block>
                This could be computationally expensive if you have lots of products in lots of sections.
                Norman - www.drillpine.biz
                Edinburgh, U K / Bitez, Turkey

                Comment


                  #23
                  Hi Norman

                  Not quite what I was aiming for, although I did try it and found that ListIndex is unreliable. I wanted the product count to appear in the section navigation bar. I'm beginning to realise that it's not possible.

                  So I've changed the requirement - to display the product count for sub-sections on the section link page.

                  Using the Section Link Within Box layout, I've amended the code around the display of the Section Name :

                  Code:
                     <actinic:block php="true">$productsonpage = 0;</actinic:block>
                     <actinic:block type="ProductList">
                      <actinic:block php="true">
                       $productsonpage++;
                      </actinic:block>
                     </actinic:block>
                     <span class="boxheading">
                        <a href="<actinic:block if="%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20AND%0d%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e" >
                  <actinic:variablename="SectionPageName" /></actinic:block>
                  <actinic:block if="%28%3cactinic%3avariable%20name%3d%22IsLoginPageSuppressed%22%20%2f%3e%20%3d%3d%20false%29%20OR%0d%28%3cactinic%3avariable%20name%3d%22UnregCustomersAreNotAllowed%22%20%2f%3e%20%3d%3d%20false%29" ><actinic:variable name="SectionURL" /></actinic:block>" class="boxlink">
                  <actinic:variable name="SectionName" /> 
                  <actinic:block php="true">echo "[";echo $productsonpage;echo "]";</actinic:block>
                  </a>
                  </span>
                  This works except for 2 problems :

                  1. I need to weed out the fragments from the product count
                  2. If there is only one product in the subsection then it is reported as 2. Every other value seems to report correctly


                  I'm sure I'll figure out the first one but I have no idea why the second one is occurring. I've done all the usual debug activities such as putting display statements in to see what's going on and they all appear fine - it's just that $productsonpage doesn't want to be displayed as a "1"!!!


                  ( also, I've just realised that this is an old V8 thread and I'm using 9.0.x!! )
                  Elysium:Online - Official Accredited SellerDeck Partner
                  SellerDeck Design, Build, Hosting & Promotion
                  Based in rural Northants

                  Comment


                    #24
                    I'd recommend putting the lump
                    Code:
                       <actinic:block type="ProductList">
                        <actinic:block php="true">
                         $productsonpage++;
                        </actinic:block>
                       </actinic:block>
                    All onto one long line, e.g.
                    Code:
                    <actinic:block type="ProductList"><actinic:block php="true">$productsonpage++;</actinic:block></actinic:block>
                    as you'll be generating a lot of spurious line breaks and spaces otherwise.
                    Norman - www.drillpine.biz
                    Edinburgh, U K / Bitez, Turkey

                    Comment


                      #25
                      And how to count only the products and not the fragments.

                      To do this replace
                      Code:
                      $productsonpage++;
                      with
                      Code:
                      if ( '<actinic:variable name="ProductName" encoding="perl" selectable="false" />' ) $productsonpage++;
                      Norman - www.drillpine.biz
                      Edinburgh, U K / Bitez, Turkey

                      Comment


                        #26
                        A star as always, Norman.

                        thanks for this - the advice to put the code on one line (apart from not generating excessive line breaks etc) fixed the problem with 1 product being reported as 2!!!!
                        Elysium:Online - Official Accredited SellerDeck Partner
                        SellerDeck Design, Build, Hosting & Promotion
                        Based in rural Northants

                        Comment


                          #27
                          Andrew,

                          I've reported that bizarre PHP execution as a bug. It happens on V8 and V9.
                          Norman - www.drillpine.biz
                          Edinburgh, U K / Bitez, Turkey

                          Comment


                            #28
                            I'v had a brief skit over this thread, and I rememberd some code i knocked together recently:
                            Code:
                            <actinic:block php="true" >
                            /***************************************************************
                            *
                            * MakeNav -
                            * PLEASE TEST BEFORE PRODCTION USE
                            * @author Gabriel Crowe 12:47 01 November 2007
                            *
                            * usage example:
                            * MakeNav($sectid,$recursedepth,$prestyle,$thissect)
                            ***************************************************************/
                            
                            if (!function_exists('GetParentSections')) {
                            function GetParentSections($connect,$sectref)
                                {
                            
                                    $query = "SELECT [Section Text], [nParentSectionID], [nSectionID] FROM [Catalog Section] WHERE [nSectionID] LIKE '".$sectref."'";
                                    $result = odbc_exec($connect, $query);
                                    $returnstring="";
                            		
                            
                                    while(odbc_fetch_row($result)){
                                    
                                        $SectionText =  odbc_result($result, 1);
                                        $nParentSectionID = odbc_result($result, 2);
                                        $nSectionID = odbc_result($result, 3);
                                        
                                        if ($nSectionID!=0) {$returnstring=GetParentSections($connect,$nParentSectionID).$nSectionID."|";}
                            
                                    }
                                    odbc_free_result($result);
                                    //odbc_close($connect);
                                return $returnstring;
                            }
                            }
                            
                            if (!function_exists('GetParentSectionsWrapper')) {
                            function GetParentSectionsWrapper($sectid) {
                                $connect = odbc_pconnect("ActinicCatalog9","","", SQL_CUR_USE_ODBC);
                                $resultage = GetParentSections($connect,$sectid);
                                odbc_close_all();    
                                return $resultage;
                            }
                            }
                            
                            if (!function_exists('DownTreeSectArrayWrapper')) {
                            function DownTreeSectArrayWrapper($nParentSectionID) {
                                $connect = odbc_pconnect("ActinicCatalog9","","", SQL_CUR_USE_ODBC);
                                $SectArray=$nParentSectionID."|";
                                $resultage = DownTreeSectArray($connect,$nParentSectionID,$SectArray);
                                odbc_close_all();    
                                return $resultage;
                            }
                            }
                            
                            if (!function_exists('DownTreeSectArray')) {
                            function DownTreeSectArray($connect,$nParentSectionID,$SectArray)
                                {
                                    $query = "SELECT [nSectionID] FROM [Catalog Section] WHERE [nParentSectionID] LIKE '".$nParentSectionID."'";
                                    $result = odbc_exec($connect, $query);
                                    $numrows = useful_odbc_num_rows($result);
                                    if ($numrows>0) {
                            			  while(odbc_fetch_row($result)){
                            					$nSectionID =  odbc_result($result, 1);
                            						$SectArray = $SectArray . $nSectionID . "|";
                            						$SectArray = DownTreeSectArray($connect,$nSectionID,$SectArray);
                            			  }
                                    }
                                    odbc_free_result($result);
                                return $SectArray;
                                }
                            }
                            
                            if (!function_exists('CountProductsInSectionArray')) {
                            function CountProductsInSectionArray($SectArray) {
                            $connect = odbc_pconnect("ActinicCatalog9","","", SQL_CUR_USE_ODBC);
                            
                            $SectArray = substr_replace($SectArray ,"",-1);
                            $aSectArray = explode("|",$SectArray);
                            
                            $tempSQL = "SELECT [Product Reference] FROM [product] WHERE bSuppressHtml=0 AND (";
                            foreach ($aSectArray as $value) {
                                $tempSQL=$tempSQL." [nParentSectionID]={$value} OR";
                            }
                            $tempSQL = substr_replace($tempSQL ,"",-3);
                            $tempSQL=$tempSQL.")";
                            
                                    $query = $tempSQL;
                            			$result = odbc_exec($connect, $query);
                            			$numrows = useful_odbc_num_rows($result);
                                    odbc_free_result($result);
                                    odbc_close_all(); 
                            
                            return $numrows;
                            }
                            }
                            
                            if (!function_exists('useful_odbc_num_rows')) {
                            function useful_odbc_num_rows($result){
                            
                               $num_rows=0;
                            
                               while($temp = odbc_fetch_into($result, &$counter))
                            
                               {
                                   $num_rows++;
                               }
                            
                            @odbc_fetch_row($result, 0);   // reset cursor
                            
                               return $num_rows;
                            }
                            }
                            
                            if (!function_exists('SectionList')) {
                            function SectionList($connect,$sectid,$recursedepth,$rendermode,$thispatharr,$stylecounter,$respect) {
                            
                                $recursedepth=$recursedepth-1;
                                $stylecounter=$stylecounter+1;
                                if($respect==true) { 
                            		$query = "SELECT [sPageName], [Section text], [nSectionID] FROM [Catalog Section] WHERE [nParentSectionID]=".$sectid." AND [bHideOnWebSite]=0 AND [bIncludeToSiteMap]=1 ORDER BY [Catalogue Section Sequence] ASC";
                                } else {
                            		$query = "SELECT [sPageName], [Section text], [nSectionID] FROM [Catalog Section] WHERE [nParentSectionID]=".$sectid." AND [bHideOnWebSite]=0 ORDER BY [Catalogue Section Sequence] ASC";
                            	 }
                            	 $result = odbc_exec($connect, $query);
                                $numrows = useful_odbc_num_rows($result);
                            
                                if ($numrows!=0 && $stylecounter!=1) { echo "\n\n<ul class=\"ul".$stylecounter."\">"; }
                                if ($numrows!=0 && $stylecounter==1) { echo "\n\n<ul class=\"menulist\" id=\"listMenuRoot\">";}    
                                
                                    while(odbc_fetch_row($result)){
                                    
                                        $sPageName = odbc_result($result, 1);
                                        $Sectiontext = odbc_result($result, 2);
                                        $nSectionID = odbc_result($result, 3);
                            
                                            $thisstyle="";
                                            $expandthis=false;
                                            foreach ($thispatharr as $value) {
                                                if ($value==$nSectionID) {
                                                $thisstyle="_selected";
                                                $expandthis=true;
                                                }
                            							
                                            }
                                            $linkitem="<a href=\"#link#\" class=\"link".$stylecounter.$thisstyle."\">";
                            
                                        echo "\t<li class=\"li".$stylecounter.$thisstyle."\">";
                                        echo str_replace("#link#",$sPageName,$linkitem);
                                        echo trim($Sectiontext);
                                        echo "</a>";
                                            //recurse
                                            if ($rendermode == 1) { $expandthis=true; }
                                            if ($recursedepth>=1 and $expandthis==true){
                                                    SectionList($connect,$nSectionID,$recursedepth,$rendermode,$thispatharr,$stylecounter,$respect);
                                                }
                                        echo "</li>\n";
                                    }
                                if ($numrows!=0) { echo "</ul>\n\n"; }
                            odbc_free_result($result);
                            }        
                            }
                            
                            if (!function_exists('MakeNav')) {
                            function MakeNav($sectid,$recursedepth,$rendermode,$thissect,$respect=true) {
                            
                                $thispath = GetParentSectionsWrapper($thissect);
                                $thispatharr = explode("|",$thispath);
                                //sPagetitle, sPageName, sMetaKeywords, sMetaDescription, sSectionImageFile, sSectionDescription, sSectionText
                                $connect = odbc_pconnect("ActinicCatalog9","","", SQL_CUR_USE_ODBC);
                                    SectionList($connect,$sectid,$recursedepth,$rendermode,$thispatharr,0,$respect);
                                odbc_close_all();    
                            
                                $connect = null;    
                            }
                            }
                            
                            
                            
                            /***************************************************************
                             *
                             * Ref2file - Use Actinic's pwn database, to convert a prod ref, to a filename
                             *
                             * @param int $ref the product reference. 
                             * @author Gabriel Crowe 18:04 08 September 2007
                             *
                             ***************************************************************/
                            if (!function_exists('GetSectFileName')) {
                            function GetSectFileName($sectref)
                            	{
                            		$connect = odbc_connect("ActinicCatalog9","","");
                            		$query = "SELECT [sPageName] FROM [Catalog Section] WHERE [nSectionID]=".$sectref."";
                            		$result = odbc_exec($connect, $query);
                            
                            		while(odbc_fetch_row($result)){
                            			//$name = odbc_result($result, 2);
                            			$url = odbc_result($result, 1);  
                            		}
                            		odbc_close($connect);
                            			return $url;
                            	}
                            }
                            
                            if (!function_exists('GetSectName')) {
                            function GetSectName($sectref)
                            	{
                            		$connect = odbc_connect("ActinicCatalog9","","");
                            		$query = "SELECT [Section Text] FROM [Catalog Section] WHERE [nSectionID]=".$sectref."";
                            		$result = odbc_exec($connect, $query);
                            
                            		while(odbc_fetch_row($result)){
                            			//$name = odbc_result($result, 2);
                            			$SectionText = odbc_result($result, 1);  
                            		}
                            		odbc_close($connect);
                            			return $SectionText;
                            	}
                            }
                            
                            if (!function_exists('GetProdParent')) {
                            function GetProdParent($prodrefs)
                            	{
                            	$prodrefs = str_replace("{","",$prodrefs);
                            	$prodrefs = str_replace("}","",$prodrefs);
                            		$connect = odbc_connect("ActinicCatalog9","","");
                            		$query = "SELECT [nParentSectionID] FROM [product] WHERE [Product Reference]='".$prodrefs."'";
                            		$result = odbc_exec($connect, $query);
                            		
                            		while(odbc_fetch_row($result)){
                            			$parentid = odbc_result($result, 1);
                            		}
                            		odbc_close($connect);
                            			return $parentid;
                            		}
                            }
                            			
                            if (!function_exists('Ref2file')) {
                            function Ref2file($ref) {
                            return GetSectFileName(GetProdParent($ref));
                            }	
                            }
                            
                            </actinic:block>
                            This is my PHP navigation, with some new support features.

                            namely, the ability to count products, downtree of a section ID.

                            Usage in Actinic template:
                            Code:
                            (<actinic:block php="true" selectable="false" >
                            echo CountProductsInSectionArray(DownTreeSectArrayWrapper('<actinic:variable name="SectionID" encoding="perl" />'));
                            </actinic:block> Products)
                            Paste this, in a location that has 'SectionID' and include the first snippet in the header of your page.

                            The code loops through the current section and any sub sections, counting the products there. It adds them up and displays them.

                            As you navigate deeper into your catalog, the number will obviously dwindle. since less products are below the currently selected section. The script knows not to count hidden products, but cannot know if the parent section is hidden. please, if you want an accurate count, then hide the child product, when you hide the section that its in.

                            No thought was made towards cpu usage and database thrashing but it was fast in my tests, so this is:

                            UNTESTED

                            Dont expect the universe from this code, please. Any php coders out there, please forgive my kludgy code. I had to do several creepy workarounds, for the unsane amount of odd actinic behaviours.

                            Comment


                              #29
                              also:
                              http://www.interact-studio.co.uk/acatalog/Products.html

                              example here, in action, not a big shop, but it shows the right stuff.

                              Comment


                                #30
                                Originally posted by drounding View Post
                                ...all the store pages will have to be uploaded as well to reflect that change, which may not be desirable if you have a large store.
                                btw: this is exactly what would happen if you used my code here, please beware.

                                Comment

                                Working...
                                X