Product Plugins » History » Version 8
Ondra Spilka, 03/01/2012 03:32 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 | 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 | 8 | Ondra Spilka | *currently (2.0.2) not implemented/obsolete* |
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 | Eg. to Get the statut ( $item->order_status == 'S' ) |
||
82 | 8 | Ondra Spilka | *currently (2.0.2) not implemented* |
83 | 2 | Patrick Kohl | |
84 | 8 | Ondra Spilka | *plgVmDisplayInOrderBE($item, $param,$productCustom, $row);* |
85 | 2 | Patrick Kohl | display the plugin in order for vendor |
86 | $item is the order item line |
||
87 | 8 | Ondra Spilka | *currently (2.0.2) not implemented* |
88 | 2 | Patrick Kohl | |
89 | |||
90 | *modifyPrice( $product, $field,$param,$selected )* |
||
91 | overide the defaut price modifation by plugin |
||
92 | you have to rewrite it in your plugin to do other calculations |
||
93 | |||
94 | _you must return $field->custom_price at end to include your changes or the price varaint is set to 0;_ |
||
95 | 1 | Patrick Kohl | |
96 | 7 | Ondra Spilka | *plgVmGetProductStockToUpdateByCustom(&$product,$param, $productCustom)* |
97 | Gets called after cart item is stored to database. |
||
98 | Developer can read product and parameters and eventually do own modifications. |
||
99 | $param contains plugin values(if applicable) so developer can read those values |
||
100 | Necessary check have to be performed...here check against field is not possible |
||
101 | so eg. at least such a vaidation have to be done: |
||
102 | 1 | Patrick Kohl | <pre> |
103 | if ( !empty($param['vmcalendar']) && is_array($param['vmcalendar'])) |
||
104 | { |
||
105 | 7 | Ondra Spilka | $rf = $param['vmcalendar']['reservation_from']; |
106 | $rt = $param['vmcalendar']['reservation_to']; |
||
107 | .... |
||
108 | |||
109 | </pre> |
||
110 | 8 | Ondra Spilka | |
111 | *See samples - specification/stockable/textinput to get inspiration and know-how* |
||
112 | |||
113 | 3 | Patrick Kohl | h3. Use of plugin XML parameters : |
114 | |||
115 | *XML Exemple for textinput* |
||
116 | <pre> |
||
117 | <?xml version="1.0" encoding="UTF-8" ?> |
||
118 | <install version="1.5" type="plugin" group="vmcustom" > |
||
119 | <name>VMCustom - textinput</name> |
||
120 | <creationDate>June 2011</creationDate> |
||
121 | <author>The VirtueMart Development Team</author> |
||
122 | <authorUrl>http://www.virtuemart.net</authorUrl> |
||
123 | <copyright>Copyright (C) 2004-2011 Virtuemart Team. All rights reserved.</copyright> |
||
124 | <license>http://www.gnu.org/licenses/gpl-3.0.html GNU/GPL</license> |
||
125 | <version>1.9.8</version> |
||
126 | <description>text input plugin for product</description> |
||
127 | <languages> |
||
128 | <language tag="en-GB">en-GB.plg_vmcustom_textinput.ini</language> |
||
129 | <language tag="fr-FR">fr-FR.plg_vmcustom_textinput.ini</language> |
||
130 | </languages> |
||
131 | <files> |
||
132 | <filename plugin="textinput">textinput.php</filename> |
||
133 | </files> |
||
134 | <params addpath="/administrator/components/com_virtuemart/elements"> |
||
135 | <param type="vmjpluginwarning" /> |
||
136 | <param name="custom_name" type="text" size="20" default="COM_VIRTUEMART_COMMENT" label="VMCUSTOM_NAME_INFO" description="VMCUSTOM_NAME_INFO_DESC" /> |
||
137 | <param name="custom_size" type="text" size="5" default="10" label="VMCUSTOM_TEXTINPUT_SIZE" description="VMCUSTOM_TEXTINPUT_SIZE_DESC" /> |
||
138 | <param name="custom_price_by_letter" type="list" default="0" label="VMCUSTOM_PRICE_BY_LETTER" description="VMCUSTOM_PRICE_BY_LETTER_DESC" > |
||
139 | <option value="0">No</option> |
||
140 | <option value="1">Yes</option> |
||
141 | </param> |
||
142 | </params> |
||
143 | </install> |
||
144 | </pre> |
||
145 | 1 | Patrick Kohl | |
146 | 5 | Ondra Spilka | *You can see somes differences with joomla standard XML files :* |
147 | 3 | Patrick Kohl | |
148 | <pre> |
||
149 | <install version="1.5" type="plugin" group="vmcustom" > |
||
150 | </pre> |
||
151 | 4 | Patrick Kohl | |
152 | 3 | Patrick Kohl | inform joomla the plugin is a "vmcustom" plugin(product customfield plugin) |
153 | |||
154 | |||
155 | <pre> |
||
156 | <params addpath="/administrator/components/com_virtuemart/elements"> |
||
157 | </pre> |
||
158 | 4 | Patrick Kohl | |
159 | 3 | Patrick Kohl | Overide the joomla system by virtuemart 2 to enchance it. |
160 | _Always add this or your plugin have chance to not work_ |
||
161 | |||
162 | |||
163 | 4 | Patrick Kohl | <pre> |
164 | 3 | Patrick Kohl | <param type="vmjpluginwarning" /> |
165 | </pre> |
||
166 | 1 | Patrick Kohl | |
167 | inform that the parameters are saved by virtuemart2 for each plugin variant. |
||
168 | 4 | Patrick Kohl | |
169 | h3. transmited parameters by functions |
||
170 | |||
171 | *$product_id* |
||
172 | is the selected product_id |
||
173 | 1 | Patrick Kohl | |
174 | *$product* |
||
175 | 4 | Patrick Kohl | is the selected product |
176 | |||
177 | 5 | Ondra Spilka | *$param* |
178 | are the plugin parameters |
||
179 | 4 | Patrick Kohl | |
180 | *$productCustom ,$field* |
||
181 | are the product customfield attributes |
||
182 | |||
183 | *$selected,$row or $idx* |
||
184 | is the parameter to find or write the right "index/row" |
||
185 | |||
186 | |||
187 | TODO : add more details for parameters |
||
188 | |||
189 | _See texinput plugin for eg._ |