Author Topic: Custom Fields in Category View?  (Read 44643 times)

Abigail Ritchie

  • Beginner
  • *
  • Posts: 5
Re: Custom Fields in Category View?
« Reply #15 on: February 01, 2013, 15:14:03 pm »
Thank you for replying Peter.

I'm using a string so assuming that value is correct according to your previous post's.

So I'm stumped and have no idea why it won't work??
Could it be where I'm placing the code in default.php(about line 120)?
Also, I have not moved the files to the joomla template folder yet, I planned on doing this later as I thought this was
only to avoid being overwritten on updates.... could this possibly be the reason?

Many thanks
Abby

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: Custom Fields in Category View?
« Reply #16 on: February 01, 2013, 15:30:38 pm »
maybe it is best to start from scratch

1. turn off your cache and clean it (system and others) so all changes are immediately visible.

2. always make a copy of the files you intend to change in that case, you can just put the old one back

3. If your not sure where to put the code or which file to use... use something like <? echo "I want it here"; ?> to locate the correct position in your file. If you see it popping up in the front-end where you want it to appear, then you already solved that problem.

There are 2 and more files that could need to be adapted
\templates\*your own template*\html\com_virtuemart\category\default.php --> for the vm category view in your own template
or
/components/com_virtuemart/views/category/tmpl/default.php --> if you use the default vm category template

same issue for your modules like "latest" products modules that you place elswhere
\modules\mod_virtuemart_category\tmpl\default.php --> if you are using the default module view from VM2

I think you need to locate the lines which creates the prices... look for the line if ($this->show_prices == '1') {. It is inside a <div>. Above that div, create a div like so

Code: [Select]
<div>
<? echo "I want it here"; ?>
</div>

And if you see it popping up above your price, you're good to go.

4. then try the database call again for your custom_value on that same location

Abigail Ritchie

  • Beginner
  • *
  • Posts: 5
Re: Custom Fields in Category View?
« Reply #17 on: February 01, 2013, 18:01:46 pm »
Thanks Peter

I did everything you recommended, the <div><? echo "I want it here"; ?></div> did show in the correct place,
then I added the code, but nothing changed.
I've tried using the db prefix instead of "#__", and also creating different types of custom fields and using "param".
Just can't see where I'm going wrong???? Its driving me crazy!

Abby

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: Custom Fields in Category View?
« Reply #18 on: February 01, 2013, 18:05:57 pm »
can you try this exact code? it is extracted from my own file that works.

Code: [Select]
$db = JFactory::getDBO();
$db->setQuery("SELECT custom_param FROM #__virtuemart_product_customfields WHERE virtuemart_product_id=".$product->virtuemart_product_id.";");
$db->query();
$result = $db->loadResult();
echo $result;

don't go crazy!  ;D

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: Custom Fields in Category View?
« Reply #19 on: February 03, 2013, 22:49:00 pm »
The curious case of Abigail Ritchie  ;D

did you solve it?

Abigail Ritchie

  • Beginner
  • *
  • Posts: 5
Re: Custom Fields in Category View?
« Reply #20 on: February 04, 2013, 11:21:36 am »
Hi Peter,

ha ha, yes this is a very curious case!!! I had to take myself away from it for the weekend.
I did try the code you sent (thank you), but it didn't seem to make any difference at all.
I was wondering if.... maybe I PM you some login details maybe you could take a look, and I would
gladly make a donation to you through paypal for your time?
I just know I've tried everything, but probably through my lack of knowledge, have missed something stupid.

Abby

Abigail Ritchie

  • Beginner
  • *
  • Posts: 5
Re: Custom Fields in Category View?
« Reply #21 on: February 05, 2013, 13:45:53 pm »
Can anyone help me?

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: Custom Fields in Category View?
« Reply #22 on: February 05, 2013, 13:54:45 pm »
i've sent you a personal message yesterday ;)

check the inbox on this forum

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: Custom Fields in Category View?
« Reply #23 on: February 05, 2013, 16:33:14 pm »
I think I solved your problem ;)


AbsoluteVM

  • Jr. Member
  • **
  • Posts: 85
Re: Custom Fields in Category View?
« Reply #24 on: February 13, 2013, 12:53:35 pm »
I found better results using the documentation:

http://docs.joomla.org/Accessing_the_database_using_JDatabase/2.5
http://docs.joomla.org/JDatabase::loadObjectList/11.1

Code: [Select]
<?php
// Get a db connection.
$db JFactory::getDbo();
 
// Create a new query object.
$query $db->getQuery(true);
 
// Select all records from the user profile table where key begins with "custom.".
// Order it by the ordering field.
$query->select(array('custom_value'));
$query->from('#__virtuemart_product_customfields');
$query->where('virtuemart_product_id='.$product->virtuemart_product_id);
$query->order('ordering ASC');
 
