NAME | PRODUCT TYPE PARAMETER NAME 1 | … PARAMETER 2 | …. | .


VirtueMart Forum

VirtueMart 1.1 => Themes & Layout Customization => Topic started by: Seth123 on November 08, 2009, 23:11:35 pm


Title: [SOLVED] Customised category browse page

Post by: Seth123 on November 08, 2009, 23:11:35 pm


Hi!

I would need help customizing the category browse page. I think this is a useful thing for any future templates/virtuemart releases.

I have a lot of products with their respecting parameters. I want to display these products as a "table" in the category view, so that a user can have a clear view of the product's parameters already in the category view.

The next picture shows the same category view when I change the theme configuration inside virtuemart to: Flat product list (fixed to 1 row, using a table):

The picture shows the same category view when I change the theme configuration inside virtuemart to: Flat product list (fixed to 1 row, using a table): 02_flat_product_list_fixed_to_1_row_using_a_table.PNG

This is similar to what I need to get! But it's just not that!

I only need 1 prouduct per row. The table row should be:
NAME | PRODUCT TYPE PARAMETER NAME 1 | … PARAMETER 2 | …. | …. PARAMETER N |

Those same parameter names + values are displayed on the product detalis page (picture 03). I need those parameters (or at least a few of them) in the category browse page.

So, I don't need the product picture, SKU, detalis link. I just need the product name with it's parameters.

I hope I explained this clearly! Please can someone help me with this or at least give me a hint what to change. I couldn't find the file where the "Flat product list" is generated.

Thanks!


Title: Re: Need help from deveoper/designer
Post by: rb on November 09, 2009, 15:29:31 pm


The answer to your question "where are the product lists generated?" depends on your VM template's Product List Style setting in the theme's config:

The "Browse" listing is outputted via:
     /components/com_virtuemart/themes/default/templates/browse/includes/browse_layouttable.tpl.php
    if config is "Product Listing with a table (default)"
or
     /components/com_virtuemart/themes/default/templates/browse/includes/browse_listtable.tpl.php
    if config is "Flat Product List (fixed to 1 product per row, using a table)"
or
    /components/com_virtuemart/themes/default/templates/browse/includes/browse_notables.tpl.php
    if config is "Product List (no table, div-based)"

For help in modifying it, check out:
http://forum.virtuemart.net/index.php?topic=52411.0


Title: Re: Need help from deveoper/designer
Post by: Seth123 on November 09, 2009, 17:03:24 pm


Thanks for Your answer. I'll get into this right now.


Title: Re: Need help from deveoper/designer
Post by: Seth123 on November 10, 2009, 23:30:20 pm


I tried to solve this but I'm not getting anywhere. I tried to modify browse_listtable.tpl.php!

