News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Custom Fields in Category View?

Started by ChristerE, March 25, 2012, 23:06:52 PM

Previous topic - Next topic

Abigail Ritchie

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

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

<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

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

can you try this exact code? it is extracted from my own file that works.

$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

The curious case of Abigail Ritchie  ;D

did you solve it?

Abigail Ritchie

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


Peter Pillen

i've sent you a personal message yesterday ;)

check the inbox on this forum

Peter Pillen


AbsoluteVM

#24
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

<?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

Hello,

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


$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

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:

$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

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


<?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

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.