Author Topic: Category Page Fields for Templating  (Read 143743 times)

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10270
  • VirtueMart Version: 3+
Category Page Fields for Templating
« on: February 08, 2012, 19:42:18 pm »
These fields are for use in the category view
For product page fields, look here http://forum.virtuemart.net/index.php?topic=92756

Product fields that are not listed here can be used like this
 <?php echo $product->COLUMN_NAME ?>

The difference between category and product page is $this
$this->product      is for product page
$product->   is for product fields on the category page.

SO, to add weight to the category page. You can do
<?php echo $product->product_weight ?>

Category Name
<?php echo $this->category->category_name; ?>

Category Description
<?php echo $this->category->category_description ; ?>

Product Name with Link
<?php echo JHTML::link($product->link, $product->product_name) ?>

Product Details Link with anchor “Product Details”
<?php echo JHTML::link($product->link, JText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name,'class' =>
'product-details'));?>

Order by list
<?php echo $this->orderByList['orderby']; ?>

Manufacturer Dropdown
<?php echo $this->orderByList['manufacturer']; ?>

Pages/Links/Pagination
<?php echo $this->vmPagination->getResultsCounter();?>
<?php echo $this->vmPagination->getLimitBox(); ?>
<?php echo $this->vmPagination->getPagesLinks(); ?>
<?php echo $this->vmPagination->getPagesCounter(); ?>

Short Description
<?php echo shopFunctionsF::limitStringByWord($product->product_s_desc, 40, '...') ?>

^^ Notice the 40 above. limitStringByWord strips the text to 40 characters. You can change the "40"
For full short desc
 <?php echo $product->product_s_desc ?>

POP UP Product Image
<?php echo $product->images[0]->displayMediaThumb('class="browseProductImage" border="0" title="'.$product->product_name.'"
',true,'class="modal"'); ?>

Link Image to product page
   <?php echo JHTML::_('link', JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$product->virtuemart_product_id.'&virtuemart_category_id='.$product->virtuemart_category_id),$product->images[0]->displayMediaThumb('class="catImage" border="0"',false));
                  ?>

Stock Level
<?php echo $product->stock->stock_level ?>

# Products in Stock
<?php echo $product->product_in_stock ?>
I do NOT do development work for hire.

balai

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1290
Re: Category Page Fields for Templating
« Reply #1 on: February 09, 2012, 00:38:25 am »
Truly interesting post.
Thank you

Lexiboy

  • Jr. Member
  • **
  • Posts: 60
    • Lemongrass House Moscow
Re: Category Page Fields for Templating
« Reply #2 on: February 10, 2012, 11:35:30 am »
To display the product weight in a usable format:

// custom code to display weight 
     if ($product->product_weight <> '0'){
     echo "Упаковка: ";
     echo $product->product_weight;
     // echo $product->product_weight_uom;
     if ($product->product_weight_uom == "LB") echo 'мл.';
     if ($product->product_weight_uom == "OZ") echo 'л.';
     if ($product->product_weight_uom == "GR") echo 'гр.';
     if ($product->product_weight_uom == "KG") echo 'Кг.';
     if ($product->product_weight_uom == "MG") echo 'мг.';
     // print_r($product);
     }

Of course I could have dug a bit deeper into the source to find build in functionality to display the labels. To find more options, print_r is your friend :)
With kind regards,
Alex Stienstra

itsystem

  • Beginner
  • *
  • Posts: 5
Re: Category Page Fields for Templating
« Reply #3 on: February 17, 2012, 11:36:52 am »
Hi,

I would like to display product_sku but when I use <?php echo $this->product->product_sku ?> it dosn't work.
What's the appropriate format ?

Thanks a lot

itsystem

  • Beginner
  • *
  • Posts: 5
Re: Category Page Fields for Templating
« Reply #4 on: February 17, 2012, 11:50:45 am »
Well, I use :

Code: [Select]
<?php // Product Sku
echo JHTML::link JRoute::'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=' $product->virtuemart_product_id '&virtuemart_category_id=' $product->virtuemart_category_id ), $product->product_sku, array ('title' => $product->product_sku ) ); ?>

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10270
  • VirtueMart Version: 3+
Re: Category Page Fields for Templating
« Reply #5 on: February 17, 2012, 13:19:32 pm »
Hi,

I would like to display product_sku but when I use <?php echo $this->product->product_sku ?> it dosn't work.
What's the appropriate format ?

Thanks a lot


$this->   Refers to the current object. So $this-> ON THE CATEGORY page is calling category variables

$product->
I do NOT do development work for hire.

coxi

  • Beginner
  • *
  • Posts: 24