// Reset the query using our newly populated query object.
$db->setQuery($query);
 
// Load the results as a list of stdClass objects.
$results $db->loadObjectList();
// print_r($results);
echo '<ul>';
foreach (
$results as $result) {
    if(!empty(
$result->custom_value)) {
echo '<li>'.$result->custom_value.'</li>';
    }
}
echo 
'</ul>';
?>

AbsoluteVM

  • Jr. Member
  • **
  • Posts: 85
Re: Custom Fields in Category View?
« Reply #25 on: February 13, 2013, 13:55:08 pm »
Hello,

I wanted to grab the custom_title aswell, so I modified my query with a LEFT join.

Code: [Select]
$query
    ->select(array('a.custom_value', 'a.virtuemart_custom_id','b.virtuemart_custom_id', 'b.custom_title'))
    ->from('#__virtuemart_product_customfields AS a')
    ->join('INNER', '#__virtuemart_customs AS b ON (a.virtuemart_custom_id = b.virtuemart_custom_id)')
->where('a.virtuemart_product_id='.$product->virtuemart_product_id)
    ->order('a.custom_value DESC');

// Reset the query using our newly populated query object.
$db->setQuery($query);
 
// Load the results as a list of stdClass objects.
$results = $db->loadObjectList();

// print_r($results);

echo '<ul>';
foreach ($results as $result) {
if(!empty($result->custom_value)) {
echo '<li><span>'.$result->custom_title.': </span>'.$result->custom_value.'</li>';
}
}
echo '</ul>';
?>

bakefrank

  • Beginner
  • *
  • Posts: 4
Re: Custom Fields in Category View?
« Reply #26 on: March 12, 2013, 19:58:35 pm »
Hello I'm developing a site here:
You will need to login
UN: tester
pw: tester1!

http://gruverscafeandcatering.com/index.php/sandwiches

I'm trying to get the category display to show the custom fields I have created.

I have followed the instructions and code in this thread and have added the code:

Code: [Select]
$db = JFactory::getDBO();
     //please do check in php myadmin how your database table is called and replace it instead of "VM2_virtuemart_product_customfields" replace the "6" with your ID of Custom field you want to output
     $db->setQuery("SELECT custom_value FROM #__virtuemart_product_customfields WHERE virtuemart_product_id=".$product->virtuemart_product_id." and virtuemart_custom_id=5 ;"); 
     $db->query();
     $result = $db->loadResult();
echo "<span class=\"YourClass\">".$result."</span>";
?>

to line 287 under Product Short description.

My problem is
It only shows one selection from the custom fields I have created.
So if you look under the product Subs it should have A custom field name Choose your sub and a drop down for custom fields for (american, Italian, Ham, turkey)

http://gruverscafeandcatering.com/index.php/sandwiches/sub-8-detail

However it does not show a drop selection as it does on the product page, it is only showing one field American:

THanks for all the help.



master_dk

  • Beginner
  • *
  • Posts: 5
Re: Custom Fields in Category View?
« Reply #27 on: March 22, 2013, 22:51:05 pm »
I am trying to add custom fields and make them orderable from category view which i have edited. Tried this and many other suggestions and could not get it to work. Anyone have an idea of how to do it? This is my file in views/category/tmpl/default.php

Code: [Select]
<?php
/**
*
* Show the products in a category
*
* @package VirtueMart
* @subpackage
* @author RolandD
* @author Max Milbers
* @todo add pagination
* @link http://www.virtuemart.net
* @copyright Copyright (c) 2004 - 2010 VirtueMart Team. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
* VirtueMart is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* @version $Id: default.php 6053 2012-06-05 12:36:21Z Milbo $
*/

//vmdebug('$this->category',$this->category);
vmdebug('$this->category '.$this->category->category_name);
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die('Restricted access');
JHTML::_'behavior.modal' );
/* javascript for list Slide
  Only here for the order list
  can be changed by the template maker
*/
$js "
jQuery(document).ready(function () {
jQuery('.orderlistcontainer').hover(
function() { jQuery(this).find('.orderlist').stop().show()},
function() { jQuery(this).find('.orderlist').stop().hide()}
)
});
"
;

$document JFactory::getDocument();
$document->addScriptDeclaration($js);

/*$edit_link = '';
if(!class_exists('Permissions')) require(JPATH_VM_ADMINISTRATOR.DS.'helpers'.DS.'permissions.php');
if (Permissions::getInstance()->check("admin,storeadmin")) {
$edit_link = '<a href="'.JURI::root().'index.php?option=com_virtuemart&tmpl=component&view=category&task=edit&virtuemart_category_id='.$this->category->virtuemart_category_id.'">
'.JHTML::_('image', 'images/M_images/edit.png', JText::_('COM_VIRTUEMART_PRODUCT_FORM_EDIT_PRODUCT'), array('width' => 16, 'height' => 16, 'border' => 0)).'</a>';
}

echo $edit_link; */

