Project

General

Profile

Product Plugins » History » Version 7

Ondra Spilka, 03/01/2012 02:40 PM

1 1 Patrick Kohl
h1. Product Plugins
2
3
h2. for user  
4
5
The product plugin is installed as a standard joomla plugin
6
7
To see it you must publish it in joomla extention after installation.
8
9 2 Patrick Kohl
After you do that, you can find it in the customfields on edit Choice : 
10
*Custom Field Type* : plugin
11 1 Patrick Kohl
12
After choicing the plugin you can setup the defaut value depending on your plugin.
13
14
h2. for developper.
15
16
h3. Language files :
17
18
XML install file must use the name in this form plg_vmcustom_YOURPLUGINNAME
19
20
EG. for textinput french and english
21
    <languages>
22
        <language tag="en-GB">en-GB.plg_vmcustom_textinput.ini</language>
23
        <language tag="fr-FR">fr-FR.plg_vmcustom_textinput.ini</language>
24
    </languages>
25
26
the constructor include directly the language file to simplify using JTEXT
27
28
Try to always use this convention name in the ini files :
29
VMCUSTOM_YOURPLUGINNAME_STRING="my string in english"
30
31
EG. for texinput plugin , string : size
32
VMCUSTOM_TEXTINPUT_INPUT_SIZE="Size of input"
33
34
h3. Write your plugin :
35
36 7 Ondra Spilka
Product plugin is always created from *vmCustomPlugin* base class eg...
37
<pre>
38
class plgvmcustomvmcalendar extends vmCustomPlugin {
39
40
	function __construct(& $subject, $config) {
41
		parent::__construct($subject, $config);
42
43
		$this->_tablepkey = 'id';
44
		$this->tableFields = array_keys($this->getTableSQLFields());
45
		$varsToPush = array(	'from'=>array('1977-01-01','date'), 'to'=>array('1977-01-01','date')
46
		);
47
48
		$this->setConfigParameterable('custom_params',$varsToPush);
49
	}
50
51
</pre>
52
53 2 Patrick Kohl
_List of function to write in your plugin_
54
55
*onProductEdit($field,$param,$row, $product_id);*
56
57
	render the plugin with param  to display on product edit customfields TAB
58
	(called by customfields inputTypePlugin)
59
60
*onDisplayProductFE( $field, $param, $product, $idx);*
61
62
	display the plugin on product FE
63
	return $html
64
65
*onViewCartModule( $product,$custom_param,$productCustom, $row);*
66
	display the product plugin on cart module
67
	return $html
68
	
69
*onViewCart($product, $param,$productCustom, $row);*
70
	display the product plugin on cart
71
	return $html
72
	
73
*onViewCartOrder($product, $param,$productCustom, $row)*
74
	handel $param before adding it in the order
75
	return $param;
76
	
77
	
78
*onViewOrderFE($item, $param,$productCustom, $row);*
79
	display the plugin in order for customers
80
	$item is the order item line
81
	Eg. to Get the statut ( $item->order_status == 'S'  )
82
	
83
*onViewOrderBE($item, $param,$productCustom, $row);*
84
	display the plugin in order for vendor
85
	$item is the order item line
86
87
	
88
*modifyPrice( $product, $field,$param,$selected )*
89
	overide the defaut price modifation by plugin
90
	you have to rewrite it in your plugin to do other calculations
91
	
92
	_you must return $field->custom_price at end to include your changes or the price varaint is set to 0;_
93 1 Patrick Kohl
94 7 Ondra Spilka
*plgVmGetProductStockToUpdateByCustom(&$product,$param, $productCustom)*
95
        Gets called after cart item is stored to database. 
96
        Developer can read product and parameters and eventually do own modifications.
97
        $param contains plugin values(if applicable) so developer can read those values
98
        Necessary check have to be performed...here check against field is not possible
99
        so eg. at least such a vaidation have to be done:
100
<pre>
101
		if ( !empty($param['vmcalendar']) && is_array($param['vmcalendar']))
102
		{
103
			$rf = $param['vmcalendar']['reservation_from'];
104
			$rt = $param['vmcalendar']['reservation_to'];
105
                        ....
106 5 Ondra Spilka
107 7 Ondra Spilka
</pre>
108 3 Patrick Kohl
h3. Use of plugin XML parameters :
109
110
*XML Exemple for textinput*
111
<pre>
112
<?xml version="1.0" encoding="UTF-8" ?>
113
<install version="1.5" type="plugin" group="vmcustom" >	
114
    <name>VMCustom - textinput</name>
115
    <creationDate>June 2011</creationDate>
116
    <author>The VirtueMart Development Team</author>
117
    <authorUrl>http://www.virtuemart.net</authorUrl>
118
    <copyright>Copyright (C) 2004-2011 Virtuemart Team. All rights reserved.</copyright>
119
    <license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>
120
    <version>1.9.8</version>
121
    <description>text input plugin for product</description>
122
    <languages>
123
        <language tag="en-GB">en-GB.plg_vmcustom_textinput.ini</language>
124
        <language tag="fr-FR">fr-FR.plg_vmcustom_textinput.ini</language>
125
    </languages>
126
    <files>
127
        <filename plugin="textinput">textinput.php</filename>
128
    </files>
129
    <params addpath="/administrator/components/com_virtuemart/elements">
130
        <param type="vmjpluginwarning" />
131
        <param name="custom_name" type="text" size="20"  default="COM_VIRTUEMART_COMMENT" label="VMCUSTOM_NAME_INFO" description="VMCUSTOM_NAME_INFO_DESC" />
132
        <param name="custom_size" type="text"  size="5"  default="10" label="VMCUSTOM_TEXTINPUT_SIZE" description="VMCUSTOM_TEXTINPUT_SIZE_DESC" />
133
        <param name="custom_price_by_letter" type="list"  default="0" label="VMCUSTOM_PRICE_BY_LETTER" description="VMCUSTOM_PRICE_BY_LETTER_DESC" >
134
			<option value="0">No</option>
135
			<option value="1">Yes</option>
136
		</param>		
137
    </params>
138
</install>
139
</pre>
140 1 Patrick Kohl
141 5 Ondra Spilka
*You can see somes differences with joomla standard XML files :*
142 3 Patrick Kohl
143
<pre>
144
<install version="1.5" type="plugin" group="vmcustom" >	
145
</pre>
146 4 Patrick Kohl
147 3 Patrick Kohl
inform joomla the plugin is a "vmcustom" plugin(product customfield plugin)
148
149
150
<pre>
151
    <params addpath="/administrator/components/com_virtuemart/elements">
152
</pre>
153 4 Patrick Kohl
154 3 Patrick Kohl
Overide the joomla system by virtuemart 2 to enchance it.
155
_Always add this or your plugin have chance to not work_
156
157
158 4 Patrick Kohl
<pre>
159 3 Patrick Kohl
        <param type="vmjpluginwarning" />
160
</pre>
161 1 Patrick Kohl
162
inform that the parameters are saved by virtuemart2 for each plugin variant.
163 4 Patrick Kohl
164
h3. transmited parameters by functions
165
166
*$product_id*
167
is the selected product_id
168 1 Patrick Kohl
169
*$product*
170 4 Patrick Kohl
is the selected product
171
172 5 Ondra Spilka
*$param*
173
 are the plugin parameters
174 4 Patrick Kohl
175
*$productCustom ,$field*
176
 are the product customfield attributes
177
178
*$selected,$row or $idx*
179
 is the parameter to find or write the right "index/row"
180
181
182
TODO : add more details for parameters
183
184
_See texinput plugin for eg._