Project

General

Profile

Product Plugins » History » Version 10

Ondra Spilka, 03/01/2012 03:57 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 9 Ondra Spilka
Product plugin is inherited from *vmCustomPlugin* base class eg...
37 7 Ondra Spilka
<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 8 Ondra Spilka
*plgVmOnProductEdit($field,$param,$row, $product_id);*
56 2 Patrick Kohl
57
	render the plugin with param  to display on product edit customfields TAB
58
	(called by customfields inputTypePlugin)
59
60 8 Ondra Spilka
*plgVmOnDisplayProductFE( $field, $param, $product, $idx);*
61 2 Patrick Kohl
62
	display the plugin on product FE
63
	return $html
64
65 8 Ondra Spilka
*plgVmOnViewCartModule( $product,$custom_param,$productCustom, $row);*
66 2 Patrick Kohl
	display the product plugin on cart module
67
	return $html
68
	
69 8 Ondra Spilka
*plgVmOnViewCart($product, $param,$productCustom, $row);*
70 2 Patrick Kohl
	display the product plugin on cart
71 1 Patrick Kohl
	return $html
72 2 Patrick Kohl
	
73 8 Ondra Spilka
*plgVmOnViewCartOrder($product, $param,$productCustom, $row)*
74 2 Patrick Kohl
	handel $param before adding it in the order
75 1 Patrick Kohl
	return $param;
76 10 Ondra Spilka
77 2 Patrick Kohl
	
78 8 Ondra Spilka
*plgVmDisplayInOrderFE($item, $param,$productCustom, $row);*
79 1 Patrick Kohl
	display the plugin in order for customers
80 2 Patrick Kohl
	$item is the order item line
81 8 Ondra Spilka
	Eg. to Get the statut ( $item->order_status == 'S'  )
82 2 Patrick Kohl
	
83 8 Ondra Spilka
*plgVmDisplayInOrderBE($item, $param,$productCustom, $row);*
84 2 Patrick Kohl
	display the plugin in order for vendor
85 8 Ondra Spilka
	$item is the order item line
86 2 Patrick Kohl
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 1 Patrick Kohl
<pre>
101
		if ( !empty($param['vmcalendar']) && is_array($param['vmcalendar']))
102
		{
103 7 Ondra Spilka
			$rf = $param['vmcalendar']['reservation_from'];
104
			$rt = $param['vmcalendar']['reservation_to'];
105
                        ....
106
107
</pre>
108 8 Ondra Spilka
109
*See samples - specification/stockable/textinput to get inspiration and know-how*
110
111 3 Patrick Kohl
h3. Use of plugin XML parameters :
112
113
*XML Exemple for textinput*
114
<pre>
115
<?xml version="1.0" encoding="UTF-8" ?>
116
<install version="1.5" type="plugin" group="vmcustom" >	
117
    <name>VMCustom - textinput</name>
118
    <creationDate>June 2011</creationDate>
119
    <author>The VirtueMart Development Team</author>
120
    <authorUrl>http://www.virtuemart.net</authorUrl>
121
    <copyright>Copyright (C) 2004-2011 Virtuemart Team. All rights reserved.</copyright>
122
    <license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license>
123
    <version>1.9.8</version>
124
    <description>text input plugin for product</description>
125
    <languages>
126
        <language tag="en-GB">en-GB.plg_vmcustom_textinput.ini</language>
127
        <language tag="fr-FR">fr-FR.plg_vmcustom_textinput.ini</language>
128
    </languages>
129
    <files>
130
        <filename plugin="textinput">textinput.php</filename>
131
    </files>
132
    <params addpath="/administrator/components/com_virtuemart/elements">
133
        <param type="vmjpluginwarning" />
134
        <param name="custom_name" type="text" size="20"  default="COM_VIRTUEMART_COMMENT" label="VMCUSTOM_NAME_INFO" description="VMCUSTOM_NAME_INFO_DESC" />
135
        <param name="custom_size" type="text"  size="5"  default="10" label="VMCUSTOM_TEXTINPUT_SIZE" description="VMCUSTOM_TEXTINPUT_SIZE_DESC" />
136
        <param name="custom_price_by_letter" type="list"  default="0" label="VMCUSTOM_PRICE_BY_LETTER" description="VMCUSTOM_PRICE_BY_LETTER_DESC" >
137
			<option value="0">No</option>
138
			<option value="1">Yes</option>
139
		</param>		
140
    </params>
141
</install>
142
</pre>
143 1 Patrick Kohl
144 5 Ondra Spilka
*You can see somes differences with joomla standard XML files :*
145 3 Patrick Kohl
146
<pre>
147
<install version="1.5" type="plugin" group="vmcustom" >	
148
</pre>
149 4 Patrick Kohl
150 3 Patrick Kohl
inform joomla the plugin is a "vmcustom" plugin(product customfield plugin)
151
152
153
<pre>
154
    <params addpath="/administrator/components/com_virtuemart/elements">
155
</pre>
156 4 Patrick Kohl
157 3 Patrick Kohl
Overide the joomla system by virtuemart 2 to enchance it.
158
_Always add this or your plugin have chance to not work_
159
160
161 4 Patrick Kohl
<pre>
162 3 Patrick Kohl
        <param type="vmjpluginwarning" />
163
</pre>
164 1 Patrick Kohl
165
inform that the parameters are saved by virtuemart2 for each plugin variant.
166 4 Patrick Kohl
167
h3. transmited parameters by functions
168
169
*$product_id*
170
is the selected product_id
171 1 Patrick Kohl
172
*$product*
173 4 Patrick Kohl
is the selected product
174
175 5 Ondra Spilka
*$param*
176
 are the plugin parameters
177 4 Patrick Kohl
178
*$productCustom ,$field*
179
 are the product customfield attributes
180
181
*$selected,$row or $idx*
182
 is the parameter to find or write the right "index/row"
183
184
185
TODO : add more details for parameters
186
187
_See texinput plugin for eg._