First the table header is created (I commented out the 'SKU', cause I don't need that).

Code:
// Table header
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_NAME');
/*$tableheader[] = $VM_LANG->_('PHPSHOP_CART_SKU');*/
if( _SHOW_PRICES && $auth['show_prices'] ) {
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_PRICE');
}
$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_FORM_THUMB_IMAGE');
$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_DESC_TITLE');
if( _SHOW_PRICES && $auth['show_prices'] && USE_AS_CATALOGUE != '1' ) {
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_ACTION');
}

1 – I want to add the product_type_parameters. There is only one product type for one product category in my shop.
My guess is that I need to look up the first product's product_type and add the parameter names of that product type to the $tableheader[]. Right? This is where I'm stuck. Don't have a clue on how to do that.  🙂
Can someone help me or give me a hint. Don't really know php, but I must try to solve this…

Thanks


Title: Re: Need help from deveoper/designer
Post by: rb on November 10, 2009, 23:50:20 pm


It's more involved than just getting the parameter names from the DB and adding them to the header.  You also have to get the parameter values from the database and put them into the detail rows.  Since this requires knowledge of PHP scripting within the VirtueMart framework (including MySQL functions), you may want to consider hiring professional assistance.  See "Commercial Jobs" in the VM Forums.


Title: Re: Need help from deveoper/designer
Post by: Seth123 on November 11, 2009, 14:04:02 pm


Hi rb!

I think I've done it for the table, but I can't seem to get it for the table header! To do this I need to get the product_type from the first product in the current category. After that I can generate the parameter_label to put it into the header. Can You help me out or give me a hint?

Here is how I did it. I don't really know php and sql that well so I practicaly copied the function list_product_type() from ps_product_type.php and just got rid of everything I didn't need.
Also I needed to add a line in shop.browse php:

Code:
$products[$i]['product_id'] = $db_browse->f("product_id");

So this is my browse_listtable.tpl.php:

Code:
// Table header
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_NAME');
/*$tableheader[] = $VM_LANG->_('PHPSHOP_CART_SKU');*/
if( _SHOW_PRICES && $auth['show_prices'] ) {
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_PRICE');
}
$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_FORM_THUMB_IMAGE');
$tableheader[] = $VM_LANG->_('PHPSHOP_PRODUCT_DESC_TITLE');
if( _SHOW_PRICES && $auth['show_prices'] && USE_AS_CATALOGUE != '1' ) {
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_ACTION');
}

// Creates a new HTML_Table object that will help us
// to build a table holding all the products
$table =& new HTML_Table('width="100%"');

$table->addRow( $tableheader, 'class="sectiontableheader"', 'th', true );

foreach( $products as $product ) {

foreach( $product as $attr => $val ) {
// Using this we make all the variables available in the template
// translated example: $this->set( 'product_name', $product_name );
$this->set( $attr, $val );
}

$data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'.$product['product_name'].'</a>';
/*$data[$row][] = $product['product_sku'];*/
$product_id = $product['product_id'];
$dbag = new ps_DB;
$dba = new ps_DB;
$dbp = new ps_DB;

$q  = "SELECT * FROM #__{vm}_product_product_type_xref ";
$q .= "LEFT JOIN #__{vm}_product_type USING (product_type_id) ";
$q .= "WHERE product_id='$product_id' AND product_type_publish='Y' ";
$q .= "ORDER BY product_type_list_order";
$dbag->query( $q );
$q  = "SELECT * FROM #__{vm}_product_type_parameter ";
$q .= "WHERE product_type_id=";
$q2 = "SELECT product_id AS key".$dbag->f("product_type_id").", #__{vm}_product_type_".$dbag->f("product_type_id").".* FROM #__{vm}_product_type_".$dbag->f("product_type_id");
$q2 .= " WHERE product_id='$product_id'";
while ($dbag->next_record()) { // Show all Product Type
// SELECT parameter value of product
/* OVO VADIM JER SAM TO VIDIO OVDJE: http://www.joomfish.net/forum/viewtopic.php?f=24&t=495&p=18481&hilit=product_type_parameter#p18481*/
/*$q2  = "SELECT * FROM #__{vm}_product_type_".$dbag->f("product_type_id");*/
$q2 = "SELECT product_id AS key".$dbag->f("product_type_id").", #__{vm}_product_type_".$dbag->f("product_type_id").".* FROM #__{vm}_product_type_".$dbag->f("product_type_id");
$q2 .= " WHERE product_id='$product_id'";
$dbp->query($q2);
// SELECT parameter of Product Type
$dba->query($q.$dbag->f("product_type_id")." ORDER BY parameter_list_order");
$i=0;
while ($dba->next_record()) {
/*$data[$row][] = $dba->f("parameter_label");*/
/*$parameter_description = $dba->f("parameter_description");
if (!empty($parameter_description)) {
$html .= "&nbsp;";
$html .= vmToolTip($parameter_description, $VM_LANG->_('PHPSHOP_PRODUCT_TYPE_PARAMETER_FORM_DESCRIPTION'));
}*/
$data[$row][] = $dbp->f($dba->f("parameter_name"))/*." ".$dba->f("parameter_unit")*/;
}
}
/*$data[$row][] = $product['product_id'];*/
if( _SHOW_PRICES && $auth['show_prices'] ) {
$data[$row][] = $product['product_price'];
}
/*$data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
. ps_product::image_tag( $product['product_thumb_image'] )
. '</a>';*/
/*$data[$row][] = $product['product_s_desc'];*/
/*$data[$row][] = $product['product_type']; */
/*if( $product['has_addtocart'] ) {
$data[$row][] = $product['form_addtocart'];
}
else {
$data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
. $product['product_details']
. '</a>';
}*/

$row++;

}

Can You help me out or give me a hint how to add the header? The result (so far) is in the attachment.
Thanks


Title: Re: Need help from deveoper/designer
Post by: Seth123 on November 11, 2009, 15:31:56 pm


I fixed the tableheader too. Lokks like I didn't need help. Anyway, thanks rb.

This is the final code, if someone needs it or if he can make it look more friendly, cause I mainly copied it from other places.

Code:
<?php if( !defined'_VALID_MOS' ) && !defined'_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );
mm_showMyFileName(__FILE__);?>


<?php echo $buttons_header // The PDF, Email and Print buttons ?>
<?php echo $browsepage_header // The heading, the category description ?>
<?php echo $parameter_form // The Parameter search form ?>
<?php echo $orderby_form // The sort-by, order-by form PLUS top page navigation ?>

<?php
$data 
=array(); // Holds the rows of products
$i 1$row 0// Counters

// Table header
$tableheader[] = $VM_LANG->_('PHPSHOP_CART_NAME');
$dbag = new ps_DB;
$dba = new ps_DB;
$dbp = new ps_DB;
foreach( 
$products as $product ) {
foreach( $product as $attr => $val ) {
// Using this we make all the variables available in the template
// translated example: $this->set( 'product_name', $product_name );
$this->set$attr$val );
}
}
$product_id$product['product_id'];
$q  "SELECT * FROM #__{vm}_product_product_type_xref ";
$q .= "LEFT JOIN #__{vm}_product_type USING (product_type_id) ";
$q .= "WHERE product_id='$product_id' AND product_type_publish='Y' ";
$q .= "ORDER BY product_type_list_order";
$dbag->query$q );
$q  "SELECT * FROM #__{vm}_product_type_parameter ";
$q .= "WHERE product_type_id=";
while (
$dbag->next_record()) { // Show all Product Type
// SELECT parameter of Product Type
$dba->query($q.$dbag->f("product_type_id")." ORDER BY parameter_list_order");
$i=0;

while ($dba->next_record()) {
$tableheader[] = $dba->f("parameter_label")."[".$dba->f("parameter_unit")."]";
}
}

