News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

VM3 - Customfields are not saved in JSON format

Started by welrachid, December 09, 2014, 15:39:30 PM

Previous topic - Next topic

welrachid

Hi everyone
using J3.3.6 and VM3.0.2 (i think the problem also was in 3.0.0)

I have some customplugins that i have rewritten using the guides found on this page and http://reinhold.kainhofer.com/software/tutorial-vm2-plugin-vm3.html
Currently im running into a problem where the customfield_params that are saved have | in them instead of being json_encoded.
This means when i try to "reload" the page, i get a lot of errors. particularly in this file
administrator/components/com_virtuemart/plugins/vmcustomplugin.php Line 100. Because the json_decode returns FALSE it cannot iterate over it. This should in my opinion be changed to if (is_array(...))

   public function parseCustomParams (&$field, $xParams = 'customfield_params') {

      VmTable::bindParameterable ($field, $xParams, $this->_varsToPushParam);

      if (empty($field->custom_element)) {
         return 0;
      }
      if (!empty($field->customfield_params) && is_string ($field->customfield_params)) {
         $custom_params = json_decode ($field->customfield_params, TRUE);
line 100      foreach ($custom_params as $k => $v) {
            if (!empty($v)) {
               $field->$k = $v;
            }
         }
      }

   }

Cant find any place in my own extension code that should be changed to make use of json_decode

thx
Wel
Best regards,
Wel

Milbo

Usually you should not care about that. VM should handle it for you.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

welrachid

So does that mean i can expect that its a bug that will be solved? The problem is that it "breaks" the data. This means i cannot edit the data through interface.
Best regards,
Wel

reinhold

I don't think there are cases where parseCustomParams should be explicitly called in VM 3... That function is no longer called by the VM core, so you must apparently call it in your plugin...
In all my customfield plugins, I have:

if (!defined('VM_VERSION') or VM_VERSION < 3) { // Only needed in VM2
$this->parseCustomParams($field);
}


Do you have any reason to call that legacy function any more? If so, there is probably a better way to do it in VM3.

Best regards,
Reinhold

PS: While migrating my plugins, I remember I also ran into that very problem that the params are JSON-encoded strings concatenated by | and so parseCustomParams doesn't work any more. Unfortunately, I don't remember where this was and how exactly I solved this - maybe I resorted to using some method of the custom or customfields model... I just remember that I realized that parseCustomParams was not needed any more.