VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: The_nino on June 04, 2012, 14:39:46 PM

Title: Is possible to override html.php files?
Post by: The_nino on June 04, 2012, 14:39:46 PM
Hi everbody,

I am using a VM 2.0.6 and Joomla 2.5.

I need to modify the file \components\com_virtuemart\views\virtuemart\view.html.php due to change the number of featured products shown at the home page of virtuemart. I need to show 6 products and the code just allow 5 (line 71).

There is any way to override the file just like the files inside the tmpl folder? I donĀ“t want to loose the work when I update the VM again...
I tried to override it including the file into the folder

templates\mytemplate\html\com_virtuemart\virtuemart

but without results...

Thanks a lot!
Title: Re: Is possible to override html.php files?
Post by: The_nino on June 10, 2012, 10:33:02 AM
Nobody??
Title: Re: Is possible to override html.php files?
Post by: srajca on July 20, 2012, 13:56:30 PM
hey the nino, have youo managed to override this? I would like to do the same. thnx
Title: Re: Is possible to override html.php files?
Post by: bytelord on August 19, 2012, 14:06:05 PM
Hello all,

because i need it for a client web site i post here a solution by calling the model (as the view.html.php files does).
that solution overrides the view.html.php for virtuemart view template but have the disadvantage that we "fill" again (for second time) the products list (affects on performance). I didn't count it, but it will be a small performance issue, if you won't load a lot of products then you will not have issue. The following code is the same code inside view.html.php but we just change the $products to $this->products and we call the product model.

So, inside our custom template under html\com_virtuemart\virtuemart\default_products.php after the first line before // Separator paste the following code:

//Lets bring the model and refill the products list.
$productModel = VmModel::getModel('product');
if (VmConfig::get('show_featured', 1)) {
$this->products['featured'] = $productModel->getProductListing('featured', 6);
$productModel->addImages($this->products['featured'],1);
}
if (VmConfig::get('show_latest', 1)) {
$this->products['latest']= $productModel->getProductListing('latest', 6);
$productModel->addImages($this->products['latest'],1);
}

if (VmConfig::get('show_topTen', 1)) {
$this->products['topten']= $productModel->getProductListing('topten', 6);
$productModel->addImages($this->products['topten'],1);
}


So, you have just to change the number "6" of the above example for featured, latest, topten.

By the way, the best solution IMHO is to change the original view.html.php file instead of that, but in case you don't show large amount of products in vm flypage you can use it.

Hopefully the developers should place an option in the BE with the max number of products for the fly page.

Hope it helps you out.

Regards,

Bytelord
Title: Re: Is possible to override html.php files?
Post by: Milbo on August 19, 2012, 16:57:09 PM
Hmmm, seems to be a requested feature.

I think we should just remove it from the view.html.php and do it only in teh layouts. then everyone can easily overwrite it.
Title: Re: Is possible to override html.php files?
Post by: bytelord on August 19, 2012, 17:18:52 PM
Hello Milbo,

It could be in the BE with some extra configuration options and stay in view. See attached.



[attachment cleanup by admin]
Title: Re: Is possible to override html.php files?
Post by: concap on March 04, 2013, 05:36:32 AM
Would be very handy to overwrite view.html.php
Title: Re: Is possible to override html.php files?
Post by: panoss on January 02, 2018, 17:47:35 PM
I raise this topic from the dead ( ;D) to ask if now is possible to overwrite a view.html.php file.
I want to override this file of the category view in order to modify a query it contains (although a view.html.php is not the best place for a query...).

Ok, I could do it in the layout (I think this is gonna be the solution), but it wouldn't be such an elegant solution or efficient (the code of view.html.php will have to be run twice)
Title: Re: Is possible to override html.php files?
Post by: panoss on January 03, 2018, 08:50:22 AM
In Joomla! a view.html.php can be overriden with a plugin (https://community.joomla.org/blogs/community/did-you-know-overrides-are-not-just-for-html.html).
Can this be done for Virtuemart?

I created a joomla plugin, installed it but the code in it's function onAfterRoute() does not get called:

public function onAfterRoute() { 
        var_dump('PlgModVMView onAfterRoute');
}


EDIT: a mistake I 've made (I think) is in the name of my plugin.
In the above posted link, in the example, the plugin 's name is: plgSystemComContentOverride
So, should I name it plgSystemComVirtuemartOverride?
Does the name have something to do with it?
Should it be a system plugin?
Title: Re: Is possible to override html.php files?
Post by: Studio 42 on January 03, 2018, 14:19:04 PM
You need to use right folder with right name
plgSystemComVirtuemartOverride
Need to be in folder plugins/system/comvirtuemartoverride and file name comvirtuemartoverride.php else this get not loaded by Joomla.
Title: Re: Is possible to override html.php files?
Post by: panoss on January 03, 2018, 16:55:25 PM
Thank you my friend, it works! (in the xml file I put 'group="system" ', so it got installed correctly in  plugins/system/comvirtuemartoverride)
Now, the plugin 's function onAfterRoute is called before the code in view.html.php.
So, how shall I continue now?

This is what I 've done so far:

public function onAfterRoute() {
        $app = JFactory::getApplication();
        $jinput = $app->input;
        $option = $jinput->get('option', '');
        $view = $jinput->get('view', '');
        $layout = $jinput->get('layout', '');
       

        if ($option && $view && !$layout && !$app->isAdmin()) {       
           
            if ($option == 'com_virtuemart' && $view = 'category' && $layout == '') {
                var_dump('plgSystemComVirtuemartOverride HERE WE aRE!!');
            }
        }


So, should I put something like to say 'override this class' (VirtuemartViewCategory) ?
Something like: (???)
require_once(dirname(__FILE__) . DS .

???
Title: Re: Is possible to override html.php files?
Post by: Studio 42 on January 03, 2018, 20:16:47 PM
You have to name the class same as the origianl class to overide, copy the original file, modify it and require the file.
Class name is important, not filename or path
Title: Re: Is possible to override html.php files?
Post by: panoss on January 04, 2018, 12:59:05 PM
1. I copied file \components\com_virtuemart\views\virtuemart\view.html.php
to \plugins\system\comvirtuemartoverride\view.html.php

2. In function onAfterRoute I put:
require_once(dirname(__FILE__) . DS . 'view.html.php');


And I get a warning on line 23 of view.html.php:
Warning: require(VMPATH_SITE\helpers\vmview.php): failed to open stream:
No such file or directory in \plugins\system\comvirtuemartoverride\view.html.php on line 23

Line 23 of view.html.php contains:
if(!class_exists('VmView'))require(VMPATH_SITE.DS.'helpers'.DS.'vmview.php');

So I suppose I 'll have to modify the path from VMPATH_SITE.DS.'helpers' to something else?
Title: Re: Is possible to override html.php files?
Post by: Studio 42 on January 04, 2018, 14:33:46 PM
YOu need to load the config.
Check in any VM core modules, how they do.
Title: Re: Is possible to override html.php files?
Post by: panoss on January 04, 2018, 18:21:39 PM
Before "if(!class_exists('VmView')....", I put this :
if (!class_exists( 'VmConfig' )) require(JPATH_ROOT .'/administrator/components/com_virtuemart/helpers/config.php');
VmConfig::loadConfig();


And it works!! Thank you very very  much!!!