Jump to content

Error/Warning when getting products schema.


zibrnp

Recommended Posts

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.

  • Like 1
Link to comment
Share on other sites

  • 4 weeks later...

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

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

  • 5 years later...

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...