News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

How to code a new viruemart module

Started by techmodule, August 20, 2012, 04:42:39 AM

Previous topic - Next topic

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

#2
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


[attachment cleanup by admin]

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


<?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>



mod_virtuemart_medias.php


<?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')); 



helper.php


<?php
defined
('_JEXEC') or die; 

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


}  



default.php


<?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);





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

techmodule

Quote from: ivus on August 21, 2012, 10:50:19 AM
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


<?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>



mod_virtuemart_medias.php


<?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')); 



helper.php


<?php
defined
('_JEXEC') or die; 

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


}  



default.php


<?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);





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

ivus ;D
Dear
I have new question
I upload my module again
I try to use fancy box to show thumnail, and light box, but it not run
Can you teach me again
the link demo http://vinaplaza.vn/index.php/hop-dung-giay-vs-co-lon/dong-thong-dung2012-07-28-13-24-39/hop-dung-giay-ve-sinh-cuon-lon-inox-tmyg-a723l-detail
Thank you

[attachment cleanup by admin]

ivus

@techmodule,

no need to quote my entire post as it is available in this thread...

Quote
I try to use fancy box to show thumnail, and light box, but it not run
Can you teach me again

it works just fine for me.



[attachment cleanup by admin]

techmodule

Dear
That pic you post is not used in the module, it is in productsdetail,
if i use the mod_medias that runs (it coded by my seft)
if i use the mod_virtuemart_medias (your code), it not runs
plz check both of them for me
Thank you

[attachment cleanup by admin]