Author Topic: SOLVED Displaying other fields in categoryChildlist.tpl.php  (Read 16698 times)

deanclarke55

  • Beginner
  • *
  • Posts: 16
Hi,

I am trying to display the category description in the categoryChildlist.tpl.php page - here is the code:-

<?php if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

$iCol = 1;
if( !isset( $categories_per_row )) {
   $categories_per_row = 3;
}
$cellwidth = intval( 100 / $categories_per_row );

if( empty( $categories )) {
   return; // Do nothing, if there are no child categories!
}
?>
<br/>
<table width="100%" cellspacing="0" cellpadding="0">
<?php
foreach( $categories as $category ) {
   if ($iCol == 1) { // this is an indicator wether a row needs to be opened or not
      echo "<tr>\n";
   }
   ?>
   
   
   <td align="center" width="<?php echo $cellwidth ?>%" >
      <br />
         <a title="<?php echo $category["category_name"] ?>" href="<?php $sess->purl(URL."index.php?option=com_virtuemart&amp;page=shop.browse&amp;category_id=".$category["category_id"]) ?>">
         <?php
         if ( $category["category_thumb_image"] ) {
            echo $category["category_name"];
            echo "<br />";
            echo ps_product::image_tag( $category["category_thumb_image"], "alt=\"".$category["category_name"]."\"", 0, "category");
            echo "<br /><br/>\n";
            echo $category["category_description"];
         }
         
         echo $category['number_of_products'];
         ?>
       </a><br/>
   </td>
   
   
   <?php
   // Do we need to close the current row now?
   if ($iCol == $categories_per_row) { // If the number of products per row has been reached
      echo "</tr>\n";
      $iCol = 1;
   }
   else {
      $iCol++;
   }
}
// Do we need a final closing row tag?
if (sizeof( $categories ) < $categories_per_row) {
   echo "</tr>\n";
}
?>
</table>

I have added the line in red.  I think it all points to which fields are being called - I only think the Category_name and Category_thumb_image fields are being called.

My question is how do I call more fields to be displayed?

Many Thanks.

flame_copper

  • Beginner
  • *
  • Posts: 7
Re: Displaying other fields in categoryChildlist.tpl.php
« Reply #1 on: July 27, 2008, 09:45:53 am »
hi there,if you were to print out the category array it won't even exist.

deanclarke55

  • Beginner
  • *
  • Posts: 16
Re: Displaying other fields in categoryChildlist.tpl.php
« Reply #2 on: July 27, 2008, 10:32:12 am »
So how would I add it to the category array?

deanclarke55

  • Beginner
  • *
  • Posts: 16
Please Please Please Help - 5th Post - No Reply
« Reply #3 on: July 29, 2008, 13:24:04 pm »
Hi,

I seem to be getting nowhere fast with this.  I need to display 2 additional fields that I have created in the database.  I have ammended the backend so that I can enter information into the 2 fields - now all I need to do is display the data from the fields in the category page.

The fields will not be included in the array for that page - where and how do I add the fields?

I have tracked down the page that I need to display the fields on which is categoryChildlist.tpl in the common folder.

