2

I'm dealing with the import plugin, processing a .csv file. in the .csv there's a column with | separated values that shoud be inserted in a table field. The entry are created correctly, also the table field ( just 1 column ) has the correct number of rows, but the content is empty ( $featureContent length is > 0 ). Here's the code, what am I missing?

foreach ($fields as $handle => $value) {

   $value = explode('|', $value);
   $content[$handle] = array();

   foreach ( $value as $featureContent ) {                       
      $featuresRow = array( 'singleFeature' => $featureContent );
      array_push( $content[$handle], $featuresRow);                             
   }

 }

--- Edit ---

According to this response the table data is stored in Json format, so now I'm trying to create the table providing a json formatted string. As this:

[
  {"col1":"very beautiful"},
  {"col1":"really beautiful"},
  {"col1":"astonishing beautiful"}

]

Still, this doesn't work for me. It doesn't even creates the 3 rows as the other approach.

2

The answer on the previous question is a little bit off - you do not want to use json_encode to save the field. Just use the actual array:

$tableValue = [
  [
    "col1": "Product #1",
    "col2": "5",
    "col3": "10",
    "col4": "15"
  ],
  [
    "col1": "Product #2",
    "col2": "7",
    "col3": "14",
    "col4": "21"
  ],
  [
    "col1": "Product #3",
    "col2": "7",
    "col3": "14",
    "col4": "21"
  ]
];

$entry->setContentFromPost(array(
  'tableField'=> $tableValue,
));

Note that 'col1', 'col2', etc, refer to locations in the table. The handle of the table column is not used.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.