Author Topic: Is possible to override html.php files?  (Read 3512 times)

The_nino

  • Beginner
  • *
  • Posts: 11
Is possible to override html.php files?
« 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!

The_nino

  • Beginner
  • *
  • Posts: 11
Re: Is possible to override html.php files?
« Reply #1 on: June 10, 2012, 10:33:02 am »
Nobody??

srajca

  • Jr. Member
  • **
  • Posts: 146
Re: Is possible to override html.php files?
« Reply #2 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

bytelord

  • Nikos
  • Global Moderator
  • Hero Member
  • *
  • Posts: 2369
Re: Is possible to override html.php files?
« Reply #3 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:

Code: [Select]
//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

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9450
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Is possible to override html.php files?
« Reply #4 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.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

bytelord

  • Nikos
  • Global Moderator
  • Hero Member
  • *
  • Posts: 2369
Re: Is possible to override html.php files?
« Reply #5 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]
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

  • Beginner
  • *
  • Posts: 41
Re: Is possible to override html.php files?
« Reply #6 on: March 04, 2013, 05:36:32 am »
Would be very handy to overwrite view.html.php

panoss

  • Jr. Member
  • **
  • Posts: 96
  • A beginner
Re: Is possible to override html.php files?
« Reply #7 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)
Virtuemart 3.2.4 on Joomla! 3.8.0

panoss

  • Jr. Member
  • **
  • Posts: 96
  • A beginner
Re: Is possible to override html.php files?
« Reply #8 on: January 03, 2018, 08:50:22 am »
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:
Code: [Select]
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2552
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Is possible to override html.php files?
« Reply #9 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.

panoss

  • Jr. Member
  • **
  • Posts: 96
  • A beginner
Re: Is possible to override html.php files?
« Reply #10 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:
Code: [Select]
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: (???)
Code: [Select]
require_once(dirname(__FILE__) . DS .
???
Virtuemart 3.2.4 on Joomla! 3.8.0

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2552
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Is possible to override html.php files?
« Reply #11 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

panoss

  • Jr. Member
  • **
  • Posts: 96
  • A beginner
Re: Is possible to override html.php files?
« Reply #12 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:
Code: [Select]
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:
Code: [Select]
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

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2552
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3.0.x.y
Re: Is possible to override html.php files?
« Reply #13 on: January 04, 2018, 14:33:46 pm »
YOu need to load the config.
Check in any VM core modules, how they do.

panoss

  • Jr. Member
  • **
  • Posts: 96
  • A beginner
Re: Is possible to override html.php files?
« Reply #14 on: January 04, 2018, 18:21:39 pm »
Before "if(!class_exists('VmView')....", I put this :
Code: [Select]
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