Closed bigappleinsider closed 8 years ago
Internal ticket: MAGETWO-40824
+1 for this issue.
Additional detail to help you replicate the situation is that there must be results for the query to return. So for example if you ask for order status pending and there is 0 orders, the result come back correctly with an empty array. If you ask for status pending and there are 1+ orders, you get the error described in the SO post.
@vpelipenko @mikhaill
In TypeCaster.php method castValueToType($value, $type)
throws the error because of incorrect arguments are passed in $type string, while $value is array. It's trying to cast array into a string.
I traced it down to another calling method in lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php - buildOutputDataArray($dataObject, $dataObjectType)
Return type is being determined by
$returnType = $this->methodsMapProcessor->getMethodReturnType($dataObjectType, $methodName);
Args that caused the issue: [dataObjectType] => \Magento\Sales\Api\Data\OrderItemInterface, [methodName] => getProductOptions
app/code/Magento/Sales/Api/Data/OrderItemInterface.php
and app/code/Magento/Sales/Model/Order/Item.php
Return annotations for getProductOptions
method should be
@return \Magento\Sales\Api\Data\OrderItemInterface[]
Cache folder will need to be cleared for the fix to take affect rm -rfv var/cache/*
Internal ticket: MAGETWO-40951
Dunno if something has changed, but getProductOptions
returns something like this:
Array
(
[info_buyRequest] => Array
(
[uenc] => aHR0cDovL3VrLmdyYXplLmRldi9wcm9kdWN0LTEuaHRtbA,,
[product] => 1
[selected_configurable_option] =>
[related_product] =>
[qty] => 1
)
[giftcard_lifetime] =>
[giftcard_is_redeemable] => 0
[giftcard_email_template] =>
[giftcard_type] =>
)
And that method's phpdoc says it returns string[]
(https://github.com/magento/magento2/blob/3e845470375b6903d79516276f3c1ffa00c9a8f3/app/code/Magento/Sales/Api/Data/OrderItemInterface.php#L859). Because of that, the object processor thinks that the returned array contains nothing but strings (https://github.com/magento/magento2/blob/develop/lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php#L110) and it tries to convert every element in that array to string. But, as you can see, the value at key info_buyRequest
cannot be just casted into a string, as that's an array.
The fix for me was to simply change the phpdoc of \Magento\Sales\Api\Data\OrderItemInterface::getProductOptions()
to @return array
, instead of @return string[]
.
So I'm not sure what you're saying, @bigappleinsider.
@adragus-inviqa awesome, can you push this fix?
Hi @bigappleinsider , @mikhaill , this bug was fixed. Described API request returns correct list of orders with correct statuses. searchCriteria also works correctly. @adragus-inviqa , getProductOptions() now returns \Magento\Catalog\Api\Data\ProductOptionInterface and phpdocs says the same. This bug is closed as resolved. Thank you all for your contribution and we are sorry for delay.
@NadiyaS : Any ETA on this release? It is keep our Magento2 integration with ERP down.
+1 Any update on when this will be released?
Do you have any insight into this issue? Is there something I'm missing?
http://magento.stackexchange.com/questions/75913/how-to-get-completed-sales-with-rest-api-in-magento-2
It works for
processing
status, however I get an error forcompleted
orclosed
result:
{"items":[]}
The log is as following:
Magento 2 Rest API: http://devdocs.magento.com/guides/v2.0/rest/restApi/restCollection/Magento/Sales/Service/V1/OrderList/orderList.html
Token-based authentication: http://devdocs.magento.com/guides/v2.0/get-started/authentication/gs-authentication-token.html
Thank you