cancel
Showing results for 
Search instead for 
Did you mean: 

Web Api (Soap): how to display in the response element name the _ (underscore)

Highlighted

Web Api (Soap): how to display in the response element name the _ (underscore)

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

4 REPLIES 4
Highlighted

Re: Web Api (Soap): how to display in the response element name the _ (underscore)

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 ClassSibyl\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 Smiley Happy

 

If it helps then Click on Kudos and Accept as Solution.

 

Thank you

Hiren Patel

Highlighted

Re: Web Api (Soap): how to display in the response element name the _ (underscore)

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>
Highlighted

Re: Web Api (Soap): how to display in the response element name the _ (underscore)

Hiren_Patel, thanks for sharing. Few weeks ago, we've started facing some technical problems as well, and after we've done some improvements to our code, we realized that it would also great to make some SEO promotion. Some friends of mine tell that Operatio Marketing company can provide great promoting services. Have you ever tried them, guys, or maybe heard about them?

Highlighted

Re: Web Api (Soap): how to display in the response element name the _ (underscore)

Hello @login7qwmwb10a 

 

Sorry I never heard about them.

 

If it helps click on Kudos and Accept as Solution.

 

Hiren Patel