News:

Support the VirtueMart project and become a member

Main Menu

Adding more extra model variables in a view

Started by bardius, December 22, 2011, 16:59:33 PM

Previous topic - Next topic

bardius

If for any case you need to add an extra model variable, other than the supported ones, at a view, lets suppose you want to display the vendor store name at products details you can do it with a a small hack.

Firstly, you have to edit the controller file components\com_virtuemart\controllers\productdetails.php (line 60)
         
//GEORGE BARDIS adding Vendor model to product details
/* Vendor functions */
$view->setModel( $this->getModel( 'vendor', 'VirtuemartModel' ));
//BARDIS ENDS

So you have added the functions of vendor, net thing to do is to use that function at the view file components\com_virtuemart\views\productdetails\view.html.php (line 157, for example we change the title of the page)

//GEORGE BARDIS correction title for SEO
$vendorModel = $this->getModel('vendor');
$vendorModel->setId($product->virtuemart_vendor_id);
$vendor = $vendorModel->getVendor();
$this->assignRef('vendor',$vendor);
$document->setTitle( strip_tags(($category->category_name?($category->category_name.' : '):'').$product->product_name).' - '.$vendor->vendor_store_name);
//Bardis ENDS

Or you can use it like a regular template overwrite afterwards. Ina ny case, this is the logic to provide more build in fuctions to the required model.

Hope you find that one useful.
George Bardis
Team Leader / Senior Web Developer
http://www.bardis.info