News:

Looking for documentation? Take a look on our wiki

Main Menu

Category Page Fields for Templating

Started by PRO, February 08, 2012, 19:42:18 PM

Previous topic - Next topic

PRO

Quote from: Piombo on December 26, 2013, 10:35:51 AM
Hello!

How can I get a direct url to thumb image in category page? (components\com_virtuemart\views\category\tmpl\default.php)

This code
<?php echo $product->images[0]->displayMediaThumb('class="browseProductImage"'false); ?>
creates an <img ... src="url to thumb image"...> tag.

I tried:



echo $product->category->images[0]->file_url_thumb;
or
echo $this->category->images[0]->file_url_thumb;
or
echo $this->product->file_url_thumb
or
echo $this->product->images[0]->file_url_thumb;

and a few more options. dosent work :(



This code works in product pages.
<?php echo $this->product->images[0]->file_url_thumb?>


Please help!

http://forum.virtuemart.net/index.php?topic=100696.0

$this-> does not work for products in a category

$product

Piombo

Thanks a lot!

This code is correct

<?php echo $product->images[0]->file_url_thumb?>

DOall

I would like to add the stock quantity at my page only for register users.
The code <?php echo $this->product->product_in_stock ?> works fine but i only want to show this function to register users. which code i need to add?

thanks in advance

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

DOall

Thanks for the help but i can't use that function correctly.

<?php
$user =& JFactory::getUser();
if( $user->shopper ) {
echo $this->product->product_in_stock
}
else{
echo 'Login in please'
}
<?php endif; ?>

what i'm missing?

PS: I have no knowledge of php


Thanks in advance

PRO


lupinlady

Im trying to get the customfields area on to the category page. The Add to Cart button was already there, came with the template. Im new to php.


I edited /hot_watches/html/com_virtuemart/category/default.php  Since the 'Add to Cart' button was hard coded in I copied the code from /components/com_virtuemart/views/productdetails/tmpl/default_customfields.php and added it above the cart button.

First I added the 'custom fields position above the 'product fields' but it didnt work so I moved it below, still not working. Then changed$this->product to $product and I also removed the part -- echo $this->loadTemplate ('customfields' ); -- since the template is already there.

Ive also added default_customfields.php to the category folder renamed as default_customfields_category.php and tried an include per some of the suggestions on this site.

Not sure what else to try. Any help would be great.

The code I tried first is below:

// Show Products
   ?>
   <div class="product floatleft<?php echo $Browsecellwidth . $show_vertical_separator ?>">
   <div class="spacer">

   <div class="product_intro">

   <h3 style="float:left;"><a href="javascript:;">
   <?php // Product Name
      echo $product->product_name; ?>
      </a></h3>
      <div style="float:right;" class="rotated_image">
      <a title="<?php echo $product->link ?>" rel="vm-additional-images" href="<?php echo $product->link; ?>">
   <?php
      echo $product->images[0]->displayMediaThumb('class="browseProductImage"', false);
   ?>
   </a>
   </div>
   <div class="clr"></div>
   </div>

   <div class="product_details_box">
               
   <div class="normal_image">
   <?php if ($product->images) {
   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="featuredProductImage" border="0"',false,'class="modal"' ) );
   } ?>
   </div>
                   
   <div class="product_details_box2">
   <div class="product_details_box3">
   <?php // Product Short Description
   if (!empty($product->product_desc)) {
   ?>
   <p class="product_s_desc">
      <?php echo shopFunctionsF::limitStringByWord ($product->product_desc, 1000, '...') ?>
   </p>
   <?php } ?>
                               
<!-- I copied the 'product fields' from /components/com_virtuemart/views/productdetails/tmpl/default_customfields.php and placed it here -->                           
                                                               
   <div class="product-fields">
      <?php
        $custom_title = null;
        foreach ($product->customfieldsSorted[$this->position] as $field) {
        if ( $field->is_hidden ) //OSP http://forum.virtuemart.net/index.php?topic=99320.0
        continue;
        if ($field->display) {
      ?><div class="product-field product-field-type-<?php echo $field->field_type ?>">
      <?php if ($field->custom_title != $custom_title && $field->show_title) { ?>
      <span class="product-fields-title" ><?php echo JText::_($field->custom_title); ?></span>
      <?php
        if ($field->custom_tip)
        echo JHTML::tooltip($field->custom_tip, JText::_($field->custom_title), 'tooltip.png');
        }
        ?>
          <span class="product-field-display"><?php echo $field->display ?></span>
          <span class="product-field-desc"><?php echo jText::_($field->custom_field_desc) ?></span>
        </div>
      <?php
        $custom_title = $field->custom_title;
         }
          }
      ?>
      </div>
<!-- I copied the 'custom fields position' from /templates/hot_watches/html/com_virtuemart/productdetails/default.php --->           
      <div>
        <?php
      if (!empty($product->customfieldsSorted['normal'])) {
      $this->position = 'normal';
       }
    ?>
     </div>
   <div style="padding:20px 0;">   
   <form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">
   <div class="addtocart-bar">

   <?php // Display the quantity box ?>
   <!-- <label for="quantity<?php echo $this->product->virtuemart_product_id;?>" class="quantity_box"><?php echo JText::_('COM_VIRTUEMART_CART_QUANTITY'); ?>: </label> -->
   <span class="quantity-box">
   <input  type="text" class="quantity-input" name="quantity[]" value="1" />
   </span>
   <span class="quantity-controls">
   <input type="button" class="quantity-controls quantity-plus" />
   <input type="button" class="quantity-controls quantity-minus" />
   </span>
   <?php // Display the quantity box END ?>

   <?php // Add the button
      $button_lbl = JText::_('COM_VIRTUEMART_CART_ADD_TO');
      $button_cls = ''; //$button_cls = 'addtocart_button';
      if (VmConfig::get('check_stock') == '1' && !$this->product->product_in_stock) {
      $button_lbl = JText::_('COM_VIRTUEMART_CART_NOTIFY');
      $button_cls = 'notify-button';
   } ?>

   <?php // Display the add to cart button ?>
      <span class="addtocart-button">
      <input type="submit" name="addtocart"  class="addtocart-button" value="<?php echo $button_lbl ?>" title="<?php echo $button_lbl ?>" />
      </span>

csg22

The problem is in virtuemart 2.6.6, if you use URL in product information &this->product->product_url, the $this->product->virtuemart_category_id will be replaced with the product url :)))
Try it: <?php echo $this->product->virtuemart_category_id; ?> As a result I see my referral link :D

Troels_E

Thanks a lot for the very very helpful posts about Product and Category pages. From a non developer perspective who hasn't got a clue regarding PHP these are truly great as it helped me comment out certain parts and pasting code needed.
Without these forums and a helpful community I'd be lost in VM/Joomla and stuck with a webshop based on Bricksite or the like (and this is much more fun!!)

aminweb

this code :

<div class="img-wrapper">
                                   <?php
                                            $image 
$product->images[0]->displayMediaThumb('class="browseProductImage featuredProductImageFirst" id="Img_to_Js_'.$product->virtuemart_product_id.'" border="0"',false) ;
if(!empty($product->images[1])){
 $image2 $product->images[1]->displayMediaThumb('class="browseProductImage featuredProductImageSecond"  border="0"',false) ;
} else {$image2$product->images[0]->displayMediaThumb('class="browseProductImage featuredProductImageSecond"  border="0"',false) ;}
                                            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),'<div class="front">'.$image.'</div><div class="back">'.$image2.'</div>');
                                    
?>

                                    </div>
                                   


output code :
<div class="img-wrapper">
    <a href="link to product">
     <div class="front">
             <img product >
         </div>
         <div class="back">
             <img product >
         </div>
    </a>                             
</div>


Now,I want add class to  <a href="libk to product">
how do it?
please help me
thanks

PRO

you can do it with css, without changing the html

.img-wrapper a{}

aminweb

no, I dont want use css...
I want only add class for <a href .....
please help

PRO

I prefer to not have the class in the html,

BECAUSE

say for example on the category page, you have 100 products

and the class name is 5 characters.

THAT MAKES THE HTML DOCUMENT 500 CHARACTERS LONGER, and has to be parsed
Less html, means faster site.

but try this

<div class="img-wrapper">
                                   <?php
                                            $image = $product->images[0]->displayMediaThumb('class="browseProductImage featuredProductImageFirst" id="Img_to_Js_'.$product->virtuemart_product_id.'" border="0"',false) ;
                                 if(!empty($product->images[1])){
                                  $image2 = $product->images[1]->displayMediaThumb('class="browseProductImage featuredProductImageSecond"  border="0"',false) ;
                                 } else {$image2= $product->images[0]->displayMediaThumb('class="browseProductImage featuredProductImageSecond"  border="0"',false) ;}
                                            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),'<div class="front">'.$image.'</div><div class="back">'.$image2.'</div>','class="my-class"');
                                    ?>
                                    </div>

just change   my-class