VirtueMart Forum

VirtueMart 2 + 3 + 4 => Templating & Layouts => Topic started by: bardius on December 22, 2011, 16:59:33 PM

Title: Adding more extra model variables in a view
Post by: bardius on December 22, 2011, 16:59:33 PM
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.