/* Show child categories */

if ( VmConfig::get('showCategory',1) and empty($this->keyword)) {
if ($this->category->haschildren) {

// Category and Columns Counter
$iCol 1;
$iCategory 1;

// Calculating Categories Per Row
$categories_per_row VmConfig::get 'categories_per_row');
$category_cellwidth ' width'.floor 100 $categories_per_row );

// Separator
$verticalseparator " vertical-separator";
?>




<?php }
}
?>

<div class="browse-view">
    <?php
if (!empty($this->keyword)) {
?>

<h3><?php echo $this->keyword?></h3>
<?php
?>

  <?php if ($this->search !==null ) { ?>
    <form action="<?php echo JRoute::_('index.php?option=com_virtuemart&view=category&limitstart=0&virtuemart_category_id='.$this->category->virtuemart_category_id ); ?>" method="get">

    <!--BEGIN Search Box --><div class="virtuemart_search">
    <?php echo $this->searchcustom ?>
    <br />
    <?php echo $this->searchcustomvalues ?>
    <input name="keyword" class="inputbox" type="text" size="20" value="<?php echo $this->keyword ?>" />
    <input type="submit" value="<?php echo JText::_('COM_VIRTUEMART_SEARCH'?>" class="button" onclick="this.form.keyword.focus();"/>
    </div>
    <input type="hidden" name="search" value="true" />
    <input type="hidden" name="view" value="category" />

    </form>
<!-- End Search Box -->
<?php ?>

<?php // Show child categories
if (!empty($this->products)) {
?>



<h2><?php echo $this->category->category_name?></h2>

<?php
// Category and Columns Counter
$iBrowseCol 1;
$iBrowseProduct 1;

// Calculating Products Per Row
$BrowseProducts_per_row $this->perRow;
$Browsecellwidth ' width'.floor 100 $BrowseProducts_per_row );

// Separator
$verticalseparator " vertical-separator";

// Count products
$BrowseTotalProducts 0;
foreach ( 
$this->products as $product ) {
   
$BrowseTotalProducts ++;
}
?>


<table class="products">
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
</tr>

<?php
// Start the Output
foreach ( $this->products as $product ) {

// Show the horizontal seperator
if ($iBrowseCol == && $iBrowseProduct $BrowseProducts_per_row) { ?>

<div class="horizontal-separator"></div>
<?php }
?>



<tr>
<td align="left" width="20%"><?php  echo JHTML::link($product->link$product->product_name); ?></td>
<td align="left" width="60%"><?php // Product Short Description

     echo shopFunctionsF::limitStringByWord($product->product_s_desc100'...'?>

</td>
<td align="center" width="15%"><?php echo $this->currency->createPriceDiv('salesprice','COM_VIRTUEMART_PRODUCT_PRICE',$product->prices['salesPrice']); ?> </td>


<td align="right" width="5%">

<form method="post" class="product" action="index.php" id="addtocartproduct<?php echo $product->virtuemart_product_id ?>">


<div class="addtocart-bar">

<?php echo $this->product->virtuemart_product_id;?>
<span class="quantity-box">
<input type="text" class="quantity-input" name="quantity[]" value="1" />
</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>


</div>

<?php // Display the add to cart button END ?>
<input type="hidden" class="pname" value="<?php echo $product->product_name ?>">
<input type="hidden" name="option" value="com_virtuemart" />
<input type="hidden" name="view" value="cart" />
<noscript><input type="hidden" name="task" value="add" /></noscript>
<input type="hidden" name="virtuemart_product_id[]" value="<?php echo $product->virtuemart_product_id ?>" />
<?php /** @todo Handle the manufacturer view */ ?>
<input type="hidden" name="virtuemart_manufacturer_id" value="<?php echo $product->virtuemart_manufacturer_id ?>" />
<input type="hidden" name="virtuemart_category_id[]" value="<?php echo $product->virtuemart_category_id ?>" />
</form>
 </td>


</tr>

<?php }
// end of foreach ( $this->products as $product )
?>




</table></div><!-- end browse-view -->

jloeza1818

  • Beginner
  • *
  • Posts: 1
Re: Custom Fields in Category View?
« Reply #28 on: April 24, 2013, 20:49:17 pm »
I'm Having the exact same issue as bakefrank it shows the customfields but is not showing the dropdown menu to select it. does anyone know how to fix this? Thank you.

PATSXM971

  • Beginner
  • *
  • Posts: 20
    • Web Ti Market
Re: Custom Fields in Category View?
« Reply #29 on: July 31, 2013, 17:49:08 pm »
Hi there,

for future user being able to find a more recent and reliable solution, see this topic
https://forum.virtuemart.net/index.php?topic=116058.msg397587#msg397587