0

need to pass following object:

{  
   "category_code":"43",
   "attribute_filters":[  
      {  
         "price":{  
            "lte":20
         }
      },
      {  
         "vintage":{  
            "eq":"blue"
         }
      },
      {  
         "size":{  
            "in":[  
               "medium",
               "large"
            ]
         }
      }
   ],
   "attribute_include":[  
      "type",
      "color",
      "size",
      "sku"
   ]
}'

to custom API method:

 * @api
 *
 * @param int $category_code
 * @param string[] $attribute_filters
 * @param string[] $attribute_include
 *
 *
 * @return string JSON encoded objects data
 */

public function myMethod($category_code, $attribute_filters, $attribute_include);

But in result r receive following exception:

{"message":"Notice: Array to string conversion in ... TypeProcessor.php ...}

It is required to keep object in this format, as this is presented by specifications, how should i properly set the doctypes vars for this API to receive data ?

UPD

tried to make

@param \Magento\Framework\DataObject[] $attribute_filters

but it throws :

{"message":"Property \"Price\" does not have corresponding setter in class \"Magento\\Framework\\DataObject\"...}

Seems like it doesnt recognize magic setters and getter via ReflectionClass

  • Did you get some solution @Anonymous ..Facing the same problem – Mohammad Mujassam Nov 9 '16 at 6:27
  • yes, I did, but i had to slightly change the input format, will post my answer here. – Ilja Nov 9 '16 at 9:36
1

Seems like there's no other option than change format to following:

  "attribute_filters" : 
  [  
    {
      "attribute" : price",
      "condition" : {  
        "lte":20
       }
    }
  ],

Then, I registered simple custom storage custom model AttributeFilter with getters and setters:

<?php

class AttributeFilter
{

  public $attribute;
  public $condition;

  /**
   * Set attribute code
   *
   * @param $attr
   */
  public function setAttribute($attr)
  {

      $this->attribute = $attr;
  }

  /**
   * Get attribute code
   * @return mixed
   */
  public function getAttribute()
  {

      return $this->condition;
  }

  /**
   * Set
   *
   * @param $condition
   */
  public function setCondition($condition)
  {
      $this->condition = $condition;
  }

  /**
   * @return mixed
   */
  public function getCondition()
  {
      return $this->condition;
  }


}

and then, declared in api interface:

* @param \My\Module\Model\AttributeFilter[] $attribute_filters

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.