How to save "extra plugin parameters" for vmuserfield plugin?

Started by UWiX, October 28, 2018, 12:33:29 PM

Previous topic - Next topic

UWiX

Previously I've posted a topic because I hade trouble saving plugin parameters for a vmcustom plugin (http://forum.virtuemart.net/index.php?topic=135801.msg473306#msg473306).

Recently I started to program a plugin for a client and even if I try to follow the directions in my last question (saving vmcustom plugin params), I cannot seem to get it fix for a vmuserfield plugin. It uses a few different triggers but the setup should be same.
What I've got so far:

data_range.xml
   
<vmconfig>
        <fields name="params">
            <fieldset name="template">

              <field
                name="use_daterange"
                type="radio"
                default="0"
                label="Use date range?"
                description=""
                class="btn-group-yesno">
                  <option value="1">JYES</option>
                  <option value="0">JNO</option>
              </field>
          </fieldset>
    </fields>
</vmconfig>


date_range.php (in plugins/vmuserfield folder)

function __construct(& $subject, $config) {

        parent::__construct($subject, $config);

        $varsToPushVM3 = array
        (
            'use_daterange'=>array('','string'),
            'select_startdate'=>array('', 'string'),
            'select_enddate'=>array('', 'string'),
        );
        $this->setConfigParameterable('userfield_params', $varsToPushVM3);
    }

    function plgVmDeclarePluginParamsUserfieldVM3(&$data)
    {
        return $this->declarePluginParams('userfield_params', $data);
    }

    function plgVmGetTablePluginParams($psType, $name, $id, &$xParams, &$varsToPush)
    {
        return $this->getTablePluginParams($psType, $name, $id, $xParams, $varsToPush);
    } 


But whatever I do, change or try to debug - nothing is saved for the userfield_params.

When checking the data using:

    public function plgVmOnBeforeUserfieldSave( $plgName , &$data, &$field )
    {
        print_r( $data['userfield_params'] );
    }


The variable is filled correctly according the selection of the extra parameter(s). But it is not saved!
Does anyone know what I am missing here? I'm really stuck at the moment  :(
-- Beam me up Scotty! This isn't the mens room!
-- Using VirtueMart 3.x

UWiX

Well, took a loooong time to figure it out, but the mistake is a bit on me - but I also needed to add some strange way to save the parameters.

First of all I had to change this line in plgVmDeclarePluginParamsUserfieldVM3:

return $this->declarePluginParams('userfield_params', $data);

to

return $this->declarePluginParams('userfield', $data);

But it's also necessary to "redirect" the saved $data['params'] value to a correct imploded format to store in the database field ''userfield_params":


public function plgVmOnBeforeUserfieldSave( $plgName , &$data, &$field )
{
    foreach ($data['params'] as $key=>$value)
    {
        $tmpParams[] = $key . '="' . $value . '"';
    }
    $data['userfield_params'] = implode('|', $tmpParams);
       
    return true; // Not sure if it's needed but can do no harm ;-)
}


Without the above function the Extra Plugin Parameters are NOT read/set according to the saved values. Well, they wont be saved at all without this adjustment.

Now the Extra plugin parameters do get saved AND restored upon loading of the backend customer-fields type. This way I do not have to alter (hack) any original VirtueMart sourcecode and it  will do the trick.  :D

-- Beam me up Scotty! This isn't the mens room!
-- Using VirtueMart 3.x