Magento 2. Make soap response as array The Next CEO of Stack OverflowMagento SOAP (v1) API causes fatal error getSelect() after completed orderMagento 1.9 Soap Api Response 500 Internal server errorMagento SOAP API Slow Response need Solution?I make the soap call catalogCategoryInfo callmain.CRITICAL: Plugin class doesn't existSOAP API V2 Response logCan't get product manufacturer attribute in my custom moduleHow to Update Magento 2 configurable child products price by REST APIHow to solve Front controller reached 100 router match iterations in magento2Magento 2.3 Can't view module's front end page output?
The exact meaning of 'Mom made me a sandwich'
How do I align (1) and (2)?
Running a General Election and the European Elections together
Can you be charged for obstruction for refusing to answer questions?
Is French Guiana a (hard) EU border?
Is there a difference between "Fahrstuhl" and "Aufzug"
How to invert MapIndexed on a ragged structure? How to construct a tree from rules?
Is there always a complete, orthogonal set of unitary matrices?
Is it okay to majorly distort historical facts while writing a fiction story?
Why does standard notation not preserve intervals (visually)
Why do airplanes bank sharply to the right after air-to-air refueling?
Solving system of ODEs with extra parameter
Make solar eclipses exceedingly rare, but still have new moons
Grabbing quick drinks
I believe this to be a fraud - hired, then asked to cash check and send cash as Bitcoin
Is wanting to ask what to write an indication that you need to change your story?
How to check if all elements of 1 list are in the *same quantity* and in any order, in the list2?
What did we know about the Kessel run before the prequels?
Why isn't acceleration always zero whenever velocity is zero, such as the moment a ball bounces off a wall?
Proper way to express "He disappeared them"
How did people program for Consoles with multiple CPUs?
Why the difference in type-inference over the as-pattern in two similar function definitions?
Does increasing your ability score affect your main stat?
Why isn't the Mueller report being released completely and unredacted?
Magento 2. Make soap response as array
The Next CEO of Stack OverflowMagento SOAP (v1) API causes fatal error getSelect() after completed orderMagento 1.9 Soap Api Response 500 Internal server errorMagento SOAP API Slow Response need Solution?I make the soap call catalogCategoryInfo callmain.CRITICAL: Plugin class doesn't existSOAP API V2 Response logCan't get product manufacturer attribute in my custom moduleHow to Update Magento 2 configurable child products price by REST APIHow to solve Front controller reached 100 router match iterations in magento2Magento 2.3 Can't view module's front end page output?
I'm implementing custom API for Magento 2. My client want the response to be as associative array.
Here is my class method:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return array
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
Here is interface declaration:
interface GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return array
*/
public function list($products = NULL);
I've added logs and I see that my method list executing. But in response I'm getting 500 error.
In exception.log I see the error:
Message: Class "array" does not exist. Please note that namespace must be specified.
I want to get the following response:
array (size=2)
0 =>
array (size=4)
'product_id' => string '3708' (length=4)
'sku' => string 'W3L2221LDCB2' (length=12)
'qty' => string '228.0000' (length=8)
'is_in_stock' => string '1' (length=1)
1 =>
array (size=4)
'product_id' => string '3709' (length=4)
'sku' => string 'W7L1226E5C96' (length=12)
'qty' => string '23.0000' (length=7)
'is_in_stock' => string '1' (length=1)
Can I get SOAP response as associative array somehow?
Thanks,
magento2 api soap
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I'm implementing custom API for Magento 2. My client want the response to be as associative array.
Here is my class method:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return array
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
Here is interface declaration:
interface GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return array
*/
public function list($products = NULL);
I've added logs and I see that my method list executing. But in response I'm getting 500 error.
In exception.log I see the error:
Message: Class "array" does not exist. Please note that namespace must be specified.
I want to get the following response:
array (size=2)
0 =>
array (size=4)
'product_id' => string '3708' (length=4)
'sku' => string 'W3L2221LDCB2' (length=12)
'qty' => string '228.0000' (length=8)
'is_in_stock' => string '1' (length=1)
1 =>
array (size=4)
'product_id' => string '3709' (length=4)
'sku' => string 'W7L1226E5C96' (length=12)
'qty' => string '23.0000' (length=7)
'is_in_stock' => string '1' (length=1)
Can I get SOAP response as associative array somehow?
Thanks,
magento2 api soap
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I'm implementing custom API for Magento 2. My client want the response to be as associative array.
Here is my class method:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return array
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
Here is interface declaration:
interface GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return array
*/
public function list($products = NULL);
I've added logs and I see that my method list executing. But in response I'm getting 500 error.
In exception.log I see the error:
Message: Class "array" does not exist. Please note that namespace must be specified.
I want to get the following response:
array (size=2)
0 =>
array (size=4)
'product_id' => string '3708' (length=4)
'sku' => string 'W3L2221LDCB2' (length=12)
'qty' => string '228.0000' (length=8)
'is_in_stock' => string '1' (length=1)
1 =>
array (size=4)
'product_id' => string '3709' (length=4)
'sku' => string 'W7L1226E5C96' (length=12)
'qty' => string '23.0000' (length=7)
'is_in_stock' => string '1' (length=1)
Can I get SOAP response as associative array somehow?
Thanks,
magento2 api soap
I'm implementing custom API for Magento 2. My client want the response to be as associative array.
Here is my class method:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return array
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
Here is interface declaration:
interface GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return array
*/
public function list($products = NULL);
I've added logs and I see that my method list executing. But in response I'm getting 500 error.
In exception.log I see the error:
Message: Class "array" does not exist. Please note that namespace must be specified.
I want to get the following response:
array (size=2)
0 =>
array (size=4)
'product_id' => string '3708' (length=4)
'sku' => string 'W3L2221LDCB2' (length=12)
'qty' => string '228.0000' (length=8)
'is_in_stock' => string '1' (length=1)
1 =>
array (size=4)
'product_id' => string '3709' (length=4)
'sku' => string 'W7L1226E5C96' (length=12)
'qty' => string '23.0000' (length=7)
'is_in_stock' => string '1' (length=1)
Can I get SOAP response as associative array somehow?
Thanks,
magento2 api soap
magento2 api soap
asked Nov 6 '17 at 13:51
HelmsmantestHelmsmantest
162
162
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 15 mins ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Rewrite your class as:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return mixed[]
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
You can see the change in return type: array
-> mixed[]
It's strongly advised to use Data interface in such cases even though mixed[]
will work for you.
In this case.Instead of associative array i'm getting std object:stdClass Object ( [result] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [key] => product_id [value] => 1 ) ...
– Helmsmantest
Nov 6 '17 at 15:12
then cast with(array) $result
after you get the result.
– MagePsycho
Nov 6 '17 at 15:13
Unfortunatelly we can not modify code on the client's side. Is there some other method to get associative array as the result of soap function calling?
– Helmsmantest
Nov 6 '17 at 16:01
Any updates, guys?
– Helmsmantest
Nov 9 '17 at 14:39
add a comment |
Once you've received the response from Magento, you can use the following snippet to convert the SOAP object into a PHP associative array:
<?php
$response = simplexml_load_string($soapResponse->any);
$response = json_decode(json_encode($response), true);
Assuming that $soapResponse->any
has this content:
<data count="1" count_available="1">
<row id="1">
<sku>1830DMG</sku>
<price>74.06</price>
<stockid>519745</stockid>
</row>
</data>
You'll get an array which looks like this:
$ php -f apitest3.php
array(2)
["@attributes"]=>
array(2)
["count"]=>
string(1) "1"
["count_available"]=>
string(1) "1"
["row"]=>
array(4)
["@attributes"]=>
array(1)
["id"]=>
string(1) "1"
["sku"]=>
string(7) "1830DMG"
["price"]=>
string(5) "74.06"
["stockid"]=>
string(6) "519745"
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f200224%2fmagento-2-make-soap-response-as-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Rewrite your class as:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return mixed[]
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
You can see the change in return type: array
-> mixed[]
It's strongly advised to use Data interface in such cases even though mixed[]
will work for you.
In this case.Instead of associative array i'm getting std object:stdClass Object ( [result] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [key] => product_id [value] => 1 ) ...
– Helmsmantest
Nov 6 '17 at 15:12
then cast with(array) $result
after you get the result.
– MagePsycho
Nov 6 '17 at 15:13
Unfortunatelly we can not modify code on the client's side. Is there some other method to get associative array as the result of soap function calling?
– Helmsmantest
Nov 6 '17 at 16:01
Any updates, guys?
– Helmsmantest
Nov 9 '17 at 14:39
add a comment |
Rewrite your class as:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return mixed[]
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
You can see the change in return type: array
-> mixed[]
It's strongly advised to use Data interface in such cases even though mixed[]
will work for you.
In this case.Instead of associative array i'm getting std object:stdClass Object ( [result] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [key] => product_id [value] => 1 ) ...
– Helmsmantest
Nov 6 '17 at 15:12
then cast with(array) $result
after you get the result.
– MagePsycho
Nov 6 '17 at 15:13
Unfortunatelly we can not modify code on the client's side. Is there some other method to get associative array as the result of soap function calling?
– Helmsmantest
Nov 6 '17 at 16:01
Any updates, guys?
– Helmsmantest
Nov 9 '17 at 14:39
add a comment |
Rewrite your class as:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return mixed[]
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
You can see the change in return type: array
-> mixed[]
It's strongly advised to use Data interface in such cases even though mixed[]
will work for you.
Rewrite your class as:
class Gcapiapi implements GcapiapiInterface
/**
* Returns greeting message to user
*
* @param string[] $products
* @return mixed[]
*/
public function list($products = NULL)
$result = array();
$stockItems = ...
...
foreach($stockItems as $stockItem)
$itemData = array('product_id' => $product->getId(), 'sku' => $productSku, 'qty' => $stockItem->getQty(), 'is_in_stock' => $stockItem->getIsInStock());
$result[] = $itemData;
return $result;
You can see the change in return type: array
-> mixed[]
It's strongly advised to use Data interface in such cases even though mixed[]
will work for you.
answered Nov 6 '17 at 14:40
MagePsychoMagePsycho
3,24711944
3,24711944
In this case.Instead of associative array i'm getting std object:stdClass Object ( [result] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [key] => product_id [value] => 1 ) ...
– Helmsmantest
Nov 6 '17 at 15:12
then cast with(array) $result
after you get the result.
– MagePsycho
Nov 6 '17 at 15:13
Unfortunatelly we can not modify code on the client's side. Is there some other method to get associative array as the result of soap function calling?
– Helmsmantest
Nov 6 '17 at 16:01
Any updates, guys?
– Helmsmantest
Nov 9 '17 at 14:39
add a comment |
In this case.Instead of associative array i'm getting std object:stdClass Object ( [result] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [key] => product_id [value] => 1 ) ...
– Helmsmantest
Nov 6 '17 at 15:12
then cast with(array) $result
after you get the result.
– MagePsycho
Nov 6 '17 at 15:13
Unfortunatelly we can not modify code on the client's side. Is there some other method to get associative array as the result of soap function calling?
– Helmsmantest
Nov 6 '17 at 16:01
Any updates, guys?
– Helmsmantest
Nov 9 '17 at 14:39
In this case.Instead of associative array i'm getting std object:stdClass Object ( [result] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [key] => product_id [value] => 1 ) ...
– Helmsmantest
Nov 6 '17 at 15:12
In this case.Instead of associative array i'm getting std object:stdClass Object ( [result] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [item] => Array ( [0] => stdClass Object ( [key] => product_id [value] => 1 ) ...
– Helmsmantest
Nov 6 '17 at 15:12
then cast with
(array) $result
after you get the result.– MagePsycho
Nov 6 '17 at 15:13
then cast with
(array) $result
after you get the result.– MagePsycho
Nov 6 '17 at 15:13
Unfortunatelly we can not modify code on the client's side. Is there some other method to get associative array as the result of soap function calling?
– Helmsmantest
Nov 6 '17 at 16:01
Unfortunatelly we can not modify code on the client's side. Is there some other method to get associative array as the result of soap function calling?
– Helmsmantest
Nov 6 '17 at 16:01
Any updates, guys?
– Helmsmantest
Nov 9 '17 at 14:39
Any updates, guys?
– Helmsmantest
Nov 9 '17 at 14:39
add a comment |
Once you've received the response from Magento, you can use the following snippet to convert the SOAP object into a PHP associative array:
<?php
$response = simplexml_load_string($soapResponse->any);
$response = json_decode(json_encode($response), true);
Assuming that $soapResponse->any
has this content:
<data count="1" count_available="1">
<row id="1">
<sku>1830DMG</sku>
<price>74.06</price>
<stockid>519745</stockid>
</row>
</data>
You'll get an array which looks like this:
$ php -f apitest3.php
array(2)
["@attributes"]=>
array(2)
["count"]=>
string(1) "1"
["count_available"]=>
string(1) "1"
["row"]=>
array(4)
["@attributes"]=>
array(1)
["id"]=>
string(1) "1"
["sku"]=>
string(7) "1830DMG"
["price"]=>
string(5) "74.06"
["stockid"]=>
string(6) "519745"
add a comment |
Once you've received the response from Magento, you can use the following snippet to convert the SOAP object into a PHP associative array:
<?php
$response = simplexml_load_string($soapResponse->any);
$response = json_decode(json_encode($response), true);
Assuming that $soapResponse->any
has this content:
<data count="1" count_available="1">
<row id="1">
<sku>1830DMG</sku>
<price>74.06</price>
<stockid>519745</stockid>
</row>
</data>
You'll get an array which looks like this:
$ php -f apitest3.php
array(2)
["@attributes"]=>
array(2)
["count"]=>
string(1) "1"
["count_available"]=>
string(1) "1"
["row"]=>
array(4)
["@attributes"]=>
array(1)
["id"]=>
string(1) "1"
["sku"]=>
string(7) "1830DMG"
["price"]=>
string(5) "74.06"
["stockid"]=>
string(6) "519745"
add a comment |
Once you've received the response from Magento, you can use the following snippet to convert the SOAP object into a PHP associative array:
<?php
$response = simplexml_load_string($soapResponse->any);
$response = json_decode(json_encode($response), true);
Assuming that $soapResponse->any
has this content:
<data count="1" count_available="1">
<row id="1">
<sku>1830DMG</sku>
<price>74.06</price>
<stockid>519745</stockid>
</row>
</data>
You'll get an array which looks like this:
$ php -f apitest3.php
array(2)
["@attributes"]=>
array(2)
["count"]=>
string(1) "1"
["count_available"]=>
string(1) "1"
["row"]=>
array(4)
["@attributes"]=>
array(1)
["id"]=>
string(1) "1"
["sku"]=>
string(7) "1830DMG"
["price"]=>
string(5) "74.06"
["stockid"]=>
string(6) "519745"
Once you've received the response from Magento, you can use the following snippet to convert the SOAP object into a PHP associative array:
<?php
$response = simplexml_load_string($soapResponse->any);
$response = json_decode(json_encode($response), true);
Assuming that $soapResponse->any
has this content:
<data count="1" count_available="1">
<row id="1">
<sku>1830DMG</sku>
<price>74.06</price>
<stockid>519745</stockid>
</row>
</data>
You'll get an array which looks like this:
$ php -f apitest3.php
array(2)
["@attributes"]=>
array(2)
["count"]=>
string(1) "1"
["count_available"]=>
string(1) "1"
["row"]=>
array(4)
["@attributes"]=>
array(1)
["id"]=>
string(1) "1"
["sku"]=>
string(7) "1830DMG"
["price"]=>
string(5) "74.06"
["stockid"]=>
string(6) "519745"
answered Jun 15 '18 at 10:34
ProcessEightProcessEight
7121417
7121417
add a comment |
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f200224%2fmagento-2-make-soap-response-as-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown