zibrnp Posted May 2, 2017 Share Posted May 2, 2017 Hello, I am trying to get blank schema for products resource and I get this error: [PHP Warning #2] Illegal string offset 'required' (.../classes/webservice/WebserviceOutputBuilder.php, line 711) Does anyone please know how to fix it? I am using prestashop 1.7.1.0 Thanks in advance. 1 Link to comment Share on other sites More sharing options...
hanshuckebein Posted May 27, 2017 Share Posted May 27, 2017 I get the same message. Any idea? Link to comment Share on other sites More sharing options...
shokinro Posted May 28, 2017 Share Posted May 28, 2017 Can you try to change following line (#709) in red in file /classes/webservice/WebserviceOutputBuilder.php From $arr_details = ''; To $arr_details = array(); public function getSynopsisDetails($field) { $arr_details = ''; if (array_key_exists('required', $field) && $field['required']) { $arr_details['required'] = 'true'; } Link to comment Share on other sites More sharing options...
zibrnp Posted May 30, 2017 Author Share Posted May 30, 2017 I get the same message. Any idea? I did not find the solution only because I was getting this error on my test server. Once I configured production server everything works perfectly ok. Did you try solution by "shokinro" Thanks Link to comment Share on other sites More sharing options...
shokinro Posted May 31, 2017 Share Posted May 31, 2017 The issue might be related to PHP version and server environment. Link to comment Share on other sites More sharing options...
zibrnp Posted May 31, 2017 Author Share Posted May 31, 2017 As mentioned earlier, when I installed PS on production server blank schema for products work without problems. As a test, I copied files from production to local box (MAMP) and now it works without problems. My local environment did not change so it would suggest that something was wrong with configuration of PS. But I am not sure what. MAMP - PHP 7.1.0 Production - PHP 7.0.19 Link to comment Share on other sites More sharing options...
shokinro Posted June 1, 2017 Share Posted June 1, 2017 Have you tried my solution? From the code, the variable $arr_details is initialised as string, but it used as array, I guess that causes the issue. 1 Link to comment Share on other sites More sharing options...
svalera Posted June 7, 2017 Share Posted June 7, 2017 I've tried shokinro's solutions and it works perfectly! Thanks! Link to comment Share on other sites More sharing options...
shokinro Posted June 8, 2017 Share Posted June 8, 2017 @svalera I am glad it helped and thanks for your feedback. Link to comment Share on other sites More sharing options...
Brian Schuster Posted December 29, 2022 Share Posted December 29, 2022 Hi @shokinro I looked at that line of code in my version of Prestashop (1.7.8.7), and I see that the arr_details variable is already set to an array, but I am still getting similar errors as the original poster. public function getSynopsisDetails($field) { $arr_details = []; if (array_key_exists('required', $field) && $field['required']) { $arr_details['required'] = 'true'; } if (array_key_exists('maxSize', $field) && $field['maxSize']) { $arr_details['maxSize'] = $field['maxSize']; } if (array_key_exists('validateMethod', $field) && $field['validateMethod']) { $arr_details['format'] = $field['validateMethod']; } if (array_key_exists('setter', $field) && !$field['setter']) { $arr_details['readOnly'] = 'true'; } return $arr_details; } The errors I get show that I have problems within this code in the same file: foreach ($fields_assoc as $field_name => $field) { if (!is_array($this->fieldsToDisplay) || in_array($field_name, $this->fieldsToDisplay[$assoc_name])) { if ($field_name == 'id' && !isset($field['sqlId'])) { $field['sqlId'] = 'id'; $field['value'] = $object_assoc['id']; } elseif (!isset($field['sqlId'])) { $field['sqlId'] = $field_name; $field['value'] = $object_assoc[$field_name]; } $field['entities_name'] = $assoc_name; $field['entity_name'] = $resource_name; if (null !== $this->schemaToDisplay) { $field['synopsis_details'] = $this->getSynopsisDetails($field); } $field['is_association'] = true; $output .= $this->setIndent($depth - 1) . $this->objectRender->renderField($field); } } $output .= $this->setIndent($depth - 1) . $this->objectRender->renderNodeFooter($resource_name, []); return $output; Link to comment Share on other sites More sharing options...
Brian Schuster Posted January 3, 2023 Share Posted January 3, 2023 I believe I have fixed the issue with metadata not showing up when using the query parameter schema=synopsis in the API. I used the following code at line 713 in prestashop/classes/webservice/WebServiceOutputBuilder.php (version 1.7.8.7), shown with changes to $field['value'] on two lines and a new conditional statement: if (!is_array($this->fieldsToDisplay) || in_array($field_name, $this->fieldsToDisplay[$assoc_name])) { if ($field_name == 'id' && !isset($field['sqlId'])) { $field['sqlId'] = 'id'; $field['value'] = (!empty($object_assoc)) ? $object_assoc['id'] : ''; } elseif (!isset($field['sqlId'])) { $field['sqlId'] = $field_name; if (!property_exists((object)$object_assoc, $field_name)) { $object_assoc[$field_name] = ''; }; $field['value'] = $object_assoc[$field_name]; } $field['entities_name'] = $assoc_name; $field['entity_name'] = $resource_name; if (null !== $this->schemaToDisplay) { $field['synopsis_details'] = $this->getSynopsisDetails($field); } $field['is_association'] = true; $output .= $this->setIndent($depth - 1) . $this->objectRender->renderField($field); } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now