// Creates a new HTML_Table object that will help us
// to build a table holding all the products
$table =& new HTML_Table('width="100%"');

$table->addRow$tableheader'class="sectiontableheader"''th'true );

foreach( 
$products as $product ) {

foreach( $product as $attr => $val ) {
// Using this we make all the variables available in the template
// translated example: $this->set( 'product_name', $product_name );
$this->set$attr$val );
}

$data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'.$product['product_name'].'</a>';
$product_id $product['product_id'];
$dbag = new ps_DB;
$dba = new ps_DB;
$dbp = new ps_DB;

$q  "SELECT * FROM #__{vm}_product_product_type_xref ";
$q .= "LEFT JOIN #__{vm}_product_type USING (product_type_id) ";
$q .= "WHERE product_id='$product_id' AND product_type_publish='Y' ";
$q .= "ORDER BY product_type_list_order";
$dbag->query$q );
$q  "SELECT * FROM #__{vm}_product_type_parameter ";
$q .= "WHERE product_type_id=";
$q2 "SELECT product_id AS key".$dbag->f("product_type_id").", #__{vm}_product_type_".$dbag->f("product_type_id").".* FROM #__{vm}_product_type_".$dbag->f("product_type_id");
$q2 .= " WHERE product_id='$product_id'";
while ($dbag->next_record()) { // Show all Product Type
// SELECT parameter value of product
/* Joomfish hack for multilanguage: http://www.joomfish.net/forum/viewtopic.php?f=24&t=495&p=18481&hilit=product_type_parameter#p18481*/
/*$q2  = "SELECT * FROM #__{vm}_product_type_".$dbag->f("product_type_id");*/
$q2 "SELECT product_id AS key".$dbag->f("product_type_id").", #__{vm}_product_type_".$dbag->f("product_type_id").".* FROM #__{vm}_product_type_".$dbag->f("product_type_id");
$q2 .= " WHERE product_id='$product_id'";
$dbp->query($q2);
// SELECT parameter of Product Type
$dba->query($q.$dbag->f("product_type_id")." ORDER BY parameter_list_order");
$i=0;
while ($dba->next_record()) {
/*$data[$row][] = $dba->f("parameter_label");*/
/*$parameter_description = $dba->f("parameter_description");
if (!empty($parameter_description)) {
$html .= "&nbsp;";
$html .= vmToolTip($parameter_description, $VM_LANG->_('PHPSHOP_PRODUCT_TYPE_PARAMETER_FORM_DESCRIPTION'));
}*/
$data[$row][] = $dbp->f($dba->f("parameter_name"))/*." ".$dba->f("parameter_unit")*/;
}
}
/*$data[$row][] = $product['product_id'];*/
if( _SHOW_PRICES && $auth['show_prices'] ) {
$data[$row][] = $product['product_price'];
}
/*$data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
. ps_product::image_tag( $product['product_thumb_image'] )
. '</a>';*/
/*$data[$row][] = $product['product_s_desc'];*/
/*$data[$row][] = $product['product_type']; */
/*if( $product['has_addtocart'] ) {
$data[$row][] = $product['form_addtocart'];
}
else {
$data[$row][] = '<a href="'.$product['product_flypage'].'" title="'.$product['product_name'].'">'
. $product['product_details']
. '</a>';
}*/

$row++;

}


// Loop through each row and build the table
foreach($data as $key => $value) {

$table->addRow$data[$key], 'class="sectiontableentry'.$i.'"''td'true );
$i $i == 1;
}
// Display the table
echo $table->toHtml();
?>

<br class="clr" /><br />
<?php echo $browsepage_footer ?>
<?php 
// Show Featured Products
if( $this->get_cfg'showFeatured')) {
    
/* featuredproducts(random, no_of_products,category_based) no_of_products 0 = all else numeric amount
    edit featuredproduct.tpl.php to edit layout */
    
echo $ps_product->featuredProducts(true,10,true);
?>

<?php echo $recent_products ?>

Just a little bit of .css and we're done. The code includes a joomfish hack for multiple languages that translates all product parameters. The link is inside the code.
Bye

Source: https://forum.virtuemart.net/index.php?action=printpage;topic=62614.0