Author Topic: Modify #__virtuemart_product_customfields.customfield_params progmatically  (Read 331 times)

sandomatyas

  • Jr. Member
  • **
  • Posts: 282
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

  • Global Moderator
  • Super Hero
  • *
  • Posts: 10377
  • VirtueMart Version: 3+
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);
J3.9+ VM 3.4.2
Slowest Page Speed Score (88) (Category)
Fastest Page Speed Score (94-96) (productdetails)

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 4067
  • Joomla & Virtuemart developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 & 3
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

  • Jr. Member
  • **
  • Posts: 282
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.