slince / shopify-api-php

:rocket: Shopify API Client for PHP
MIT License
128 stars 47 forks source link

Retrieval of wrong customer information using getCustomerManager #21

Closed chintankotadia closed 3 years ago

chintankotadia commented 5 years ago

Hello,

I am trying to retrieve customers information using following code but it is providing wrong customer id using getCustomerManager() compare to normal REST API call:

$customers = $client->getCustomerManager()->findAll(['limit' => 1]);
foreach ($customers as $customer) {
  print_r($customer);
}

Output:

Array
(
    [0] => Slince\Shopify\Manager\Customer\Customer Object
        (
            [email:protected] => chintan.kotadia+180731@knectar.com
            [acceptsMarketing:protected] => 
            [createdAt:protected] => DateTime Object
                (
                    [date] => 2018-08-01 00:00:36.000000
                    [timezone_type] => 1
                    [timezone] => -04:00
                )

            [updatedAt:protected] => DateTime Object
                (
                    [date] => 2018-08-01 00:00:37.000000
                    [timezone_type] => 1
                    [timezone] => -04:00
                )

            [firstName:protected] => Michael
            [lastName:protected] => Zaremba
            [ordersCount:protected] => 0
            [state:protected] => enabled
            [totalSpent:protected] => 0
            [lastOrderId:protected] => 
            [note:protected] => 
            [verifiedEmail:protected] => 1
            [multipassIdentifier:protected] => 
            [taxExempt:protected] => 1
            [phone:protected] => +13216549870
            [tags:protected] => Tax Exempt
            [lastOrderName:protected] => 
            [addresses:protected] => Array
                (
                    [0] => Slince\Shopify\Manager\CustomerAddress\Address Object
                        (
                            [customerId:protected] => 1162707001
                            [default:protected] => 1
                            [id:protected] => 1231388729
                            [firstName:protected] => Michael
                            [lastName:protected] => Zaremba
                            [company:protected] => Company Name
                            [address1:protected] => 180 pleasant st
                            [address2:protected] => suite 206
                            [city:protected] => easthampton
                            [province:protected] => Massachusetts
                            [country:protected] => United States
                            [zip:protected] => 01027
                            [phone:protected] => 3216549870
                            [name:protected] => Michael Zaremba
                            [provinceCode:protected] => MA
                            [countryCode:protected] => US
                            [countryName:protected] => United States
                        )

                )

            [defaultAddress:protected] => Slince\Shopify\Manager\CustomerAddress\Address Object
                (
                    [customerId:protected] => 1162707001
                    [default:protected] => 1
                    [id:protected] => 1231388729
                    [firstName:protected] => Michael
                    [lastName:protected] => Zaremba
                    [company:protected] => Company Name
                    [address1:protected] => 180 pleasant st
                    [address2:protected] => suite 206
                    [city:protected] => easthampton
                    [province:protected] => Massachusetts
                    [country:protected] => United States
                    [zip:protected] => 01027
                    [phone:protected] => 3216549870
                    [name:protected] => Michael Zaremba
                    [provinceCode:protected] => MA
                    [countryCode:protected] => US
                    [countryName:protected] => United States
                )

            [id:protected] => 1162707001
        )

)
$customers = $client->get('customers', ['limit' => 1]);
print_r($customers);

Output:

Array
(
    [customers] => Array
        (
            [0] => Array
                (
                    [id] => 825796427833
                    [email] => chintan.kotadia+180731@knectar.com
                    [accepts_marketing] => 
                    [created_at] => 2018-08-01T00:00:36-04:00
                    [updated_at] => 2018-08-01T00:00:37-04:00
                    [first_name] => Michael
                    [last_name] => Zaremba
                    [orders_count] => 0
                    [state] => enabled
                    [total_spent] => 0.00
                    [last_order_id] => 
                    [note] => 
                    [verified_email] => 1
                    [multipass_identifier] => 
                    [tax_exempt] => 1
                    [phone] => +13216549870
                    [tags] => Tax Exempt
                    [last_order_name] => 
                    [currency] => USD
                    [addresses] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 903174520889
                                    [customer_id] => 825796427833
                                    [first_name] => Michael
                                    [last_name] => Zaremba
                                    [company] => Company Name
                                    [address1] => 180 pleasant st
                                    [address2] => suite 206
                                    [city] => easthampton
                                    [province] => Massachusetts
                                    [country] => United States
                                    [zip] => 01027
                                    [phone] => 3216549870
                                    [name] => Michael Zaremba
                                    [province_code] => MA
                                    [country_code] => US
                                    [country_name] => United States
                                    [default] => 1
                                )

                        )

                    [admin_graphql_api_id] => gid://shopify/Customer/825796427833
                    [default_address] => Array
                        (
                            [id] => 903174520889
                            [customer_id] => 825796427833
                            [first_name] => Michael
                            [last_name] => Zaremba
                            [company] => Company Name
                            [address1] => 180 pleasant st
                            [address2] => suite 206
                            [city] => easthampton
                            [province] => Massachusetts
                            [country] => United States
                            [zip] => 01027
                            [phone] => 3216549870
                            [name] => Michael Zaremba
                            [province_code] => MA
                            [country_code] => US
                            [country_name] => United States
                            [default] => 1
                        )

                )

        )

)

Problem over here is that getCustomerManager() is setting up id of customer address instead of real customer id.

Thank you.

maximzasorin commented 5 years ago

@chintankotadia Hello, looks like you use library on 32-bit platform, and you get integer overflow for customer's id.

825796427833 % 2^32 = 1162707001
maximzasorin commented 5 years ago

@slince Hello, I think we need to specify a 64-bit integers in the library requirements.

slince commented 5 years ago

@maximzasorin maybe we can use string type instead of integer

chintankotadia commented 5 years ago

@maximzasorin: Yes, that's correct. I am using 32-bit platform.

maximzasorin commented 5 years ago

@chintankotadia Now, lib support only platform with 64-bit integers.

chintankotadia commented 5 years ago

@maximzasorin : I think, you might need to add this in your future development roadmap. :)

jonathangreco commented 5 years ago

Hi sorry to ask but how we know if our platform will handle this case correctly, let say we use Heroku for instance ?

chintankotadia commented 5 years ago

@jonathangreco : Make sure that you've selected 64-bit OS instance.