I need to know one way of the other if this can be done!!  >:(

willowtree

  • Full Member
  • ***
  • Posts: 542
    • Willow Tree Crafts
Re: Please Please Please Help - 5th Post - No Reply
« Reply #4 on: July 29, 2008, 19:13:23 pm »
I'm sute it can be done, you'll need to find the query that pulls the data from the database and amend it to pull the data from your extra fields.

A more helpful title might get more responses, please describe your problem in the title.
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

deanclarke55

  • Beginner
  • *
  • Posts: 16
Re: Please Please Please Help - 5th Post - No Reply
« Reply #5 on: July 29, 2008, 19:37:48 pm »
Thanks for your reply.

I tried a more helpful title in my 4 previous posts - 0 responses.  You are the first to respond!

I guess I am trying to find out on which page the query on and where about on that page it is.  I will be able to take it from there.

willowtree

  • Full Member
  • ***
  • Posts: 542
    • Willow Tree Crafts
Re: Please Please Please Help - 5th Post - No Reply
« Reply #6 on: July 29, 2008, 20:01:15 pm »
I think you're in the wrong place, the tpl will only display data that is already there, the actual query is likey to be in a php file, can you post a link to the page where you want it to display.
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

willowtree

  • Full Member
  • ***
  • Posts: 542
    • Willow Tree Crafts
Re: Please Please Please Help - 5th Post - No Reply
« Reply #7 on: July 29, 2008, 20:03:23 pm »
I've just looked at your posts, and it looks like you've posted multiple times on this. It doesn't really help, for example, I've just looked at this thread, but I have no knowledge of your previous threads (apart from a moan) so I cannot use the information you have posted there to help solve it. Please don't cross-post as it only clutters the boards and makes it more difficult to help
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

deanclarke55

  • Beginner
  • *
  • Posts: 16
Re: Displaying other fields in categoryChildlist.tpl.php
« Reply #8 on: July 29, 2008, 21:10:58 pm »
Hi, Again thanks for the reply.

Here is the page where I am trying to display the extra fields:

http://www.cprv2.yclweb.co.uk/index.php?page=shop.browse&category_id=1&option=com_virtuemart&Itemid=64

You will see the Category page and the Category image underneath.  I want to display the 2 fields below the image.  A small description (basically 4 lines of text e.g 16 pages per minute, 200MHz CPU, 128MB Ram, Duplex Unit) and then a prices from field (which will just containg text along the lines of "Prices starting from £199.00").

Hope this makes sense.  Apologies for cross posting. :-[

willowtree

  • Full Member
  • ***
  • Posts: 542
    • Willow Tree Crafts
Re: Displaying other fields in categoryChildlist.tpl.php
« Reply #9 on: July 29, 2008, 21:44:47 pm »
in that case you'll need ot look in the shop.browse page, probably in administrator/componants/com_vm/html
Please add your VM and Joomla Version to your signature to make it easier to help you:

Most of my code posted in the forum is for VirtueMart 1.0  -  not for 1.1

deanclarke55

  • Beginner
  • *
  • Posts: 16
Re: Displaying other fields in categoryChildlist.tpl.php
« Reply #10 on: July 29, 2008, 22:22:09 pm »
Hmm - I thought I would be able to figure out where to mod the page, any ideas??

Is it a mod to this page? - or is it a mod to an include file which is called by this page?

akerman

  • Jr. Member
  • **
  • Posts: 325
  • Knowledge weighs Nothing!
    • STOLT/AKERMAN
Re: Displaying other fields in categoryChildlist.tpl.php
« Reply #11 on: July 31, 2008, 18:44:15 pm »
Hi there, 'deanclarke55'!  :)

I think we have something in common; the search for the holy code!  ;)

I think I've managed what you initially asked in this thread:
"To place 'category_description' into the category childlist display", a file also known as 'categoryCildlist.tpl.php'

------------------------------------------------------------------------------------------
Here's how:

First add the following lines in 'ps_product_category.php' in /administrator/components/com_virtuemart/classes/..' (in about line 904 -> ff)

   /**
    * creates a bulleted of the childen of this category if they exist
    * @author pablo
    * @param int $category_id
    * @return string The HTML code
    */
   function get_child_list($category_id) {
      global $sess, $ps_product, $VM_LANG;
      $ps_vendor_id = $_SESSION["ps_vendor_id"];
      $db = new ps_DB;
      $childs = array();
      
      $q = "SELECT category_id, category_thumb_image, category_description, category_child_id,category_name FROM #__{vm}_category,#__{vm}_category_xref ";
      $q .= "WHERE #__{vm}_category_xref.category_parent_id='$category_id' ";
      $q .= "AND #__{vm}_category.category_id=#__{vm}_category_xref.category_child_id ";
      $q .= "AND #__{vm}_category.vendor_id='$ps_vendor_id' ";
      $q .= "AND #__{vm}_category.category_publish='Y' ";
      $q .= "ORDER BY #__{vm}_category.list_order, #__{vm}_category.category_name ASC";
      $db->setQuery($q);
      $db->query();

      while( $db->next_record() ) {
         $childs[] = array (
                     'category_name' =>  $db->f("category_name"),
                     'category_id' => $db->f("category_id"),
                     'category_thumb_image' => $db->f("category_thumb_image"),
                     'category_description' => $db->f("category_description"),
                     'number_of_products' => ps_product_category::products_in_category( $db->f("category_id")),
                  );
      }
      return $childs;
   }
