3

I´m trying to display Ebay GetSingleItem response (http://developer.ebay.com/devzone/shopping/docs/callref/GetSingleItem.html) and I´m having problems displaying array ["ItemSpecifics"]. The call is working ok and I´m receiving the following information:

["ItemSpecifics"] => object(DTS\eBaySDK\Shopping\Types\NameValueListArrayType)#208 (2) {
          ["values":"DTS\eBaySDK\Types\BaseType":private] => array(1) {
            ["NameValueList"] => object(DTS\eBaySDK\Types\UnboundType)#129 (5) {
              ["data":"DTS\eBaySDK\Types\UnboundType":private] => array(8) {
                [0] => object(DTS\eBaySDK\Shopping\Types\NameValueListType)#207 (2) {
                  ["values":"DTS\eBaySDK\Types\BaseType":private] => array(2) {
                    ["Name"] => string(6) "Format"
                    ["Value"] => object(DTS\eBaySDK\Types\UnboundType)#191 (5) {
                      ["data":"DTS\eBaySDK\Types\UnboundType":private] => array(1) {
                        [0] => string(10) "DVD/HD-DVD"
                      }
                      ["position":"DTS\eBaySDK\Types\UnboundType":private] => int(0)
                      ["class":"DTS\eBaySDK\Types\UnboundType":private] => string(44) "DTS\eBaySDK\Shopping\Types\NameValueListType"
                      ["property":"DTS\eBaySDK\Types\UnboundType":private] => string(5) "Value"
                      ["expectedType":"DTS\eBaySDK\Types\UnboundType":private] => string(6) "string"
                    }
                  }
                  ["attachment":"DTS\eBaySDK\Types\BaseType":private] => array(2) {
                    ["data"] => NULL
                    ["mimeType"] => NULL
                  }
                }
                [1] => object(DTS\eBaySDK\Shopping\Types\NameValueListType)#65 (2) {
                  ["values":"DTS\eBaySDK\Types\BaseType":private] => array(2) {
                    ["Name"] => string(5) "Genre"
                    ["Value"] => object(DTS\eBaySDK\Types\UnboundType)#152 (5) {
                      ["data":"DTS\eBaySDK\Types\UnboundType":private] => array(1) {
                        [0] => string(16) "Sci-Fi & Fantasy"
                      }
                      ["position":"DTS\eBaySDK\Types\UnboundType":private] => int(0)
                      ["class":"DTS\eBaySDK\Types\UnboundType":private] => string(44) "DTS\eBaySDK\Shopping\Types\NameValueListType"
                      ["property":"DTS\eBaySDK\Types\UnboundType":private] => string(5) "Value"
                      ["expectedType":"DTS\eBaySDK\Types\UnboundType":private] => string(6) "string"
                    }
                  }
                  ["attachment":"DTS\eBaySDK\Types\BaseType":private] => array(2) {
                    ["data"] => NULL
                    ["mimeType"] => NULL
                  }
                }
                [2] => object(DTS\eBaySDK\Shopping\Types\NameValueListType)#180 (2) {
                  ["values":"DTS\eBaySDK\Types\BaseType":private] => array(2) {
                    ["Name"] => string(7) "Edition"
                    ["Value"] => object(DTS\eBaySDK\Types\UnboundType)#253 (5) {
                      ["data":"DTS\eBaySDK\Types\UnboundType":private] => array(1) {
                        [0] => string(10) "Widescreen"
                      }
                      ["position":"DTS\eBaySDK\Types\UnboundType":private] => int(0)
                      ["class":"DTS\eBaySDK\Types\UnboundType":private] => string(44) "DTS\eBaySDK\Shopping\Types\NameValueListType"
                      ["property":"DTS\eBaySDK\Types\UnboundType":private] => string(5) "Value"
                      ["expectedType":"DTS\eBaySDK\Types\UnboundType":private] => string(6) "string"
                    }

So in my controller I put the following information:

$event = array();
            foreach($item->ItemSpecifics->NameValueList as $data){
                $event[] = $data;
            }

I set the data using: ->setCollection($event)

and in my html page (view) I used:

<?php $res = $this->getCollection() ?>
<?php foreach ($res as $row)
{
    echo "<tr id='0' class='0'>
                    <td>
                        <div class='name'>" . $row->Name . " </div>
                    </td>
                    <td>
                        <div class='value'>" . $row->Value . " </div>
                    </td>
                </tr>";
} ?>

but my problem is that the data included in NAME only is retrieved. the information in Value is not retrieved into the view. just to put more in clear with an example. The information = FORMAT is displayed but DVD/HD-DVD is not.

["Name"] => string(6) "Format"
                        ["Value"] => object(DTS\eBaySDK\Types\UnboundType)#191 (5) {
                          ["data":"DTS\eBaySDK\Types\UnboundType":private] => array(1) {
                            [0] => string(10) "DVD/HD-DVD"
                          }
  • 1
    As I can see the Value is an object, so you need to call $row->Value->data[0]. – michael Sep 22 '15 at 16:10
  • @michael thanks for your reply. I´m receiving Fatal error: Cannot access private property when using $row->Value->data[0] – s_h Sep 22 '15 at 16:21
3

->Value is an object, and the ->Value->data property is marked as private. That means you cannot read it from outside (without doing reflection) but instead need to call a relevant method to read its value. Looking at the implementation of UnboundType we see that you should be able to read the ->Value object as if it was an array (they implement the ArrayAccess interface). The data you want is in position 0 so try this:

$row->Value[0]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.