Serialized Field

edited February 2018 in Feature Requests
I have a frontend shopping cart over a fuelCMS website, which saves the cart data serialized in a "cart" field inside a "orders" table.
Based on this: http://docs.getfuelcms.com/general/models#serialized How does it supposes that "cart" field will be displayed in the CMS inside the "orders" model?

Thanks!

Comments

  • edited 9:53AM
    You can use the template field type which is repeatable and posts the data in a nested array format.
    http://docs.getfuelcms.com/general/forms#template
  • edited 9:53AM
    The field has been serialized but the data isn´t showed.

    Here is my code:

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');

    require_once(FUEL_PATH.'models/Base_module_model.php');

    class Orders_model extends Base_module_model {

    public $required = array('nombre',"apellido","empresa","email");
    public $serialized_fields = array('cart');

    function __construct()
    {
    parent::__construct('orders');
    }

    function list_items($limit = NULL, $offset = NULL, $col = 'name', $order = 'asc', $just_count = FALSE)
    {
    $this->db->select('id, nombre, apellido, email, date_added', FALSE);
    $data = parent::list_items($limit, $offset, $col, $order, $just_count);

    // check just_count is FALSE or else $data may not be a valid array
    if (empty($just_count))
    {
    foreach($data as $key => $val)
    {
    $data[$key]['nombre'] = htmlentities($val['nombre'], ENT_QUOTES, 'UTF-8');
    }
    }
    return $data;
    }

    function form_fields($values = array(), $related = array())
    {
    $fields = parent::form_fields($values, $related);

    // ******************* ADD CUSTOM FORM STUFF HERE *******************
    $fields["cart"] = array('display_label' => TRUE,
    'add_extra' => FALSE,
    'init_display' => 'none',
    'dblclick' => 'accordion',
    'repeatable' => TRUE,
    'style' => 'width: 900px;',
    'type' => 'template',
    'label' => 'detalles del carrito',
    'title_field' => 'name',
    'fields' => array(
    'Item' => array('type' => 'section', 'label' => '{__name__}'),
    'qty' => array('style' => 'width: 800px'),
    'name' => array("type"=>"text"),
    'price' => array('type' => 'textarea', 'style' => 'width: 800px; height: 500px;'),
    )
    );


    return $fields;
    }

    Thanks!
  • edited 9:53AM
    I'm not quite sure I understand what you mean by the data isn't showed? Where are you referring?
  • edited 9:53AM
    The data comes from the shopping cart using the cart library provided by CI 3.0
    When the user submits his cart, that data is inserted in an "orders" table.
  • edited 9:53AM
    OK. But when you say "the data isn't showed" where are you referring?
  • edited 9:53AM
    inside CMS.
  • edited 9:53AM
    Do i can send you a screenshot of the cms?
  • edited 9:53AM
    Yes, that would help.
  • edited 9:53AM
    Here is: https://ibb.co/bNnacx

    Thanks!
  • edited 9:53AM
    You have init_display parameter set to "none". That will have it set to collapsed requiring a you to double click the gray bar to display. Try commenting out that line.
  • edited 9:53AM
    Ok, but that isn`t a problem. When i do uncollapse the bar, the fields are empty.
  • edited 9:53AM
    $fields["cart"] = array('display_label' => TRUE,
    'add_extra' => FALSE,
    'dblclick' => 'accordion',
    'repeatable' => TRUE,
    'style' => 'width: 900px;',
    'type' => 'template',
    'label' => 'detalles del carrito',
    'title_field' => 'name',
    'fields' => array(
    'Item' => array('type' => 'section', 'label' => '{__name__}'),
    'qty' => array('style' => 'width: 800px'),
    'name' => array("type"=>"text"),
    'price' => array('type' => 'textarea', 'style' => 'width: 800px; height: 500px;'),
    )
    );
  • edited 9:53AM
    Are there any javascript console errors by chance? Or if you inspect the element DOM do you see any fields there that may be hidden? I don't see issues with the field code above at first glance.
Sign In or Register to comment.