WsdlToPhp / PackageGenerator

Generates a PHP SDK based on a WSDL, simple and powerful, WSDL to PHP
https://providr.io
MIT License
418 stars 73 forks source link

SoapClient not serializing attributes of child classes #314

Closed datWeazel closed 1 month ago

datWeazel commented 1 month ago

Describe the bug I got a generated class ArrayOfBasketItem which in turn got an array of BasketItem objects. BasketItem is a base class for different types of items. One of those is ExpositionPeriodReservation.

I created a new ArrayOfBasketItem with one ExpositionPeriodReservation and tried to send it via the Soap Client to the service.

BasketItem provides some attributes like id and quantity. ExpositionPeriodReservation got additional parameters like expositionId, expositionPeriodId and more.

$myExpositionPeriodReservation = new ExpositionPeriodReservation(...);
$parameters = new ArrayOfBasketItem([$myExpositionPeriodReservation]);
$this->setResult($resultLockBasketItems = $this->getSoapClient()->__soapCall('LockBasketItems', [
                $parameters,
            ], [], [], $this->outputHeaders));

The generated XML (in __getLastRequest) looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:ns1="http://www.xxx.be/webshop/"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <SOAP-ENV:Header />
    <SOAP-ENV:Body>
        <ns1:LockBasketItemsRequest>
            <ns1:BasketItems>
                <ns1:BasketItem>
                    <ns1:Id>3f717c96-2200-424d-b987-2b9bf58c1357</ns1:Id>
                    <ns1:Quantity>1</ns1:Quantity>
                    <ns1:RuleNamesToIgnore xsi:nil="true" />
                </ns1:BasketItem>
            </ns1:BasketItems>
            <ns1:Context>
                <ns1:ShopId>xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx</ns1:ShopId>
                <ns1:Password>xxxxx</ns1:Password>
            </ns1:Context>
        </ns1:LockBasketItemsRequest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

So it is missing all of the attributes of the ExpositionPeriodReservation and only got the attributes of BasketItem.

I uploaded the BasketItem and ExpositionPeriodReservation class files as well as the generated client file for the method I try to use:

BasketItem.txt ExpositionPeriodReservation.txt Lock.txt

This is the full object that's in $parameters of the __soapCall: (There's another object of type LockBasketItemsRequest around it, but that's irrelevant for the problem.

App\Lib\xxx\Generated\StructType\LockBasketItemsRequest Object
(
    [BasketItems:protected] => App\Lib\xxx\Generated\ArrayType\ArrayOfBasketItem Object
        (
            [internArray:WsdlToPhp\PackageBase\AbstractStructArrayBase:private] => Array
                (
                )

            [internArrayIsArray:WsdlToPhp\PackageBase\AbstractStructArrayBase:private] => 
            [internArrayOffset:WsdlToPhp\PackageBase\AbstractStructArrayBase:private] => 0
            [BasketItem:protected] => Array
                (
                    [0] => App\Lib\xxx\Generated\StructType\ExpositionPeriodReservation Object
                        (
                            [Quantity:protected] => 1
                            [UnitPrice:protected] => 
                            [AdvancementPrice:protected] => 
                            [AsReseller:protected] => 
                            [PromotionRuleDiscountAmount:protected] => 
                            [DivisionId:protected] => 
                            [Id:protected] => 3f717c96-2200-424d-b987-2b9bf58c1357
                            [RuleNamesToIgnore:protected] => 
                            [CustomerContactId:protected] => 
                            [OrderWithoutPayment:protected] => 
                            [WaiterPadDiscountPercentage:protected] => 
                            [Entries:protected] => App\Lib\xxx\Generated\ArrayType\ArrayOfExpositionPeriodReservationEntry Object
                                (
                                    [internArray:WsdlToPhp\PackageBase\AbstractStructArrayBase:private] => Array
                                        (
                                        )

                                    [internArrayIsArray:WsdlToPhp\PackageBase\AbstractStructArrayBase:private] => 
                                    [internArrayOffset:WsdlToPhp\PackageBase\AbstractStructArrayBase:private] => 0
                                    [ExpositionPeriodReservationEntry:protected] => Array
                                        (
                                            [0] => App\Lib\xxx\Generated\StructType\ExpositionPeriodReservationEntry Object
                                                (
                                                    [ParticipantCount:protected] => 2
                                                    [PromotionRuleDiscountAmount:protected] => 
                                                    [Amount:protected] => 
                                                    [PriceGroupId:protected] => c23dfa75-25cf-ee11-a334-abb7811cc7f0
                                                )

                                            [1] => App\Lib\xxx\Generated\StructType\ExpositionPeriodReservationEntry Object
                                                (
                                                    [ParticipantCount:protected] => 3
                                                    [PromotionRuleDiscountAmount:protected] => 
                                                    [Amount:protected] => 
                                                    [PriceGroupId:protected] => 6549a6c3-63d1-ee11-a334-abb7811cc7f0
                                                )

                                        )

                                )

                            [ExpositionPeriodId:protected] => c6daecb0-8faf-4df4-bbb3-c7b16be980db
                            [ExpositionId:protected] => cd78f077-da1c-ef11-a337-dca22e30ef70
                        )

                )

        )

    [Context:protected] => App\Lib\xxx\Generated\StructType\ServiceContext Object
        (
            [Origin:protected] => 
            [Encode:protected] => 
            [DivisionId:protected] => 
            [ShopId:protected] => xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
            [SessionId:protected] => 
            [Password:protected] => xxxx
        )

)
mikaelcom commented 1 month ago

Hi, This is possibly due to the native PHP SoapClient class that does not map all the attributes from the ExpositionPeriodReservation to an XML structure. Is the ExpositionPeriodReservation indeed defined in the WSDL? You'll probably have to override the SoapClient class, as I did at https://github.com/WsdlToPhp/PackageEws365, in order to alter the XML before it is actually sent. You'll have to check the Parameter instance type in order to map the PHP class properties to their XML tag. Let me know anyway