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

Edit VMLayout in Category view to single-row, custom layout?

Started by mailblade, August 07, 2019, 20:58:18 PM

Previous topic - Next topic

mailblade

I am redesigning an old site on a whole new template. The old version of the site was still on Joomla 3.6.

Eventually I realised this site and template will have to be updated due to it just being outdated. I purchased a template from Template Monster, which is using Joomla 3.9, T3 framework and is also running on PHP 7.130.

Back in 2017 when I first learned of VM I posted this thread: http://forum.virtuemart.net/index.php?topic=138437.msg485568#msg485568

The above thread is basically what I require now...

However, simply copying the code on the old site's "category/default.php" to the new "category/default.php" file I installed on the new template does not work.

I did not install the latest version of VM on the new site. I installed the exact same version as on the old site, as I feared too many changes were made and it would take much longer to simply move all the work and custom coding I have done.




I will post some of the old site's "category/default.php" code so you can get an idea of what I did:


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

<?php 
//$test = $product->virtuemart_product_id;
//echo ($test);
?>

<tr style="border-bottom: 1px solid #ffb3b3; height: 30px;">
<td style="padding-right: 15px;"><?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($db->quoteName(array('customfield_value''virtuemart_product_id')));
$query->from($db->quoteName('jos_virtuemart_product_customfields'));
$query->where($db->quoteName('virtuemart_custom_id') . ' LIKE '$db->quote('6'). ' AND '$db->quoteName('virtuemart_product_id') . 'LIKE ' $db->quote($product->virtuemart_product_id));

// Reset the query using our newly populated query object.
$db->setQuery($query);

// Load the results as a list of stdClass objects (see later for more options on retrieving data).
$results $db->loadResult();
echo (
$results); 
?>


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







Now, this is what I can't figure out. In the new version, there is this piece of code:

<?php
if (!empty(
$this->products)) {
//revert of the fallback in the view.html.php, will be removed vm3.2
if($this->fallback){
$p $this->products;
$this->products = array();
$this->products[0] = $p;
vmdebug('Refallback');
}

echo shopFunctionsF::renderVmSubLayout($this->productsLayout,array('products'=>$this->products,'currency'=>$this->currency,'products_per_row'=>$this->perRow,'showRating'=>$this->showRating));

if(!empty($this->orderByList)) { ?>

<div class="vm-pagination vm-pagination-bottom"><?php echo $this->vmPagination->getPagesLinks (); ?><span class="vm-page-counter"><?php echo $this->vmPagination->getPagesCounter (); ?></span></div>
<?php }
} elseif (
$this->keyword !== false) {
echo vmText::('COM_VIRTUEMART_NO_RESULT') . ($this->keyword ' : (' $this->keyword ')' '');
}
?>




If I remove this line of code from the newer version: echo shopFunctionsF::renderVmSubLayout($this->productsLayout,array('products'=>$this->products,'currency'=>$this->currency,'products_per_row'=>$this->perRow,'showRating'=>$this->showRating));, the products won't even load.  I assume this line is what renders the layout. However, I do not need this as in the old version I used the "foreach ($product)" line to load each item on an individual row using the horizontal seperator.

This is despite me using the foreach ( $this->products as $product ) as in the old version.




I really hope my explanations makes sense. I can't figure how to use the "renderVmSubLayout" line to create single rows so that I can do the same as on the old site.


I will attach a screenshot of the old site and how my category layout looks. I will also attach the code I wrote to achieve this. If someone could please take a look and see how I could duplicate this same layout to the new version, I would be very grateful. I hope it is not too much work. Or if someone could please help me with figuring out how to get around the "renderVmSubLayout" issue I'm having... (I've been trying for a few days now and can't figure it out embarrassingly) In the files I have obviously changed the name of the DB tables and such.

StefanSTS

Hi,

the line just calls the products.php sublayout in com_virtuemart/sublayouts.
You can find your products loop there and remove stuff you want different.
Or you could use the layout products_horizon.php that is already meant for one product per row.
Just call it in the category settings or via menu link.

Regards
Stefan
--
Stefan Schumacher
www.jooglies.com - VirtueMart Invoice Layouts

Please use only stable versions with even numbers for your live shop! Use Alpha versions only if you know what risk you are taking.

mailblade

Hi Stefan, really appreciate the reply!

Could you expand a bit on what you mean by this:
QuoteYou can find your products loop there and remove stuff you want different.

Do you mean the sublayout line?


StefanSTS

Hello,

the sublayout line calls the sublayout. VM3 has a lot of sublayouts now that you can override in your template.
The old category layout had the loop to display the products in itself. Now it just calls the sublayout instead.

The sublayout products.php is also used in the product module and can be called from anywhere where you want to produce a list of products.

Just have a look into the sublayout products.php and products_horinzon.php. You will find the old code that was in the category view before.

So just change the products.php and see what happens.
Override path would be: /templates/your_template/html/com_virtuemart/sublayouts/

Stefan
--
Stefan Schumacher
www.jooglies.com - VirtueMart Invoice Layouts

Please use only stable versions with even numbers for your live shop! Use Alpha versions only if you know what risk you are taking.

mailblade

Ahhh now I understand! I have to basicallly edit the sublayouts which will then have an effect on the category layout!

Thank you so much Stefan, really appreciate the help !!! I will be checking in a while and post my results back.