News:

Looking for documentation? Take a look on our wiki

Main Menu

Is possible to override html.php files?

Started by The_nino, June 04, 2012, 14:39:46 PM

Previous topic - Next topic

The_nino

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!


srajca

hey the nino, have youo managed to override this? I would like to do the same. thnx

bytelord

#3
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
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bytelord

#5
Hello Milbo,

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



[attachment cleanup by admin]
Production: Joomla 2.5.8 | VM 2.0.14 | PHP 5.3.13
Testing     : Joomla 2.5.8 | VM 2.0.16 | PHP 5.3.8
Testing     : Joomla 2.5.8 |    VM 2.1   | PHP 5.3.8

- Don't Forget to mark thread as solved when it is solved!
- Please do not PM with support questions, use the forum!

concap

Would be very handy to overwrite view.html.php

panoss

#7
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)
Virtuemart 3.2.4 on Joomla! 3.8.0

panoss

#8
In Joomla! a view.html.php can be overriden with a plugin.
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?
Virtuemart 3.2.4 on Joomla! 3.8.0

Studio 42

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.

panoss

#10
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 .

???
Virtuemart 3.2.4 on Joomla! 3.8.0

Studio 42

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

panoss

#12
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?
Virtuemart 3.2.4 on Joomla! 3.8.0

Studio 42

YOu need to load the config.
Check in any VM core modules, how they do.

panoss

#14
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!!!
Virtuemart 3.2.4 on Joomla! 3.8.0