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

Modify #__virtuemart_product_customfields.customfield_params progmatically

Started by sandomatyas, July 19, 2019, 10:34:25 AM

Previous topic - Next topic

sandomatyas

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.

PRO

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);

Studio 42

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

sandomatyas

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.