Weble / RevisoApi

5 stars 3 forks source link

Not able to access protected property "Info" returned by get customers api #2

Closed alok932 closed 5 years ago

alok932 commented 5 years ago

PHP Code to get customers

$reviso = new \Webleit\RevisoApi\Reviso();
$customers = $reviso->customers->perPage(2)->get();
echo "<pre>";
print_r($customers);
echo "</pre>";

Response:

Webleit\RevisoApi\Collection Object
(
    [data:protected] => Array
        (
        )

    [keyName:protected] => customerNumber
    [info:protected] => stdClass Object
        (
            [collection] => Array
                (
                    [0] => stdClass Object
                        (
                            [address] => 1 Data Street
                            [attention] => stdClass Object
                                (
                                    [customerContactNumber] => 1
                                    [self] => https://rest.reviso.com/customers/101/contacts/1
                                )

                            [balance] => 6259.2
                            [city] => London
                            [contacts] => https://rest.reviso.com/customers/101/contacts
                            [corporateIdentificationNumber] => 123456789
                            [country] => Data Country
                            [county] => Data County 1
                            [currency] => GBP
                            [customerContact] => stdClass Object
                                (
                                    [customerContactNumber] => 1
                                    [self] => https://rest.reviso.com/customers/101/contacts/1
                                )

                            [customerGroup] => stdClass Object
                                (
                                    [customerGroupNumber] => 1
                                    [self] => https://rest.reviso.com/customer-groups/1
                                )

                            [email] => api@reviso.com
                            [lastUpdated] => 2016-11-25T09:40:32Z
                            [layout] => stdClass Object
                                (
                                    [isDefault] => 
                                    [layoutNumber] => 19
                                    [self] => https://rest.reviso.com/layouts/19
                                )

                            [paymentTerms] => stdClass Object
                                (
                                    [paymentTermsNumber] => 3
                                    [self] => https://rest.reviso.com/payment-terms/3
                                )

                            [salesPerson] => stdClass Object
                                (
                                    [canApprove] => 
                                    [canInvoice] => 
                                    [employeeNumber] => 1
                                    [self] => https://rest.reviso.com/employees/1
                                )

                            [splitPayment] => 
                            [telephoneAndFaxNumber] => 80123456
                            [templates] => stdClass Object
                                (
                                    [invoice] => https://rest.reviso.com/customers/101/templates/invoice
                                    [self] => https://rest.reviso.com/customers/101/templates
                                )

                            [vatZone] => stdClass Object
                                (
                                    [vatZoneNumber] => 1
                                    [self] => https://rest.reviso.com/vat-zones/1
                                )

                            [zip] => DA1 1DA
                            [tags] => Array
                                (
                                )

                            [customerNumber] => 101
                            [name] => Datahouse Ltd.
                            [self] => https://rest.reviso.com/customers/101
                        )

                    [1] => stdClass Object
                        (
                            [address] => Schmidt Street 1
                            [attention] => stdClass Object
                                (
                                    [customerContactNumber] => 1
                                    [self] => https://rest.reviso.com/customers/102/contacts/1
                                )

                            [balance] => 3565.16
                            [city] => New York
                            [contacts] => https://rest.reviso.com/customers/102/contacts
                            [country] => USA
                            [county] => Schmidt County
                            [currency] => USD
                            [customerContact] => stdClass Object
                                (
                                    [customerContactNumber] => 1
                                    [self] => https://rest.reviso.com/customers/102/contacts/1
                                )

                            [customerGroup] => stdClass Object
                                (
                                    [customerGroupNumber] => 2
                                    [self] => https://rest.reviso.com/customer-groups/2
                                )

                            [email] => api@reviso.com
                            [lastUpdated] => 2016-11-25T09:41:29Z
                            [layout] => stdClass Object
                                (
                                    [isDefault] => 
                                    [layoutNumber] => 19
                                    [self] => https://rest.reviso.com/layouts/19
                                )

                            [paymentTerms] => stdClass Object
                                (
                                    [paymentTermsNumber] => 3
                                    [self] => https://rest.reviso.com/payment-terms/3
                                )

                            [salesPerson] => stdClass Object
                                (
                                    [canApprove] => 
                                    [canInvoice] => 
                                    [employeeNumber] => 5
                                    [self] => https://rest.reviso.com/employees/5
                                )

                            [splitPayment] => 
                            [templates] => stdClass Object
                                (
                                    [invoice] => https://rest.reviso.com/customers/102/templates/invoice
                                    [self] => https://rest.reviso.com/customers/102/templates
                                )

                            [vatZone] => stdClass Object
                                (
                                    [vatZoneNumber] => 3
                                    [self] => https://rest.reviso.com/vat-zones/3
                                )

                            [zip] => VA 12345
                            [tags] => Array
                                (
                                )

                            [customerNumber] => 102
                            [name] => Schmidt & Co.
                            [self] => https://rest.reviso.com/customers/102
                        )

                )

            [metaData] => stdClass Object
                (
                    [create] => stdClass Object
                        (
                            [description] => Create a new customer
                            [href] => https://rest.reviso.com/customers?demo=true
                            [httpMethod] => post
                        )

                )

            [pagination] => stdClass Object
                (
                    [maxPageSizeAllowed] => 10000
                    [pageSize] => 2
                    [skipPages] => 0
                    [results] => 10
                    [resultsWithoutFilter] => 10
                    [firstPage] => https://rest.reviso.com/customers?skippages=0&pagesize=2&demo=true
                    [lastPage] => https://rest.reviso.com/customers?skippages=4&pagesize=2&demo=true
                    [nextPage] => https://rest.reviso.com/customers?skippages=1&pagesize=2&demo=true
                )

            [self] => https://rest.reviso.com/customers?skippages=0&pagesize=2&demo=true
        )

)

