Skip to content
This repository has been archived by the owner on Jun 13, 2021. It is now read-only.

Improve serialization #1

Closed
davidtsadler opened this issue Aug 2, 2015 · 3 comments
Closed

Improve serialization #1

davidtsadler opened this issue Aug 2, 2015 · 3 comments

Comments

@davidtsadler
Copy link
Owner

Look at improving the serialization of the SDK.

One possible solution is for the SDK to implement the Serializable interface

Another solution is to improve the passing of property values via the constructor. At the moment it is possible to do the following.

$item->Variations->Variation[] = new Types\VariationType(array(
    'SKU' => 'TS-W-S',
    'Quantity' => 5,
    'StartPrice' => new Types\AmountType(array('value' => 10.99)),
    'VariationSpecifics' => array(new Types\NameValueListArrayType(array(
        'NameValueList' => array(
            new Types\NameValueListType(array('Name' => 'Color', 'Value' => array('White'))),
            new Types\NameValueListType(array('Name' => "Size (Men's)", 'Value' => array('S')))
        )
    )))
));

However the above method involves constructing objects before passing them via the array. An improvement would be to also allow the following.

$item->Variations->Variation[] = new Types\VariationType(array(
    'SKU' => 'TS-W-S',
    'Quantity' => 5,
    'StartPrice' => array('value' => 10.99),
    'VariationSpecifics' => array((array(
        'NameValueList' => array(
            array('Name' => 'Color', 'Value' => array('White')),
            array('Name' => "Size (Men's)", 'Value' => array('S'))
        )
    )))
));

This solution could allow the usage shown below when calling the toArray method.

if (Cache::has($key)) {
    // Create a new instance and populates its properties with values from the cache.
    $results = new FindItemsAdvancedResponse(Cache::get($key));
    return $results;
}

$results = $service->findItemsAdvanced($this->request);

// Cache the values of the response object.
// toArray returns an assoicated array of the response object properties.
Cache::put($key,$results->toArray(),24*60);
@davidtsadler
Copy link
Owner Author

Implemented in d8457f4

stiivo added a commit to stiivo/ebay-sdk-php that referenced this issue Apr 28, 2017
```php
<?php
use DTS\eBaySDK\Fulfillment\Types;
use DTS\eBaySDK\Fulfillment\Services;
use DTS\eBaySDK\Fulfillment\Types\GetOrdersRestRequest;

require_once __DIR__.'/vendor/autoload.php';

$token = "token";



$service = new Services\FulfillmentService([
  'authorization' => $token
]);

$request = new GetOrdersRestRequest();

$request->filter = "creationdate:[2017-04-27T08:25:43.511Z..]";

$response = $service->getOrders($request);

file_put_contents("test.json", json_encode($response->toArray(), JSON_PRETTY_PRINT));
```

brought me this:

    PHP Fatal error:  Uncaught DTS\eBaySDK\Exceptions\UnknownPropertyException: Unknown property discountAmount in /home/steven/Schreibtisch/eBayTrackingNumber/vendor/dts/ebay-sdk-php/src/Types/BaseType.php:464
    Stack trace:
    #0 /home/steven/Schreibtisch/eBayTrackingNumber/vendor/dts/ebay-sdk-php/src/Types/BaseType.php(309): DTS\eBaySDK\Types\BaseType::ensurePropertyExists('DTS\\eBaySDK\\Typ...', 'discountAmount')
    davidtsadler#1 /home/steven/Schreibtisch/eBayTrackingNumber/vendor/dts/ebay-sdk-php/src/Types/BaseType.php(276): DTS\eBaySDK\Types\BaseType->set('DTS\\eBaySDK\\Typ...', 'discountAmount', Array)
    davidtsadler#2 /home/steven/Schreibtisch/eBayTrackingNumber/vendor/dts/ebay-sdk-php/src/Types/BaseType.php(62): DTS\eBaySDK\Types\BaseType->setValues('DTS\\eBaySDK\\Typ...', Array)
    davidtsadler#3 /home/steven/Schreibtisch/eBayTrackingNumber/vendor/dts/ebay-sdk-php/src/Fulfillment/Types/DeliveryCost.php(58): DTS\eBaySDK\Types\BaseType->__construct(Array)
    davidtsadler#4 /home/steven/Schreibtisch/eBayTrackingNumber/vendor/dts/ebay-sdk-php/src/Types/BaseType.php(676): DTS\eBaySDK\Ful in /home/steven/Schreibtisch/eBayTrackingNumber/vendor/dts/ebay-sdk-php/src/Types/BaseType.php on line 464

adding the discountAmount property manually made it work for me.
@izshreyansh
Copy link

How do you convert \DTS\eBaySDK\Trading\Types\GetAccountResponseType response to array?
I'm trying to save this whole object in Cache for later use.

  • If i simply type cast it to array & populate it while retrieval: I get this Unknown property DTS\eBaySDK\Types\BaseTypevalue error. Which is rightfully so caused by array having: BaseType key.

Can anyone help please?

@izshreyansh
Copy link

It's what becomes of the array as i typecast it from response object.

   array (size=2)
  '�DTS\eBaySDK\Types\BaseType�values' => 
    array (size=11)
      'Timestamp' => 
        object(DateTime)[571] ```

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants