Hello all,
I'm trying to display in the response an element with the underscore character, but I can't (i'm getting an error).
For example I should have <increment_id>123456</increment_id>
Following is the situation:
this is the interface and i must have in the response the element
<?php namespace Sibyl\Ctm\Api\Data; interface SibylDataOrder2Interface { /** * Get value * * @return string */ public function getIncrement_Id(); /** * Return value * * @return void */ public function setIncrement_Id(String $temp); ...... ?>
and here the class implementing the previous interface
<?php // app/code/local/Sibyl/Ctm/Model/Order/SibylDataOrder2.php namespace Sibyl\Ctm\Model\Order; class SibylDataOrder2 implements \Sibyl\Ctm\Api\Data\SibylDataOrder2Interface{ public $increment_Id; public function getIncrement_Id(){ return $this->increment_Id; } public function setIncrement_Id(String $temp){ $this->increment_Id = $temp; } ..... ?>
When i call the service I get this error message:
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"><SOAP-ENV:Body><SOAP-ENV:Fault><faultcode>SOAP-ENV:Server</faultcode><faultstring>SOAP-ERROR: Encoding: object has no 'increment_Id' property</faultstring></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>{"messages":{"error":[{"code":500,"message":"Server internal error. See details in report api\/1549231960746"}]}}
But if i remove the _ (underscore) from methods (get and set) and variable increment_Id service working fine.
Can anyone help me?
Thanks in advance
Hello,
This is Magento standard and Magento standard follows PSR 1 and PSR 2.
https://devdocs.magento.com/guides/v2.3/coding-standards/code-standard-php.html
As per Magento Standard, your code should be as per the following.
In interface file (Sibyl\Ctm\Api\Data\SibylDataOrder2Interface)
<?php namespace Sibyl\Ctm\Api\Data; interface SibylDataOrder2Interface { /** * Get value * * @return string */ public function getIncrementId(); /** * Return value * * @return void */ public function setIncrementId(String $temp); ...... ?>
and in implemented Class ( Sibyl\Ctm\Model\Order\SibylDataOrder2 )
<?php // app/code/local/Sibyl/Ctm/Model/Order/SibylDataOrder2.php namespace Sibyl\Ctm\Model\Order; class SibylDataOrder2 implements \Sibyl\Ctm\Api\Data\SibylDataOrder2Interface{ public $increment_Id; public function getIncrementId(){ return $this->increment_Id; } public function setIncrementId(String $temp){ $this->increment_Id = $temp; } .... ?>
Enjoy Coding
If it helps then Click on Kudos and Accept as Solution.
Thank you
Hiren Patel
Hello Hiren_Patel,
first of all thank you you for helping.
I tried your solution but, nothing changed, in the soap response I don't see the underscore.
take a look following
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://xxxx/soap/all?services=sibylCtmCustomapiV1"> <SOAP-ENV:Body> <ns1:sibylCtmCustomapiV1OrderListResponse> <result> <item> <incrementId>100000158</incrementId> </item> </result> </ns1:sibylCtmCustomapiV1OrderListResponse> </SOAP-ENV:Body> </SOAP-ENV:Envelope>
Hello @login7qwmwb10a
Sorry I never heard about them.
If it helps click on Kudos and Accept as Solution.
Hiren Patel