VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: sandomatyas on July 19, 2019, 10:34:25 AM

Title: Modify #__virtuemart_product_customfields.customfield_params progmatically
Post by: sandomatyas on July 19, 2019, 10:34:25 AM
I need to write a custom CLI script which checks the #__virtuemart_product_customfields for a specific virtuemart_custom_id, loads the rows, analyze the customfield_params field's value and modify it if it needs and stores it back.
The field's value is something like that:
color="red"|products={
    "2": "3",
    "3": "0",
    "4": "1",
    "5": "0"
}|priority="high"|wh="w1"|

I need to run this plugin in every hour, it checks these values agains a custom external database, etc.

I was wondering what is the proper way to convert this string as field value to an array/object? I'm pretty sure there are better way than explode it by | and parse the json manually.
Is there a model/helper method for that which I missed?
And a same question backwards, because the modified data should be stored to the database too.
Title: Re: Modify #__virtuemart_product_customfields.customfield_params progmatically
Post by: PRO on July 19, 2019, 17:36:01 PM
is this a product input plugin? whats it do?

You can always get the values dynamically.
You can even CREATE the params dynamically.

To get the values dynamically on front end, just do it in this method.
function plgVmOnDisplayProductFEVM3

To CREATE the params dynamically.
You just query database and set  $varsToPush as your params
$this->setConfigParameterable('customfield_params',$varsToPush);
Title: Re: Modify #__virtuemart_product_customfields.customfield_params progmatically
Post by: Studio 42 on July 20, 2019, 11:15:13 AM
Of you permanently need to modify the values. I think that you should use another table when you save/read the values.
I do this so i can use index to optimize search filters
Title: Re: Modify #__virtuemart_product_customfields.customfield_params progmatically
Post by: sandomatyas on July 23, 2019, 14:25:42 PM
Quote from: PRO on July 19, 2019, 17:36:01 PM
is this a product input plugin? whats it do?

You can always get the values dynamically.
You can even CREATE the params dynamically.

To get the values dynamically on front end, just do it in this method.
function plgVmOnDisplayProductFEVM3

To CREATE the params dynamically.
You just query database and set  $varsToPush as your params
$this->setConfigParameterable('customfield_params',$varsToPush);

yes, it's a custom plugin but I need to modify this value from outside of this plugin with a standalone script.
This is why I need to parse the content of the table field.