VirtueMart 2 > Frontend Modules VM 2

How to code a new viruemart module

(1/2) > >>

techmodule:
Hi every one
I am newbee
I want to make a single virtuemart module
The main works:
- Show product images, example when i open the ABC product, it will show image of ABC.
Any one can guild me how to do, thank you

ivus:
Hi techmodule,

perhaps I'm missing something???? but doesn't IMAGES already show when you open the ABC product by default?

If you want to learn how to create modules, you can read all about it (with examples for you to follow and download) over on the Joomla! site.

http://docs.joomla.org/Creating_a_Hello_World_Module_for_Joomla_1.5

It's pretty much the same for 2.5

Good luck.

techmodule:
Dear
I mean that.
the name of product: ABC
the image is abc.jpg
in normally, the image will show on views/productdetails/tmpl/defaul.php
But the possition only in content possition
But i want to know create a module that will show abc.jpg on every possition i want, for example "left" possition
Do you understand me?
I have write an module by my self, but it not run, can you check the attached file for me

ivus:
Hi techmodule,

Your code won't run because it is not well formed.
Firstly we're working in PHP, and technically the only files that should contain any HTML elements in the VIEWS file, which means the first line of most of your code should read <?php and not <html

You should also name your modules so that they are easily recognisable, this is just a rule-of-thumb. You have "mod_medias", better if you called it "mod_virtuemart_medias"

Anyway... here's how you do it : (code is provided for anyone else wanting a solution ;D )


File Structure :

|- [mod_virtuemart_medias]
     |-- [tmpl]
     |     |- default.php
     |     |- index.html
     |-- helper.php
     |-- index.html
     |-- mod_virtuemart_medias.php
     |-- mod_virtuemart_medias.xml


mod_virtuemart_medias.xml

--- Code: ---
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE install SYSTEM "http://www.joomla.org/xml/dtd/1.5/module-install.dtd">
<install type="module" version="1.5.0">
    <name>VirtueMart Media Display</name>
    <creationDate>August 21 2012</creationDate>
    <author>Your Name here</author>
    <authorUrl>http://www.domain.com</authorUrl>
    <copyright>Copyright (C) 2004-2012 Virtuemart Team. All rights reserved.</copyright>
    <license>http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL</license>
    <version>1.0.0</version>
    <description>Displays Virtuemart product images in module position for the specified product</description>
    <files>
<filename module="mod_virtuemart_medias">mod_virtuemart_medias.php</filename>
<filename>index.html</filename>
<filename>helper.php</filename>
<filename>tmpl/default.php</filename>
<filename>tmpl/index.html</filename>
    </files>
<params>
</params>
</install>


--- End code ---

mod_virtuemart_medias.php

--- Code: ---
<?php
defined('_JEXEC') or die; 

require_once dirname(__FILE__).'/helper.php'; 

$id = JRequest::getInt('virtuemart_product_id'); 
$images = modVmMediasHelper::getMedias($id); 

require JModuleHelper::getLayoutPath('mod_virtuemart_medias', $params->get('layout', 'default')); 


--- End code ---

helper.php

--- Code: ---
<?php
defined('_JEXEC') or die; 

class modVmMediasHelper {
 
static function getMedias($id) { 
$productModel = VmModel::getModel('product');
return $productModel->getProduct($id);


}  


--- End code ---

default.php

--- Code: ---
<?php
defined('_JEXEC') or die; 

echo $images->images[0]->displayMediaThumb('', false);
echo '<br>';
echo $images->images[0]->displayMediaFull('class="medium-image" id="medium-image"', false);


--- End code ---



That should be enough to get you started. Good luck.

ivus ;D

techmodule:
Thank you so much, i have just do it, it run, thank you

Navigation

[0] Message Index

[#] Next page

Go to full version