Here as all data is in Protected property info we cannot really access it from outside this package. There is not getter for Info in Collection Class.

Skullbock commented 5 years ago

Hey, you can use any item in the collection as an object.

$reviso = new \Webleit\RevisoApi\Reviso();
$customers = $reviso->customers->perPage(2)->get();

$customer = $customers->first(); // or $customers->each or foreach ($customers as $customer)
echo $customer->address;

echo "<pre>";
print_r($customers->toArray());
echo "</pre>";
alok932 commented 5 years ago

Thanks for the reply. $customers->first() works but not the foreach.

    foreach ($customers as $customer) {
        echo "<pre>";
        print_r($customer);
        echo "</pre>";
    }

This returns nothing.

Skullbock commented 5 years ago

Sorry, it's foreach ($customers->toArray() as $customer)

On Tue, Oct 1, 2019 at 2:46 PM Alok notifications@github.com wrote:

Thanks for the reply. $customers->first() works but not the foreach.

foreach ($customers as $customer) {
    echo "<pre>";
    print_r($customer);
    echo "</pre>";
}

This returns nothing.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Weble/RevisoApi/issues/2?email_source=notifications&email_token=AAINRU3FQOQPA7NOGXHQFSDQMNBEDA5CNFSM4I4I2PJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEABELPY#issuecomment-537019839, or mute the thread https://github.com/notifications/unsubscribe-auth/AAINRU3HWM5CC4MJWIE745LQMNBEDANCNFSM4I4I2PJQ .

-- [image: Logo Weble] Daniele Rosario

CTO Weble Srl Via Enrico Fermi, 265 36100 Vicenza ufficio: +39 0444 1454934 <003904441454934> mobile: +39 3283017134 <00393283017134> weble.it https://www.weble.it/ https://www.facebook.com/pages/Weble/110077192371908?fref=ts https://twitter.com/Webleit?lang=it https://www.linkedin.com/company/2470613?trk=tyah&trkInfo=clickedVertical%3Acompany%2Cidx%3A2-2-7%2CtarId%3A1432717146425%2Ctas%3Aweble https://www.instagram.com/weble.it/

alok932 commented 5 years ago

Yes but toArray() has bug that returns only 1 record.

Skullbock commented 5 years ago

just tagged 1.1.1 that should fix that

On Tue, Oct 1, 2019 at 2:51 PM Alok notifications@github.com wrote:

Yes but toArray() has bug that returns only 1 record.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/Weble/RevisoApi/issues/2?email_source=notifications&email_token=AAINRU3XJ4ODFH6UAYJQUWLQMNBVFA5CNFSM4I4I2PJ2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEABEY3Q#issuecomment-537021550, or mute the thread https://github.com/notifications/unsubscribe-auth/AAINRU5JSMHCIUQP6DJ7A3TQMNBVFANCNFSM4I4I2PJQ .

-- [image: Logo Weble] Daniele Rosario

CTO Weble Srl Via Enrico Fermi, 265 36100 Vicenza ufficio: +39 0444 1454934 <003904441454934> mobile: +39 3283017134 <00393283017134> weble.it https://www.weble.it/ https://www.facebook.com/pages/Weble/110077192371908?fref=ts https://twitter.com/Webleit?lang=it https://www.linkedin.com/company/2470613?trk=tyah&trkInfo=clickedVertical%3Acompany%2Cidx%3A2-2-7%2CtarId%3A1432717146425%2Ctas%3Aweble https://www.instagram.com/weble.it/

alok932 commented 5 years ago

yes this fixed it. Thanks for such a quick fix.

Skullbock commented 5 years ago

You're welcome.