PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, June 30, 2022

[FIXED] How to save array value as configuration value in Prestashop 1.6

 June 30, 2022     arrays, php, prestashop, smarty     No comments   

Issue

I have an array, for example:

[0] => Array
    (
      [id_order_state] => 2
      [name] => Text
    )

I want to save this value by using this code, but I can't.

Configuration::updateValue('SELECTED_STATUSES', $array);

In /classes/Configuration.php I have more information about this:

/**
     * Update configuration key and value into database (automatically insert if key does not exist)
     *
     * Values are inserted/updated directly using SQL, because using (Configuration) ObjectModel
     * may not insert values correctly (for example, HTML is escaped, when it should not be).
     * @TODO Fix saving HTML values in Configuration model
     *
     * @param string $key Key
     * @param mixed $values $values is an array if the configuration is multilingual, a single string else.
     * @param bool $html Specify if html is authorized in value
     * @param int $id_shop_group
     * @param int $id_shop
     * @return bool Update result
     */
    public static function updateValue($key, $values, $html = false, $id_shop_group = null, $id_shop = null)

Thanks for any help.


Solution

$key and $values are string parameters so you can serialize() the array to a string then unserialize() it later

sample code:

Configuration::updateValue('SELECTED_STATUSES', serialize($array));


Answered By - ehmad11
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing