News:

Looking for documentation? Take a look on our wiki

Main Menu

Data tables for products in category view

Started by memos, June 21, 2018, 15:07:50 PM

Previous topic - Next topic

memos

I ve seen a similar topic for virtuemart2 here: https://forum.virtuemart.net/index.php?topic=104825.msg353573#msg353573

Can you help me with the code for virtuemart 3?

I change the category->default.php with the code from above link  but no price is shown.

<?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 9017 2015-10-14 10:44:34Z Milbo $
 */

defined ('_JEXEC') or die('Restricted access');

?>
<div class="category-view"> <?php
$js 
"
jQuery(document).ready(function () {
jQuery('.orderlistcontainer').hover(
function() { jQuery(this).find('.orderlist').stop().show()},
function() { jQuery(this).find('.orderlist').stop().hide()}
)
});
"
;
vmJsApi::addJScript('vm.hover',$js);

if (empty(
$this->keyword) and !empty($this->category)) {
?>

<div class="category_description">
<?php echo $this->category->category_description?>

</div>
</div>
<?php
}

// Show child categories
if (VmConfig::get ('showCategory'1) and empty($this->keyword)) {
if (!empty($this->category->haschildren)) {

echo ShopFunctionsF::renderVmSubLayout('categories',array('categories'=>$this->category->children));

}
}

