News:

Support the VirtueMart project and become a member

Main Menu

Upgrade an older plug-in for VM3.x

Started by antifragile, March 20, 2016, 15:17:27 PM

Previous topic - Next topic

antifragile

Hi, I have been using a plug-in to enable category-based shipping pricing. The plug-in was for VM2.x and has not been upgraded. The function itself still works fine in VM3.0.14. The configuration works via a field in MySQL. However, the configuration page does not show anymore in VM3, so editing the configuration works only via the SQL entry (which is cryptic). I have attached two images: one with the configuration page from J2.5, one showing the empty page in J3.4.

There is probably something in the PHP-or SQL-file in the plugin which prevents the page from showing in VM. Does anyone please have an idea?

I have attached the plug-in. It is under a gpl-2.0.html GNU/GPL license, so I hope that this is ok to post that here.

Many thanks and regards,

Dan

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

PRO

if this is a shipping plugin,

just make a copy of the weight_countries plugin
re-name it. (dont forget to change the class name)
Then, replace the functions with yours.

Do the same on the .xml file

reinhold

Dear Dan,
The main issue with the configuration screen is that VM2 used the Joomla 1.x-style <param> configuration declaration in the plugin's manifest, while VM3 switched to the Joomla 2.x/3.x-style <fields> configuration declaraion.

See also my tutorial / checklist for what is needed to upgrade a plugin for VM2 to VM3:
https://open-tools.net/documentation/upgrading-vm2-plugin-to-vm3.html

The XML switch to <fields> is indicated with an example, but due to space restraints, that tutorial cannot give an in-depth overview about how the Joomal 3.x fields work. The <fields> are not VM-specific, so you can search for any Joomla 3 tutorial describing the configuration fields for Joomla plugins. The only difference to Joomla plugins is that for VM shipping methods, it is preferred to use <vmconfig> instead of <config> (which would also work, but also show up in the plugin's configuration page rather than only in the shipping method's configuration page).

Best regards,
Reinhold

antifragile

Reinhold, this sounds like exactly the solution that I am seeking.

It looks as if the site with your link is down. Same with http://reinhold.kainhofer.com/software/tutorial-vm2-plugin-vm3.html. Error is "Error displaying the error page: Application Instantiation Error: Could not connect to MySQL."

I'll post the solution once I have solved the issue.

Thanks and regards,

Dan

reinhold

Dear Dan,
Sorry for the broken page... Due to a severe hardware crash (broken disk in the RAID array and incredible stupidity on my side led to a complete loss of data and the need to restore from backups), some database permissions have been wrongly restored. Everything should be working now, again, and the link should work.

Best regards,
Reinhold

antifragile

Reinhold, sorry to hear about the hardware crash. Murphy's Law ...

I now executed all the recommendations in your tutorial. I am struggling with the function getST().

As your tutorial recommended I replaced:

      // Get address information
      $address = (($cart->ST == 0) ? $cart->BT : $cart->ST);
      if (!is_array($address)) {
          $address = array();
          $address['zip'] = 0;
          $address['virtuemart_country_id'] = 0;
      }

With:

      // Get address information
      if (method_exists($cart 'getST')) {
         $address = $cart->getST();
      }
      else {   
         $address = (($cart->ST == 0) || $cart->STSameAsBT == 1) ? $cart->BT : $cart->ST);
      }
   
      if (!is_array($address)) {
          $address = array();
          $address['zip'] = 0;
          $address['virtuemart_country_id'] = 0;
      }

It returns a blank screen. Error reporting gives me this:

   Strict Standards: Declaration of plgVmShipmentRules_Shipping_Base::setCartPrices() should be compatible with vmPSPlugin::setCartPrices(VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) in ./plugins/vmshipment/rules_shipping/rules_shipping_base.php on line 743

   Parse error: syntax error, unexpected ''getST'' (T_CONSTANT_ENCAPSED_STRING) in ./plugins/vmshipment/category_shipping/category_shipping.php on line 292



When I replace that section again with what was there before, while leaving all other adjustments in the XML and PHP files in place, I am getting the error:

    0 JForm::getInstance could not load file


Any ideas please on what I may have done wrong?

Many thanks and regards,

Dan


