Search code examples
phparraysprestashopsmarty

How to save array value as configuration value in Prestashop 1.6


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