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

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10292
  • VirtueMart Version: 3+
Re: Category Page Fields for Templating
« Reply #120 on: December 29, 2013, 03:01:30 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
Code: [Select]
<?php echo $product->images[0]->displayMediaThumb('class="browseProductImage"'false); ?>creates an <img ... src="url to thumb image"...> tag.

I tried:

Code: [Select]

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.
Code: [Select]
<?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
I do NOT do development work for hire.

Piombo

  • Beginner
  • *
  • Posts: 28
Re: Category Page Fields for Templating
« Reply #121 on: December 30, 2013, 09:51:04 am »
Thanks a lot!

This code is correct

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

DOall

  • Beginner
  • *
  • Posts: 11
Re: Category Page Fields for Templating
« Reply #122 on: January 05, 2014, 16:21:59 pm »
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

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 25252
  • On vacation
    • Jenkin Hill Internet
Re: Category Page Fields for Templating
« Reply #123 on: January 05, 2014, 17:17:11 pm »
Use JFactory/getUser

See http://bit.ly/Ktnw5j
Kelvyn

Jenkin Hill Internet,
Keswick, Lake District

Unsolicited PMs/emails will be ignored.

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

Currently using VM3.0.18.8 on Joomla 3.6.5 PHP 7.0.12

Testing VM3.0.18.9 On J!3.6.5

DOall

  • Beginner
  • *
  • Posts: 11
Re: Category Page Fields for Templating
« Reply #124 on: January 05, 2014, 22:23:19 pm »
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

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10292
  • VirtueMart Version: 3+
Re: Category Page Fields for Templating
« Reply #125 on: January 06, 2014, 01:00:19 am »
if ($user->id)

or

($user->id !=0 )
I do NOT do development work for hire.

lupinlady

  • Beginner
  • *
  • Posts: 5
Re: Category Page Fields for Templating
« Reply #126 on: February 20, 2014, 02:14:03 am »
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

  • Beginner
  • *
  • Posts: 3
Re: Category Page Fields for Templating
« Reply #127 on: November 07, 2014, 10:58:31 am »
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

  • Beginner
  • *
  • Posts: 40
Re: Category Page Fields for Templating
« Reply #128 on: April 16, 2015, 20:49:21 pm »
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

  • Beginner
  • *
  • Posts: 5
  • A beginner
Re: Category Page Fields for Templating
« Reply #129 on: July 20, 2016, 08:08:58 am »
this code :
Code: [Select]
<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 :
Code: [Select]
<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

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10292
  • VirtueMart Version: 3+
Re: Category Page Fields for Templating
« Reply #130 on: July 20, 2016, 13:25:34 pm »
you can do it with css, without changing the html

.img-wrapper a{}
I do NOT do development work for hire.

aminweb

  • Beginner
  • *
  • Posts: 5
  • A beginner
Re: Category Page Fields for Templating
« Reply #131 on: July 20, 2016, 14:58:02 pm »
no, I dont want use css...
I want only add class for <a href .....
please help

PRO

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10292
  • VirtueMart Version: 3+
Re: Category Page Fields for Templating
« Reply #132 on: July 20, 2016, 20:12:41 pm »
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
I do NOT do development work for hire.