{"id":149,"date":"2009-06-18T01:57:43","date_gmt":"2009-06-17T23:57:43","guid":{"rendered":"http:\/\/kavdesign.net\/wordpress\/?p=149"},"modified":"2010-04-12T11:57:02","modified_gmt":"2010-04-12T09:57:02","slug":"how-to-make-an-extension-to-virtuemart-which-will-allow-you-to-add-distributors-to-the-products","status":"publish","type":"post","link":"https:\/\/www.kavdesign.net\/blog\/coding\/how-to-make-an-extension-to-virtuemart-which-will-allow-you-to-add-distributors-to-the-products\/","title":{"rendered":"How to make an extension to virtuemart which will allow you to add distributors and then chose distributor for each product?"},"content":{"rendered":"<p><!--:bg-->First I\u2019ll try to explain what needs to be achieved. If you have a big online store and you try to remember all your distributors (people and companies which you take your goods from and then you sell these goods to the customers) it won\u2019t be easy. Especially if there are more people working in your online shop. So the issue is that virtuemart doesn\u2019t have distributors support. What needs to be done is write an extension to virtuemart which will add distributors to the menu of modules (manufacturers, tax rates, vendors, ets.).<\/p>\n<p><!--more--><\/p>\n<p>This extension will allow you to add distributors (like you add manufacturers) and when you are in the product details page you will have the ability to choose the distributor from which this product comes from, the same way like you choose manufacturer of the product.<\/p>\n<p>So I used the manufacturers extension for base to create this distributors extension. And since I have no idea how to make a real extension which will install automatically I will write the steps here:<!--:--><!--:en-->First I\u2019ll try to explain what needs to be achieved. If you have a big online store and you try to remember all your distributors (people and companies which you take your goods from and then you sell these goods to the customers) it won\u2019t be easy. Especially if there are more people working in your online shop. So the issue is that virtuemart doesn\u2019t have distributors support. What needs to be done is write an extension to virtuemart which will add distributors to the menu of modules (manufacturers, tax rates, vendors, ets.).<\/p>\n<p>This extension will allow you to add distributors (like you add manufacturers) and when you are in the product details page you will have the ability to choose the distributor from which this product comes from, the same way like you choose manufacturer of the product.<\/p>\n<p>So I used the manufacturers extension for base to create this distributors extension. And since I have no idea how to make a real extension which will install automatically I will write the steps here:<!--:--><!--:bg--><\/p>\n<p><strong>1. Add one more menu item to the virtumart menu (virtuemart modules)<\/strong><\/p>\n<p>To do this go to the your-site\/administrator\/components\/com_virtuemart\/header.php and add one more menu item.<\/p>\n<p>Find this code: <em>case \u2018manufacturer\u2019:<\/em><\/p>\n<p>and paste this code before it:<\/p>\n<p><em> case \u2018distributor\u2019:<br \/>\n?&gt;<br \/>\n&lt;h3 class=\u201dtitle-smenu\u201d title=\u201ddistributor\u201d onclick=\u201dSwitchMenu(\u2019&lt;?php echo $modCount ?&gt;\u2019)\u201d&gt;<br \/>\n&lt;?php echo Distributor<br \/>\n?&gt;<br \/>\n&lt;\/h3&gt;<br \/>\n&lt;div class=\u201dsection-smenu\u201d&gt;<br \/>\n&lt;ul&gt;<br \/>\n&lt;li class=\u201ditem-smenu vmicon vmicon-16-content\u201d&gt;<br \/>\n&lt;a href=\u201d&lt;?php $sess-&gt;purl($_SERVER[&#8216;PHP_SELF&#8217;].\u201d?pshop_mode=admin&amp;amp;page=distributor.distributor_list\u201d) ?&gt;\u201d&gt;&lt;?php echo \u201cDistributor list\u201d ?&gt;&lt;\/a&gt;<br \/>\n&lt;\/li&gt;<br \/>\n&lt;li class=\u201ditem-smenu vmicon vmicon-16-editadd\u201d&gt;<br \/>\n&lt;a href=\u201d&lt;?php $sess-&gt;purl($_SERVER[&#8216;PHP_SELF&#8217;].\u201d?pshop_mode=admin&amp;amp;page=distributor.distributor_form\u201d) ?&gt;\u201d&gt;&lt;?php echo \u201cAdd distributor\u201d ?&gt;&lt;\/a&gt;<br \/>\n&lt;hr \/&gt;<br \/>\n&lt;\/li&gt;<br \/>\n&lt;\/ul&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;?php<br \/>\n$modCount++;<br \/>\nbreak;<\/em><\/p>\n<p><em><br \/>\n<\/em><\/p>\n<p><strong>2. Create a new table in the DB for example called <a class=\"item\" href=\"http:\/\/kavdesign.net:2082\/3rdparty\/phpMyAdmin\/tbl_structure.php?db=kavdesig_magazin6&amp;table=jos_vm_distributor_kefi&amp;token=b5819ad519cababad395d7f6fc9d0244\"> <\/a><span class=\"item\">jos_vm_distributor <\/span><\/strong><\/p>\n<p><span class=\"item\">I have created a table similar to the on for the manufacturers<\/span><strong><span class=\"item\"><br \/>\n<\/span><\/strong><\/p>\n<table id=\"tablestructure\" class=\"data\" border=\"0\">\n<thead>\n<tr>\n<th id=\"th2\">Field<\/th>\n<th id=\"th3\">Type<\/th>\n<th id=\"th4\">Collation<\/th>\n<th id=\"th5\">Attributes<\/th>\n<th id=\"th6\">Null<\/th>\n<th id=\"th7\">Default<\/th>\n<th id=\"th8\">Extra<\/th>\n<th id=\"th9\" colspan=\"7\">Action<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd marked\">\n<td align=\"center\"><input id=\"checkbox_row_1\" name=\"selected_fld[]\" type=\"checkbox\" value=\"distributor_id\" \/><\/td>\n<th><label for=\"checkbox_row_1\"><span style=\"text-decoration: underline;\">distributor_id<\/span><\/label><\/th>\n<td><bdo dir=\"ltr\" xml:lang=\"en\">int(11)<\/bdo><\/td>\n<td><\/td>\n<td style=\"font-size: 70%;\"><\/td>\n<td>No<\/td>\n<td><\/td>\n<td>auto_increment<\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<\/tr>\n<tr class=\"even\">\n<td align=\"center\"><input id=\"checkbox_row_2\" name=\"selected_fld[]\" type=\"checkbox\" value=\"d_name\" \/><\/td>\n<th><label for=\"checkbox_row_2\">d_name<\/label><\/th>\n<td><bdo dir=\"ltr\" xml:lang=\"en\">varchar(64)<\/bdo><\/td>\n<td><dfn title=\"Unicode (multilingual), case-insensitive\">utf8_general_ci<\/dfn><\/td>\n<td style=\"font-size: 70%;\"><\/td>\n<td>Yes<\/td>\n<td><em>NULL<\/em><\/td>\n<td><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<\/tr>\n<tr class=\"odd\">\n<td align=\"center\"><input id=\"checkbox_row_3\" name=\"selected_fld[]\" type=\"checkbox\" value=\"d_email\" \/><\/td>\n<th><label for=\"checkbox_row_3\">d_email<\/label><\/th>\n<td><bdo dir=\"ltr\" xml:lang=\"en\">varchar(255)<\/bdo><\/td>\n<td><dfn title=\"Unicode (multilingual), case-insensitive\">utf8_general_ci<\/dfn><\/td>\n<td style=\"font-size: 70%;\"><\/td>\n<td>Yes<\/td>\n<td><em>NULL<\/em><\/td>\n<td><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<\/tr>\n<tr class=\"even\">\n<td align=\"center\"><input id=\"checkbox_row_4\" name=\"selected_fld[]\" type=\"checkbox\" value=\"d_desc\" \/><\/td>\n<th><label for=\"checkbox_row_4\">d_desc<\/label><\/th>\n<td><bdo dir=\"ltr\" xml:lang=\"en\">text<\/bdo><\/td>\n<td><dfn title=\"Unicode (multilingual), case-insensitive\">utf8_general_ci<\/dfn><\/td>\n<td style=\"font-size: 70%;\"><\/td>\n<td>Yes<\/td>\n<td><em>NULL<\/em><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>3. Add the record for the distributors in the <span class=\"item\">jos_vm_module<\/span> table<\/strong><\/p>\n<p>Add a record to the DB like this one in the jos_vm_module table. Choose some ID and write the name \u201cdistributor\u201d, And don\u2019t forget to add Y to published.<\/p>\n<p>It is possible to do this 3-th step from the virtuemart backend -&gt; admin -&gt; list modules,\u00a0 but I\u2019m not sure.<\/p>\n<p><strong><br \/>\n<\/strong><\/p>\n<p><strong>4. Add some functions to the newly published module<\/strong>.<\/p>\n<p>Go to virtuemart backend -&gt; admin -&gt; list modules. Go to function list for the distributor module.<\/p>\n<p>Add this functions: distributorAdd, distributorDelete, distributorUpdate (see virtuemart manual for help with adding new functions)<\/p>\n<p><strong>5. Now create the files for the distributor. <\/strong><\/p>\n<p>&#8211; \/administrator\/components\/com_virtuemart\/html\/<a href=\"..\/stuff\/codes\/distributor.distributor_form.php\">distributor.distributor_form.php<\/a><\/p>\n<p>&#8211; \/administrator\/components\/com_virtuemart\/html\/<a href=\"..\/stuff\/codes\/distributor.distributor_list.php\">distributor.distributor_list.php<\/a><\/p>\n<p>-\/administrator\/components\/com_virtuemart\/classes\/<a href=\"..\/stuff\/codes\/ps_distributor.php\">ps_distributor.php<\/a><\/p>\n<p>You could download my files from here above.<\/p>\n<p><strong>6. Add the code to support distributors in the product details page. <\/strong><\/p>\n<p>(this is a helpfull article &#8211; <a title=\"Add a New Field to Products in Joomla! VirtueMart\" href=\"http:\/\/www.newcircleconsulting.com\/2008\/06\/10\/add-a-field-to-products-in-joomla-virtuemart\/\">Add a New Field to Products in Joomla! VirtueMart<\/a>)<\/p>\n<p><strong>6.1.<\/strong> First of all we have to ctreate a new table in the database which will link the distributors to the products. In my case it\u2019s called <em>jos_vm_product_dist_xref.<\/em><\/p>\n<p>You should do it the same way the\u00a0<em> jos_vm_product_mf_xref <\/em>is fone. Add the two fields and the two indexes to the table.<\/p>\n<p><strong>6.2.<\/strong> Open ps_product.html and add these lines:<\/p>\n<p>6.2.1. After these lines :<\/p>\n<p>if (empty($d[&#8216;manufacturer_id&#8217;])) {<br \/>\n$d[&#8216;manufacturer_id&#8217;] = \u201c1\u2033;<\/p>\n<p>}<\/p>\n<p>add<\/p>\n<p>if (empty($d[&#8216;distributor_id&#8217;])) {<br \/>\n$d[&#8216;distributor_id&#8217;] = \u201c1\u2033;<br \/>\n}<\/p>\n<p>6.2.2. Before:<\/p>\n<p>$q = \u201cINSERT INTO #__{vm}_product_mf_xref VALUES (\u201d;<br \/>\n$q .= \u201c\u2018\u201d.$d[&#8216;product_id&#8217;].\u201d\u2018, \u2018\u201d.vmRequest::getInt(\u2019manufacturer_id\u2019).\u201d\u2018)\u201d;<br \/>\n$db-&gt;setQuery($q); $db-&gt;query();<\/p>\n<p>add:<\/p>\n<p>$q = \u201cINSERT INTO #__{vm}_product_dist_xref VALUES (\u201d;<br \/>\n$q .= \u201c\u2018\u201d.$d[&#8216;product_id&#8217;].\u201d\u2018, \u2018\u201d.vmRequest::getInt(\u2019distributor_id\u2019).\u201d\u2018)\u201d;<br \/>\n$db-&gt;setQuery($q); $db-&gt;query();<\/p>\n<p>6.2.3. After:<\/p>\n<p>$q = \u201cUPDATE #__{vm}_product_mf_xref SET \u201c;<br \/>\n$q .= \u2018manufacturer_id=\u2019.vmRequest::getInt(\u2019manufacturer_id\u2019).\u2019 \u2018;<br \/>\n$q .= \u2018WHERE product_id = \u2018.$d[&#8216;product_id&#8217;];<br \/>\n$db-&gt;query($q);<\/p>\n<p>add:<\/p>\n<p>$q = \u201cUPDATE #__{vm}_product_dist_xref SET \u201c;<br \/>\n$q .= \u2018distributor_id=\u2019.vmRequest::getInt(\u2019distributor_id\u2019).\u2019 \u2018;<br \/>\n$q .= \u2018WHERE product_id = \u2018.$d[&#8216;product_id&#8217;];<br \/>\n$db-&gt;query($q);<\/p>\n<p>6.2.4. After:<\/p>\n<p>\/* Delete product &#8211; manufacturer xref *\/<br \/>\n$q = \u201cDELETE FROM #__{vm}_product_mf_xref WHERE product_id=\u2019$product_id\u2019\u201d;<br \/>\n$db-&gt;setQuery($q); $db-&gt;query();<\/p>\n<p>add:<\/p>\n<p>\/* Delete product &#8211; distributor xref *\/<br \/>\n$q = \u201cDELETE FROM #__{vm}_product_dist_xref WHERE product_id=\u2019$product_id\u2019\u201d;<br \/>\n$db-&gt;setQuery($q); $db-&gt;query();<\/p>\n<p>6.2.5. After this function :<\/p>\n<p>function get_manufacturer_id($product_id) {}<\/p>\n<p>add:<\/p>\n<p>\/**<br \/>\n* Function to get the distributor id the product $product_id is assigned to<br \/>\n* @author soeren<br \/>\n* @param int $product_id<br \/>\n* @return int The distributor id<br \/>\n*\/<br \/>\nfunction get_distributor_id($product_id) {<br \/>\n$db = new ps_DB;<\/p>\n<p>$q = \u201cSELECT distributor_id FROM #__{vm}_product_dist_xref \u201c;<br \/>\n$q .= \u201cWHERE product_id=\u2019$product_id\u2019 \u201c;<\/p>\n<p>$db-&gt;query($q);<br \/>\n$db-&gt;next_record();<br \/>\nif ($db-&gt;f(\u201ddistributor_id\u201d)) {<br \/>\nreturn $db-&gt;f(\u201ddistributor_id\u201d);<br \/>\n}<br \/>\nelse {<br \/>\nreturn false;<br \/>\n}<br \/>\n}<\/p>\n<p>6.2.6. After function get_mf_name($product_id) {}<\/p>\n<p>add<\/p>\n<p>\/**<br \/>\n* Functon to get the name of the distributor this product is assigned to<br \/>\n*<br \/>\n* @param int $product_id<br \/>\n* @return string the distributor name<br \/>\n*\/<br \/>\nfunction get_d_name($product_id) {<br \/>\n$db = new ps_DB;<\/p>\n<p>$q = \u201cSELECT d_name,#__{vm}_distributor_kefi.distributor_id FROM #__{vm}_product_dist_xref,#__{vm}_distributor_kefi \u201c;<br \/>\n$q .= \u201cWHERE product_id=\u2019$product_id\u2019 \u201c;<br \/>\n$q .= \u201cAND #__{vm}_distributor_kefi.distributor_id=#__{vm}_product_dist_xref.distributor_id\u201d;<\/p>\n<p>$db-&gt;query($q);<br \/>\n$db-&gt;next_record();<br \/>\nif ($db-&gt;f(\u201dd_name\u201d)) {<br \/>\nreturn $db-&gt;f(\u201dd_name\u201d);<br \/>\n}<br \/>\nelse {<br \/>\nreturn \u201c\u201d;<br \/>\n}<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Functon to get the id of the distributor this product is assigned to<br \/>\n*<br \/>\n* @param int $product_id<br \/>\n* @return string the distributor id<br \/>\n*\/<br \/>\nfunction get_d_id($product_id) {<br \/>\n$db = new ps_DB;<\/p>\n<p>$q = \u201cSELECT d_name,#__{vm}_distributor_kefi.distributor_id FROM #__{vm}_product_dist_xref,#__{vm}_distributor_kefi \u201c;<br \/>\n$q .= \u201cWHERE product_id=\u2019$product_id\u2019 \u201c;<br \/>\n$q .= \u201cAND #__{vm}_distributor_kefi.distributor_id=#__{vm}_product_dist_xref.distributor_id\u201d;<\/p>\n<p>$db-&gt;query($q);<br \/>\n$db-&gt;next_record();<br \/>\nif ($db-&gt;f(\u201ddistributor_id\u201d)) {<br \/>\nreturn $db-&gt;f(\u201ddistributor_id\u201d);<br \/>\n}<br \/>\nelse {<br \/>\nreturn \u201c\u201d;<br \/>\n}<br \/>\n}<\/p>\n<p>6.3. Open product.product_form.php and modify:<\/p>\n<p>6.3.1.After:<\/p>\n<p>require_once( CLASSPATH.\u2019ps_manufacturer.php\u2019 );<\/p>\n<p>add:<\/p>\n<p>require_once( CLASSPATH.\u2019ps_distributor.php\u2019 );<\/p>\n<p>6.3.2. After :<\/p>\n<p>\/\/ Get the Manufacturer ID<br \/>\n$db2-&gt;query(\u201dSELECT manufacturer_id FROM #__{vm}_product_mf_xref WHERE product_id=\u2019$product_id\u2019\u201d);<br \/>\n$db2-&gt;next_record();<br \/>\n$manufacturer_id = $db2-&gt;f(\u201dmanufacturer_id\u201d);<\/p>\n<p>add:<\/p>\n<p>\/\/ Get the Distributor ID<br \/>\n$db2-&gt;query(\u201dSELECT distributor_id FROM #__{vm}_product_dist_xref WHERE product_id=\u2019$product_id\u2019\u201d);<br \/>\n$db2-&gt;next_record();<br \/>\n$distributor_id = $db2-&gt;f(\u201ddistributor_id\u201d);<\/p>\n<p>6.3.3. After :<\/p>\n<p>&lt;tr class=\u201drow0\u2033&gt;<br \/>\n&lt;td width=\u201d21%\u201d&gt;&lt;div style=\u201dtext-align:right;font-weight:bold;\u201d&gt; &lt;?php echo $VM_LANG-&gt;_(\u2019PHPSHOP_PRODUCT_FORM_VENDOR\u2019) ?&gt;:&lt;\/div&gt;&lt;\/td&gt;<br \/>\n&lt;td width=\u201d79%\u201d &gt;&lt;?php ps_vendor::list_vendor($db-&gt;sf(\u201dvendor_id\u201d));\u00a0 ?&gt;&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<\/p>\n<p>add:<\/p>\n<p>&lt;tr class=\u201drow1\u2033&gt;<br \/>\n&lt;td width=\u201d21%\u201d &gt;&lt;div style=\u201dtext-align:right;font-weight:bold;\u201d&gt; &lt;?php echo \u201cDistributor\u201d ?&gt;:&lt;\/div&gt;&lt;\/td&gt;<br \/>\n&lt;td width=\u201d79%\u201d &gt;&lt;?php ps_distributor::list_distributor(@$distributor_id);\u00a0 ?&gt;&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<\/p>\n<p>That\u2019s it\u2026<!--:--><!--:en--><\/p>\n<p><strong>1. Add one more menu item to the virtumart menu (virtuemart modules)<\/strong><\/p>\n<p>To do this go to the your-site\/administrator\/components\/com_virtuemart\/header.php and add one more menu item.<\/p>\n<p>Find this code: <em>case \u2018manufacturer\u2019:<\/em><\/p>\n<p>and paste this code before it:<\/p>\n<p><em> case \u2018distributor\u2019:<br \/>\n?&gt;<br \/>\n&lt;h3 class=\u201dtitle-smenu\u201d title=\u201ddistributor\u201d onclick=\u201dSwitchMenu(\u2019&lt;?php echo $modCount ?&gt;\u2019)\u201d&gt;<br \/>\n&lt;?php echo Distributor<br \/>\n?&gt;<br \/>\n&lt;\/h3&gt;<br \/>\n&lt;div class=\u201dsection-smenu\u201d&gt;<br \/>\n&lt;ul&gt;<br \/>\n&lt;li class=\u201ditem-smenu vmicon vmicon-16-content\u201d&gt;<br \/>\n&lt;a href=\u201d&lt;?php $sess-&gt;purl($_SERVER[&#8216;PHP_SELF&#8217;].\u201d?pshop_mode=admin&amp;amp;page=distributor.distributor_list\u201d) ?&gt;\u201d&gt;&lt;?php echo \u201cDistributor list\u201d ?&gt;&lt;\/a&gt;<br \/>\n&lt;\/li&gt;<br \/>\n&lt;li class=\u201ditem-smenu vmicon vmicon-16-editadd\u201d&gt;<br \/>\n&lt;a href=\u201d&lt;?php $sess-&gt;purl($_SERVER[&#8216;PHP_SELF&#8217;].\u201d?pshop_mode=admin&amp;amp;page=distributor.distributor_form\u201d) ?&gt;\u201d&gt;&lt;?php echo \u201cAdd distributor\u201d ?&gt;&lt;\/a&gt;<br \/>\n&lt;hr \/&gt;<br \/>\n&lt;\/li&gt;<br \/>\n&lt;\/ul&gt;<br \/>\n&lt;\/div&gt;<br \/>\n&lt;?php<br \/>\n$modCount++;<br \/>\nbreak;<\/em><\/p>\n<p><em><br \/>\n<\/em><\/p>\n<p><strong>2. Create a new table in the DB for example called <a class=\"item\" href=\"http:\/\/kavdesign.net:2082\/3rdparty\/phpMyAdmin\/tbl_structure.php?db=kavdesig_magazin6&amp;table=jos_vm_distributor_kefi&amp;token=b5819ad519cababad395d7f6fc9d0244\"> <\/a><span class=\"item\">jos_vm_distributor <\/span><\/strong><\/p>\n<p><span class=\"item\">I have created a table similar to the on for the manufacturers<\/span><strong><span class=\"item\"><br \/>\n<\/span><\/strong><\/p>\n<table id=\"tablestructure\" class=\"data\" border=\"0\">\n<thead>\n<tr>\n<th id=\"th2\">Field<\/th>\n<th id=\"th3\">Type<\/th>\n<th id=\"th4\">Collation<\/th>\n<th id=\"th5\">Attributes<\/th>\n<th id=\"th6\">Null<\/th>\n<th id=\"th7\">Default<\/th>\n<th id=\"th8\">Extra<\/th>\n<th id=\"th9\" colspan=\"7\">Action<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr class=\"odd marked\">\n<td align=\"center\"><input id=\"checkbox_row_1\" name=\"selected_fld[]\" type=\"checkbox\" value=\"distributor_id\" \/><\/td>\n<th><label for=\"checkbox_row_1\"><span style=\"text-decoration: underline;\">distributor_id<\/span><\/label><\/th>\n<td><bdo dir=\"ltr\" xml:lang=\"en\">int(11)<\/bdo><\/td>\n<td><\/td>\n<td style=\"font-size: 70%;\"><\/td>\n<td>No<\/td>\n<td><\/td>\n<td>auto_increment<\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<\/tr>\n<tr class=\"even\">\n<td align=\"center\"><input id=\"checkbox_row_2\" name=\"selected_fld[]\" type=\"checkbox\" value=\"d_name\" \/><\/td>\n<th><label for=\"checkbox_row_2\">d_name<\/label><\/th>\n<td><bdo dir=\"ltr\" xml:lang=\"en\">varchar(64)<\/bdo><\/td>\n<td><dfn title=\"Unicode (multilingual), case-insensitive\">utf8_general_ci<\/dfn><\/td>\n<td style=\"font-size: 70%;\"><\/td>\n<td>Yes<\/td>\n<td><em>NULL<\/em><\/td>\n<td><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<\/tr>\n<tr class=\"odd\">\n<td align=\"center\"><input id=\"checkbox_row_3\" name=\"selected_fld[]\" type=\"checkbox\" value=\"d_email\" \/><\/td>\n<th><label for=\"checkbox_row_3\">d_email<\/label><\/th>\n<td><bdo dir=\"ltr\" xml:lang=\"en\">varchar(255)<\/bdo><\/td>\n<td><dfn title=\"Unicode (multilingual), case-insensitive\">utf8_general_ci<\/dfn><\/td>\n<td style=\"font-size: 70%;\"><\/td>\n<td>Yes<\/td>\n<td><em>NULL<\/em><\/td>\n<td><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<td align=\"center\"><\/td>\n<\/tr>\n<tr class=\"even\">\n<td align=\"center\"><input id=\"checkbox_row_4\" name=\"selected_fld[]\" type=\"checkbox\" value=\"d_desc\" \/><\/td>\n<th><label for=\"checkbox_row_4\">d_desc<\/label><\/th>\n<td><bdo dir=\"ltr\" xml:lang=\"en\">text<\/bdo><\/td>\n<td><dfn title=\"Unicode (multilingual), case-insensitive\">utf8_general_ci<\/dfn><\/td>\n<td style=\"font-size: 70%;\"><\/td>\n<td>Yes<\/td>\n<td><em>NULL<\/em><\/td>\n<td><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>3. Add the record for the distributors in the <span class=\"item\">jos_vm_module<\/span> table<\/strong><\/p>\n<p>Add a record to the DB like this one in the jos_vm_module table. Choose some ID and write the name \u201cdistributor\u201d, And don\u2019t forget to add Y to published.<\/p>\n<p>It is possible to do this 3-th step from the virtuemart backend -&gt; admin -&gt; list modules,\u00a0 but I\u2019m not sure.<\/p>\n<p><strong><br \/>\n<\/strong><\/p>\n<p><strong>4. Add some functions to the newly published module<\/strong>.<\/p>\n<p>Go to virtuemart backend -&gt; admin -&gt; list modules. Go to function list for the distributor module.<\/p>\n<p>Add this functions: distributorAdd, distributorDelete, distributorUpdate (see virtuemart manual for help with adding new functions)<\/p>\n<p><strong>5. Now create the files for the distributor. <\/strong><\/p>\n<p>&#8211; \/administrator\/components\/com_virtuemart\/html\/<a href=\"..\/stuff\/codes\/distributor.distributor_form.php\">distributor.distributor_form.php<\/a><\/p>\n<p>&#8211; \/administrator\/components\/com_virtuemart\/html\/<a href=\"..\/stuff\/codes\/distributor.distributor_list.php\">distributor.distributor_list.php<\/a><\/p>\n<p>-\/administrator\/components\/com_virtuemart\/classes\/<a href=\"..\/stuff\/codes\/ps_distributor.php\">ps_distributor.php<\/a><\/p>\n<p>You could download my files from here above.<\/p>\n<p><strong>6. Add the code to support distributors in the product details page. <\/strong><\/p>\n<p>(this is a helpfull article &#8211; <a title=\"Add a New Field to Products in Joomla! VirtueMart\" href=\"http:\/\/www.newcircleconsulting.com\/2008\/06\/10\/add-a-field-to-products-in-joomla-virtuemart\/\">Add a New Field to Products in Joomla! VirtueMart<\/a>)<\/p>\n<p><strong>6.1.<\/strong> First of all we have to ctreate a new table in the database which will link the distributors to the products. In my case it\u2019s called <em>jos_vm_product_dist_xref.<\/em><\/p>\n<p>You should do it the same way the\u00a0<em> jos_vm_product_mf_xref <\/em>is fone. Add the two fields and the two indexes to the table.<\/p>\n<p><strong>6.2.<\/strong> Open ps_product.html and add these lines:<\/p>\n<p>6.2.1. After these lines :<\/p>\n<p>if (empty($d[&#8216;manufacturer_id&#8217;])) {<br \/>\n$d[&#8216;manufacturer_id&#8217;] = \u201c1\u2033;<\/p>\n<p>}<\/p>\n<p>add<\/p>\n<p>if (empty($d[&#8216;distributor_id&#8217;])) {<br \/>\n$d[&#8216;distributor_id&#8217;] = \u201c1\u2033;<br \/>\n}<\/p>\n<p>6.2.2. Before:<\/p>\n<p>$q = \u201cINSERT INTO #__{vm}_product_mf_xref VALUES (\u201d;<br \/>\n$q .= \u201c\u2018\u201d.$d[&#8216;product_id&#8217;].\u201d\u2018, \u2018\u201d.vmRequest::getInt(\u2019manufacturer_id\u2019).\u201d\u2018)\u201d;<br \/>\n$db-&gt;setQuery($q); $db-&gt;query();<\/p>\n<p>add:<\/p>\n<p>$q = \u201cINSERT INTO #__{vm}_product_dist_xref VALUES (\u201d;<br \/>\n$q .= \u201c\u2018\u201d.$d[&#8216;product_id&#8217;].\u201d\u2018, \u2018\u201d.vmRequest::getInt(\u2019distributor_id\u2019).\u201d\u2018)\u201d;<br \/>\n$db-&gt;setQuery($q); $db-&gt;query();<\/p>\n<p>6.2.3. After:<\/p>\n<p>$q = \u201cUPDATE #__{vm}_product_mf_xref SET \u201c;<br \/>\n$q .= \u2018manufacturer_id=\u2019.vmRequest::getInt(\u2019manufacturer_id\u2019).\u2019 \u2018;<br \/>\n$q .= \u2018WHERE product_id = \u2018.$d[&#8216;product_id&#8217;];<br \/>\n$db-&gt;query($q);<\/p>\n<p>add:<\/p>\n<p>$q = \u201cUPDATE #__{vm}_product_dist_xref SET \u201c;<br \/>\n$q .= \u2018distributor_id=\u2019.vmRequest::getInt(\u2019distributor_id\u2019).\u2019 \u2018;<br \/>\n$q .= \u2018WHERE product_id = \u2018.$d[&#8216;product_id&#8217;];<br \/>\n$db-&gt;query($q);<\/p>\n<p>6.2.4. After:<\/p>\n<p>\/* Delete product &#8211; manufacturer xref *\/<br \/>\n$q = \u201cDELETE FROM #__{vm}_product_mf_xref WHERE product_id=\u2019$product_id\u2019\u201d;<br \/>\n$db-&gt;setQuery($q); $db-&gt;query();<\/p>\n<p>add:<\/p>\n<p>\/* Delete product &#8211; distributor xref *\/<br \/>\n$q = \u201cDELETE FROM #__{vm}_product_dist_xref WHERE product_id=\u2019$product_id\u2019\u201d;<br \/>\n$db-&gt;setQuery($q); $db-&gt;query();<\/p>\n<p>6.2.5. After this function :<\/p>\n<p>function get_manufacturer_id($product_id) {}<\/p>\n<p>add:<\/p>\n<p>\/**<br \/>\n* Function to get the distributor id the product $product_id is assigned to<br \/>\n* @author soeren<br \/>\n* @param int $product_id<br \/>\n* @return int The distributor id<br \/>\n*\/<br \/>\nfunction get_distributor_id($product_id) {<br \/>\n$db = new ps_DB;<\/p>\n<p>$q = \u201cSELECT distributor_id FROM #__{vm}_product_dist_xref \u201c;<br \/>\n$q .= \u201cWHERE product_id=\u2019$product_id\u2019 \u201c;<\/p>\n<p>$db-&gt;query($q);<br \/>\n$db-&gt;next_record();<br \/>\nif ($db-&gt;f(\u201ddistributor_id\u201d)) {<br \/>\nreturn $db-&gt;f(\u201ddistributor_id\u201d);<br \/>\n}<br \/>\nelse {<br \/>\nreturn false;<br \/>\n}<br \/>\n}<\/p>\n<p>6.2.6. After function get_mf_name($product_id) {}<\/p>\n<p>add<\/p>\n<p>\/**<br \/>\n* Functon to get the name of the distributor this product is assigned to<br \/>\n*<br \/>\n* @param int $product_id<br \/>\n* @return string the distributor name<br \/>\n*\/<br \/>\nfunction get_d_name($product_id) {<br \/>\n$db = new ps_DB;<\/p>\n<p>$q = \u201cSELECT d_name,#__{vm}_distributor_kefi.distributor_id FROM #__{vm}_product_dist_xref,#__{vm}_distributor_kefi \u201c;<br \/>\n$q .= \u201cWHERE product_id=\u2019$product_id\u2019 \u201c;<br \/>\n$q .= \u201cAND #__{vm}_distributor_kefi.distributor_id=#__{vm}_product_dist_xref.distributor_id\u201d;<\/p>\n<p>$db-&gt;query($q);<br \/>\n$db-&gt;next_record();<br \/>\nif ($db-&gt;f(\u201dd_name\u201d)) {<br \/>\nreturn $db-&gt;f(\u201dd_name\u201d);<br \/>\n}<br \/>\nelse {<br \/>\nreturn \u201c\u201d;<br \/>\n}<br \/>\n}<\/p>\n<p>\/**<br \/>\n* Functon to get the id of the distributor this product is assigned to<br \/>\n*<br \/>\n* @param int $product_id<br \/>\n* @return string the distributor id<br \/>\n*\/<br \/>\nfunction get_d_id($product_id) {<br \/>\n$db = new ps_DB;<\/p>\n<p>$q = \u201cSELECT d_name,#__{vm}_distributor_kefi.distributor_id FROM #__{vm}_product_dist_xref,#__{vm}_distributor_kefi \u201c;<br \/>\n$q .= \u201cWHERE product_id=\u2019$product_id\u2019 \u201c;<br \/>\n$q .= \u201cAND #__{vm}_distributor_kefi.distributor_id=#__{vm}_product_dist_xref.distributor_id\u201d;<\/p>\n<p>$db-&gt;query($q);<br \/>\n$db-&gt;next_record();<br \/>\nif ($db-&gt;f(\u201ddistributor_id\u201d)) {<br \/>\nreturn $db-&gt;f(\u201ddistributor_id\u201d);<br \/>\n}<br \/>\nelse {<br \/>\nreturn \u201c\u201d;<br \/>\n}<br \/>\n}<\/p>\n<p>6.3. Open product.product_form.php and modify:<\/p>\n<p>6.3.1.After:<\/p>\n<p>require_once( CLASSPATH.\u2019ps_manufacturer.php\u2019 );<\/p>\n<p>add:<\/p>\n<p>require_once( CLASSPATH.\u2019ps_distributor.php\u2019 );<\/p>\n<p>6.3.2. After :<\/p>\n<p>\/\/ Get the Manufacturer ID<br \/>\n$db2-&gt;query(\u201dSELECT manufacturer_id FROM #__{vm}_product_mf_xref WHERE product_id=\u2019$product_id\u2019\u201d);<br \/>\n$db2-&gt;next_record();<br \/>\n$manufacturer_id = $db2-&gt;f(\u201dmanufacturer_id\u201d);<\/p>\n<p>add:<\/p>\n<p>\/\/ Get the Distributor ID<br \/>\n$db2-&gt;query(\u201dSELECT distributor_id FROM #__{vm}_product_dist_xref WHERE product_id=\u2019$product_id\u2019\u201d);<br \/>\n$db2-&gt;next_record();<br \/>\n$distributor_id = $db2-&gt;f(\u201ddistributor_id\u201d);<\/p>\n<p>6.3.3. After :<\/p>\n<p>&lt;tr class=\u201drow0\u2033&gt;<br \/>\n&lt;td width=\u201d21%\u201d&gt;&lt;div style=\u201dtext-align:right;font-weight:bold;\u201d&gt; &lt;?php echo $VM_LANG-&gt;_(\u2019PHPSHOP_PRODUCT_FORM_VENDOR\u2019) ?&gt;:&lt;\/div&gt;&lt;\/td&gt;<br \/>\n&lt;td width=\u201d79%\u201d &gt;&lt;?php ps_vendor::list_vendor($db-&gt;sf(\u201dvendor_id\u201d));\u00a0 ?&gt;&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<\/p>\n<p>add:<\/p>\n<p>&lt;tr class=\u201drow1\u2033&gt;<br \/>\n&lt;td width=\u201d21%\u201d &gt;&lt;div style=\u201dtext-align:right;font-weight:bold;\u201d&gt; &lt;?php echo \u201cDistributor\u201d ?&gt;:&lt;\/div&gt;&lt;\/td&gt;<br \/>\n&lt;td width=\u201d79%\u201d &gt;&lt;?php ps_distributor::list_distributor(@$distributor_id);\u00a0 ?&gt;&lt;\/td&gt;<br \/>\n&lt;\/tr&gt;<\/p>\n<p>That\u2019s it\u2026<!--:--><\/p>\n","protected":false},"excerpt":{"rendered":"<p>First I\u2019ll try to explain what needs to be achieved. If you have a big online store and you try to remember all your distributors<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/www.kavdesign.net\/blog\/coding\/how-to-make-an-extension-to-virtuemart-which-will-allow-you-to-add-distributors-to-the-products\/\">Continue reading<span class=\"screen-reader-text\">How to make an extension to virtuemart which will allow you to add distributors and then chose distributor for each product?<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[9],"tags":[],"class_list":["post-149","post","type-post","status-publish","format-standard","hentry","category-coding","entry"],"_links":{"self":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/149","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/comments?post=149"}],"version-history":[{"count":18,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/149\/revisions"}],"predecessor-version":[{"id":269,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/posts\/149\/revisions\/269"}],"wp:attachment":[{"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/media?parent=149"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/categories?post=149"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kavdesign.net\/blog\/wp-json\/wp\/v2\/tags?post=149"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}