What about items qty in each category ?
« Reply #6 on: February 22, 2012, 19:21:32 pm »
Hi,
At first, thanks a lot for the support. I could make hack and my website is fine.
But...
It would be better if number of item could be shown in category.

Like this :
Category1 (3)           Category2 (17)            Category3 (4)
instead of
Category1                Category2                    Category3

Unfortunatly, i didn't find the solution. Any idea ?
Regards from France. Alain

dontflinch

  • Jr. Member
  • **
  • Posts: 152
Re: Category Page Fields for Templating
« Reply #7 on: March 02, 2012, 01:08:16 am »
I'm trying to test for a category image before echoing its link.

I've tried:

Code: [Select]
<?php if(!empty($this->category->images)) { ?>
       <div id=""><img src="<?php echo $this->category->images[0]->file_url_thumb?>"  alt="" /></div>
<?php }  ?>

but the test does not work (image renders fine if there is one), any ideas anyone?


=========================================================
solution edit: this works (thanks banquet tables pro!):

http://forum.virtuemart.net/index.php?topic=97744.msg326572#msg326572

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10270
  • VirtueMart Version: 3+
Re: Category Page Fields for Templating
« Reply #8 on: March 02, 2012, 01:17:23 am »
I'm trying to test for a category image before echoing its link.

I've tried:

Code: [Select]
<?php if(!empty($this->category->images)) { ?>
       <div id=""><img src="<?php echo $this->category->images[0]->file_url_thumb?>"  alt="" /></div>
<?php }  ?>

but the test does not work (image renders fine if there is one), any ideas anyone?

have you tried?

category->images[0]
I do NOT do development work for hire.

dontflinch

  • Jr. Member
  • **
  • Posts: 152
Re: Category Page Fields for Templating
« Reply #9 on: March 02, 2012, 03:32:03 am »
I have tried many variations of $this and $category with and without the
Code: [Select]
[0]

trying this makes the image disappear even on pages where there is one:

Code: [Select]
<?php if(!empty($category->images[0])) { ?>
<div id=""><img src="<?php echo $this->category->images[0]->file_url_thumb?>" alt="" /></div>
<?php ?>


btw I think you are the one I saw first say to use this 
Code: [Select]
echo $this->category->images[0]->file_url_thumb; and I modeled my 'if not empty' on your snippet for the product additional images, thanks.


PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10270
  • VirtueMart Version: 3+
Re: Category Page Fields for Templating
« Reply #10 on: March 02, 2012, 12:58:07 pm »
<?php if($this->category->images[0]->file_url_thumb) { ?>
       <div id=""><img src="<?php echo $this->category->images[0]->file_url_thumb; ?>"  alt="" /></div>
<?php }  ?>
I do NOT do development work for hire.

amanda mc donald

  • Beginner
  • *
  • Posts: 32
Re: Category Page Fields for Templating
« Reply #11 on: March 10, 2012, 12:40:40 pm »
THANK YOU!!!!!

This helped me so much!

Another question.... can you help me with adding new fields to products information page (I do NOT want to add attributes ... I want to add extra fields).
Joomla 1.7 Vm 2

Thank you

amanda mc donald

  • Beginner
  • *
  • Posts: 32
Re: Category Page Fields for Templating
« Reply #12 on: March 10, 2012, 13:17:38 pm »
Hi

I want to use this code (linking image to a product):

<?php echo JHTML::_('link', JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$product-
>virtuemart_product_id.'&virtuemart_category_id='.$product->virtuemart_category_id),$product->images[0]->displayMediaThumb
('class="browseProductImage" border="0"',false)); ?>


BUT instead of linking the image to a product ... I want to link the image to a URL ... how do I do that?

Thank you
amanda

dontflinch

  • Jr. Member
  • **
  • Posts: 152
Re: Category Page Fields for Templating
« Reply #13 on: March 10, 2012, 16:47:26 pm »
what sort of url (i.e. dynamic or one/static)? I think you'll have to be more specific than this.

Hi

I want to use this code (linking image to a product):

<?php echo JHTML::_('link', JRoute::_('index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$product-
>virtuemart_product_id.'&virtuemart_category_id='.$product->virtuemart_category_id),$product->images[0]->displayMediaThumb
('class="browseProductImage" border="0"',false)); ?>


BUT instead of linking the image to a product ... I want to link the image to a URL ... how do I do that?

Thank you
amanda

amanda mc donald

  • Beginner
  • *
  • Posts: 32
Re: Category Page Fields for Templating
« Reply #14 on: March 11, 2012, 20:34:13 pm »

I want to link an image to a URL on the internet (e.g. a specific youtube video)