if(
$this->showproducts){
?>

<div class="browse-view">
<?php

if (!empty($this->keyword)) {
//id taken in the view.html.php could be modified
$category_id  vRequest::getInt ('virtuemart_category_id'0); ?>

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

<form action="<?php echo JRoute::('index.php?option=com_virtuemart&view=category&limitstart=0'FALSE); ?>" method="get">

<!--BEGIN Search Box -->
<div class="virtuemart_search">
<?php echo $this->searchCustomList ?>
<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 vmText::('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"/>
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="hidden" name="virtuemart_category_id" value="<?php echo $category_id?>"/>

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

<?php // Show child categories

?>

<div class="orderby-displaynumber">
<div class="floatleft vm-order-list">
<?php echo $this->orderByList['orderby']; ?>
<?php echo $this->orderByList['manufacturer']; ?>
</div>

<div class="floatright display-number"><?php echo $this->vmPagination->getResultsCounter ();?><br/><?php echo $this->vmPagination->getLimitBox ($this->category->limit_list_step); ?></div>

<div class="floatright vm-pagination vm-pagination-top">
<span class="vm-page-counter"><?php echo $this->vmPagination->getPagesCounter (); ?></span>
<?php echo $this->vmPagination->getPagesLinks (); ?>
</div>

<div class="clear"></div>
</div> <!-- end of orderby-displaynumber -->

<?php if($this->category->category_name) : ?>
<h1><?php echo vmText::_($this->category->category_name); ?></h1>
<?php endif; ?>

<?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="orders">
<tr>
<th>Name</th>
<th>Quantity</th>
<th>Price</th>
<th> Product Details </th>
<th> Add to Cart </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><?php  echo JHTML::link($product->link$product->product_name); ?></td>
<td><?php // Product Short Description

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

</td>
<td><?php echo $this->currency->createPriceDiv('basePrice','COM_VIRTUEMART_PRODUCT_BASEPRICE',$product->prices); ?> </td>

<td><?php // Product Details Button
echo JHTML::link($product->linkJText::_('COM_VIRTUEMART_PRODUCT_DETAILS'), array('title' => $product->product_name,'class' => 'product-details'));
?>
</td>



<td>

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

<div class="clear"></div>
</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>

<div class="vm-pagination vm-pagination-bottom">
<span class="vm-page-counter"><?php echo $this->vmPagination->getPagesCounter (); ?></span>
<?php echo $this->vmPagination->getPagesLinks (); ?>
</div>


</div>



</div>

<?php
$j 
"Virtuemart.container = jQuery('.category-view');
Virtuemart.containerSelector = '.category-view';"
;

vmJsApi::addJScript('ajaxContent',$j);
?>

<!-- end browse-view -->




memos

And a 2nd question.

Because i want my table to have styling from here: https://datatables.net/examples/styling/jqueryUI.html

when i put this code above the <table> it gives me a white page:

<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.css"/>


<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/dataTables.jqueryui.min.js"></script>



<script type="text/javascript"> 
$(document).ready(function() {
    $('#example').DataTable();

   
} );

</script>



Studio 42

For first question, i think that you have to modify many codes, the sample is obsolete and for eg cart should not be included this way.

In your 2nd question, if you added this inside PHP you get a blank page.

memos

Quote from: Studio 42 on June 21, 2018, 21:05:25 PM
For first question, i think that you have to modify many codes, the sample is obsolete and for eg cart should not be included this way.

Yes,i understand so i put codes from virtuemart 3 in the <td>

<?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 9017 2015-10-14 10:44:34Z Milbo $
 */

defined ('_JEXEC') or die('Restricted access');

?>
<div class="category-view"> <?php
$js 
"
jQuery(document).ready(function () {
jQuery('.orderlistcontainer').hover(
function() { jQuery(this).find('.orderlist').stop().show()},
function() { jQuery(this).find('.orderlist').stop().hide()}
)
});
"
;
vmJsApi::addJScript('vm.hover',$js);

if (empty(
$this->keyword) and !empty($this->category)) {
?>

<div class="category_description">
<?php echo $this->category->category_description?>

</div>
</div>
<?php
}

// Show child categories
if (VmConfig::get ('showCategory'1) and empty($this->keyword)) {
if (!empty($this->category->haschildren)) {

echo ShopFunctionsF::renderVmSubLayout('categories',array('categories'=>$this->category->children));

}
}

if(
$this->showproducts){
?>

<div class="browse-view">
<?php

if (!empty($this->keyword)) {
//id taken in the view.html.php could be modified
$category_id  vRequest::getInt ('virtuemart_category_id'0); ?>

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

<form action="<?php echo JRoute::('index.php?option=com_virtuemart&view=category&limitstart=0'FALSE); ?>" method="get">

<!--BEGIN Search Box -->
<div class="virtuemart_search">
<?php echo $this->searchCustomList ?>
<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 vmText::('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"/>
<input type="hidden" name="option" value="com_virtuemart"/>
<input type="hidden" name="virtuemart_category_id" value="<?php echo $category_id?>"/>

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

<?php // Show child categories

?>

<div class="orderby-displaynumber">
<div class="floatleft vm-order-list">
<?php echo $this->orderByList['orderby']; ?>
<?php echo $this->orderByList['manufacturer']; ?>
</div>

<div class="floatright display-number"><?php echo $this->vmPagination->getResultsCounter ();?><br/><?php echo $this->vmPagination->getLimitBox ($this->category->limit_list_step); ?></div>

<div class="floatright vm-pagination vm-pagination-top">
<span class="vm-page-counter"><?php echo $this->vmPagination->getPagesCounter (); ?></span>
<?php echo $this->vmPagination->getPagesLinks (); ?>
</div>

<div class="clear"></div>
</div> <!-- end of orderby-displaynumber -->

<?php if($this->category->category_name) : ?>
<h1><?php echo vmText::_($this->category->category_name); ?></h1>
<?php endif; ?>

<?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="orders">
<tr>
<th>Name</th>
<th>Price</th>
<th> Add to Cart </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><a title="<?php echo $product->product_name ?>" href="<?php echo $product->link.$ItemidStr?>"><?php echo $product->product_name ?></td>
<td><?php echo shopFunctionsF::renderVmSubLayout('prices',array('product'=>$product,'currency'=>$currency)); ?> </td>
<td><?php echo shopFunctionsF::renderVmSubLayout('addtocart',array('product'=>$product,'rowHeights'=>$rowsHeight[$row])); ?></td>
</tr>
<?php }
// end of foreach ( $this->products as $product )
?>




</table></div>

<div class="vm-pagination vm-pagination-bottom">
<span class="vm-page-counter"><?php echo $this->vmPagination->getPagesCounter (); ?></span>
<?php echo $this->vmPagination->getPagesLinks (); ?>
</div>


</div>



</div>

<?php
$j 
"Virtuemart.container = jQuery('.category-view');
Virtuemart.containerSelector = '.category-view';"
;

vmJsApi::addJScript('ajaxContent',$j);
?>

<!-- end browse-view -->



Still though gives me a white page when i insert the sublayout price in 2nd <td>
I understand there is somewhere an error.
Unfortunately i am not a programmer.

Studio 42

About blank page, you have to close and reopen the php using <?php ?>

//closing tag nest line
?>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.css"/>


<script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/dataTables.jqueryui.min.js"></script>



<script type="text/javascript"> 
$(document).ready(function() {
    $('#example').DataTable();

   
} );

</script>
<?php
//opening php tag