--------------------------------------------------------------------------------

Then go to 'categoryCildlist.tpl.php' in /components/com_virtuemart/themes/your_theme/templates/common/..' (Yes, I know you know where it is... but hey it's for everybody... ;) )

Add the following. PS. You have to experiment a little with placement of the code since I just placed it under the category picture. (Putting it inside <a> makes it linkable).

   <td align="left" valign="top" width="<?php echo $cellwidth ?>%" >
      <br />
         <a title="<?php echo $category["category_name"] ?>" href="<?php $sess->purl(URL."index.php?option=com_virtuemart&amp;page=shop.browse&amp;category_id=".$category["category_id"]) ?>">
         <?php
         echo $category["category_name"];
         echo $category['number_of_products']. "<br />\n";
         if ( $category["category_thumb_image"] ) {
            echo ps_product::image_tag( $category["category_thumb_image"], "alt=\"".$category["category_name"]."\"", 0, "category");
 
         echo "<br />\n";
         }
         ?>
   </a>
         <?php echo $category["category_description"]; ?>         

       <br/>
   </td>

------------------------------------ E N D  C O D E ---------------------------------

So, lesson learned: Do not call upon arrays from within templates, utilize the code already there, in the PHP for each part of the shop/cart. Kind of logical, but hey, it took me a good while to find the right place...  :D   


Now I'm off to hunt for the category image to show up in its category page as well!
(But that's another thread altogether...) http://forum.virtuemart.net/index.php?topic=43800.0

Good luck!


PS If you're happy with a solution, go to your first post (if you started it) in the thread, and set icon 'Solved' and pretext in 'Subject' to "Solved". It helps us to find solutions quicker. Thanx!  ;)


Regards
Akerman

 
http://STOLT-AKERMAN.com - Web & Design agency. Spemildt in e-shop, ecommerce and marketing.
http://InfoClip.se - Swedish Antique & Used Books & Art Shop.
http://AkermansCove - Personal Portfolio
Ubuntu LAMP / Joomla 1.5.22 / VM 1.1.6 / JoomFish Contributor / Developer / Designer

deanclarke55

  • Beginner
  • *
  • Posts: 16
Re: Displaying other fields in categoryChildlist.tpl.php
« Reply #12 on: August 02, 2008, 12:59:08 pm »
Oh I thought this was gonna be it, the answer to all my VM prayers, alas no...I did everything suggested but no output on the category page.

Any other suggestions.  If you need to see my code I can supply.

Cheers.

deanclarke55

  • Beginner
  • *
  • Posts: 16
Re: Displaying other fields in categoryChildlist.tpl.php
« Reply #13 on: August 02, 2008, 13:19:12 pm »
ignore me - it worked a dream.  Very happy - think ill go and have a cherry scone to celebrate.

Matt Noyes

  • Beginner
  • *
  • Posts: 5
Re: SOLVED Displaying other fields in categoryChildlist.tpl.php
« Reply #14 on: October 27, 2008, 13:26:12 pm »
Have just been searching around these forums trying to find this answer and you nailed it.  Thank you so much for being generous enough to post your solution; just wish there were a lot more people willing to do this!

Matt