P.S. When I restore the original VM2 plugin, I am also getting the error "Strict Standards: Declaration of plgVmShipmentRules_Shipping_Base::setCartPrices() should be compatible with vmPSPlugin::setCartPrices(VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) in ./plugins/vmshipment/rules_shipping/rules_shipping_base.php on line 743"

reinhold

Quote from: antifragile on April 02, 2016, 14:52:06 PM
      if (method_exists($cart 'getST')) {
A comma is missing here:

if (method_exists($cart, 'getST')) {


Best regards,
Reinhold

antifragile

Yes, my fail. Thanks!

I had another fail in the else function, "Parse error: syntax error, unexpected ')' " but I took care of that by taking out the relevant")" from the code I sent earlier.

Result: no more white screen, Plugin appears.


However, the configuration page remains empty as in my original post (even after having adjusted the XML-file as outlined in the tutorial). It initially looks as if this error causes it:

QuoteStrict Standards: Declaration of plgVmShipmentRules_Shipping_Base::setCartPrices() should be compatible with vmPSPlugin::setCartPrices(VirtueMartCart $cart, &$cart_prices, $method, $progressive = true) in /homepages/14/d28024892/htdocs/www.homepatchwork.de/dev/plugins/vmshipment/rules_shipping/rules_shipping_base.php on line 743

What is odd is that "plgVmShipmentRules" is not part of the plugin that I am working on. Then I tested the standard VM shipping plugin, the same error appears. But here the configuration page works just fine.


I now suspect a fail in my change of the XML-file, specificaly the <params><param> to <vmconfig><fields><fieldset><field> as you had outlined in your tutorial.

The orig was:
    <params addpath="/administrator/components/com_virtuemart/elements">
<param name="countries" type="vmcountries" scope="com_virtuemart" default="" label="VMSHIPMENT_CS_COUNTRIES" description="VMSHIPMENT_CS_COUNTRIES_DESC" />
<param name="zip_start" type="text" size="10" default="" label="VMSHIPMENT_CS_ZIP_START" description="VMSHIPMENT_CS_ZIP_START_DESC"/>
<param name="zip_stop" type="text" size="10" default="" label="VMSHIPMENT_CS_ZIP_STOP" description="VMSHIPMENT_CS_ZIP_STOP_DESC"/>
<param name="package_fee" type="text" label="VMSHIPMENT_CS_PACKAGE_FEE" description="VMSHIPMENT_CS_PACKAGE_FEE_DESC" />
<param name="tax_id" type="vmtaxes" scope="com_virtuemart" label="VMSHIPMENT_CS_TAX" description="VMSHIPMENT_CS_TAX_DESC" />
<param name="category_shipping_cost" type="textarea" label="VMSHIPMENT_CS_CATEGORY_SHIPPING_COST" description="VMSHIPMENT_CS_CATEGORY_SHIPPING_COST_DESC" cols="2" rows="10" />
<param name="include_duplicated_categories" type="radio" default="1" label="VMSHIPMENT_CS_INCLUDE_DUPLICATED_CATEGORIES" description="VMSHIPMENT_CS_INCLUDE_DUPLICATED_CATEGORIES_DESC">
<option value="1">Yes</option>
<option value="0">No</option>
</param>
<param name="include_duplicated_products" type="radio" default="1" label="VMSHIPMENT_CS_INCLUDE_DUPLICATED_PRODUCTS" description="VMSHIPMENT_CS_INCLUDE_DUPLICATED_PRODUCTS_DESC">
<option value="1">Yes</option>
<option value="0">No</option>
</param>
<param name="use_max_category_cost" type="radio" default="0" label="VMSHIPMENT_CS_USE_MAXIMUM_CATEGORY_COST" description="VMSHIPMENT_CS_USE_MAXIMUM_CATEGORY_COST_DESC">
<option value="1">Yes</option>
<option value="0">No</option>
</param>
<param name="min_price_for_free_shipping" type="text" label="VMSHIPMENT_CS_MIN_PRICE_FOR_FREE_SHIPPING" description="VMSHIPMENT_CS_MIN_PRICE_FOR_FREE_SHIPPING_DESC" />
</params>



My adjusted code is:

    <vmconfig>
<fields name="params" addfieldpath="/administrator/components/com_virtuemart/elements">

<fieldset name="countries" label="VMSHIPMENT_CS_COUNTRIES" description="VMSHIPMENT_CS_COUNTRIES_DESC" >
<field type="vmcountries" scope="com_virtuemart" default="" />
</fieldset>

<fieldset name="zip_start" label="VMSHIPMENT_CS_ZIP_START" description="VMSHIPMENT_CS_ZIP_START_DESC" >
<field type="text" size="10" default=""  />
</fieldset>

<fieldset "zip_stop" label="VMSHIPMENT_CS_ZIP_STOP" description="VMSHIPMENT_CS_ZIP_STOP_DESC" >
<field name= type="text" size="10" default=""   />
</fieldset>

<fieldset name="package_fee" label="VMSHIPMENT_CS_PACKAGE_FEE" description="VMSHIPMENT_CS_PACKAGE_FEE_DESC" >
<field type="text"  />
</fieldset>

<fieldset name="tax_id" label="VMSHIPMENT_CS_TAX"  description="VMSHIPMENT_CS_TAX_DESC" >
<field type="vmtaxes" scope="com_virtuemart"  />
</fieldset>

<fieldset name="category_shipping_cost" label="VMSHIPMENT_CS_CATEGORY_SHIPPING_COST" description="VMSHIPMENT_CS_CATEGORY_SHIPPING_COST_DESC" >
<field type="textarea"  cols="2" rows="10" />
</fieldset>

<fieldset name="include_duplicated_categories" label="VMSHIPMENT_CS_INCLUDE_DUPLICATED_CATEGORIES" description="VMSHIPMENT_CS_INCLUDE_DUPLICATED_CATEGORIES_DESC" >
<field type="radio" default="1" label="VMSHIPMENT_CS_INCLUDE_DUPLICATED_CATEGORIES"  />
<option value="1">Yes</option>
<option value="0">No</option>
</fieldset>

<fieldset name="include_duplicated_products" label="VMSHIPMENT_CS_INCLUDE_DUPLICATED_PRODUCTS"  description="VMSHIPMENT_CS_INCLUDE_DUPLICATED_PRODUCTS_DESC" >
<field type="radio" default="1" />
<option value="1">Yes</option>
<option value="0">No</option>
</fieldset>

<fieldset name="use_max_category_cost" label="VMSHIPMENT_CS_USE_MAXIMUM_CATEGORY_COST" description="VMSHIPMENT_CS_USE_MAXIMUM_CATEGORY_COST_DESC" >
<field type="radio" default="0"  />
<option value="1">Yes</option>
<option value="0">No</option>
</fieldset>

<fieldset name="min_price_for_free_shipping" label="VMSHIPMENT_CS_MIN_PRICE_FOR_FREE_SHIPPING" description="VMSHIPMENT_CS_MIN_PRICE_FOR_FREE_SHIPPING_DESC" >
<field type="text"  />
</fieldset>

</fields>
</vmconfig>



I probably misunderstood the instruction in the tutorial. I have displased the "description=" (which did not appear in your tutorial) or perhaps the "option value=".

(Sorry, I am just a rookie programmer, if that ...)

Many thanks again!

reinhold

Dear Dan,
There are several issues with your XML that I can see. What I would recommend is to start with an empty <vmconfig><fields...><fieldset...></fieldset></fields></vmconfig> and then add the params one after the other. That way you can always concentrate on getting one <field> tag correct and it is easier to fin problems.

Issues that I can see in your XML (without actually testing it):

  • The "zip_stop" is missing the name=
  • I don't think you want so many fieldsets. Each fieldset means one tab in the plugin config. You rather want to combine multiple fields into one fieldset
  • Each <field> needs a name and a label.
  • The individual <option ... /> tag for radio button groups need to be inside the <field type="radio"...>   </field>

Just for clarification: A fieldset is a group of settings, which is e.g. shown in a separate tab in the plugin config, or in its own box in the shipping method config.
Each <field> defines an actul configuration parameter, so it needs a name and a label and a type.

As mentioned at the beginning, it's way easier to debug if you start with an empty vmconfig / fieldset and then try to get just one parameter to appear. Once that works, you can add further config settings.

Best regards,
Reinhold