I have this code in a laravel model:
Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'We are gonna to save an order with shopify_id: '.$this->shopify_id]);
$this->save();
Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'SQL of insert: ', 'sql' => DB::getQueryLog()]);
Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'Order saved with shopify_id: '.$this->shopify_id]);
$orderInBD = Order::where('shopify_id', $this->shopify_id)->first();
Log::info($this->TAG.'.trySave ('.session()->getId().')', ['msg' => 'Order in BD with shopify_id: '.$orderInBD->shopify_id, 'order' => $orderInBD]);
And it shows this in the log:
[2017-06-22 18:33:55] production.INFO: Order.trySave (sP9IZwqbzXLn4b6EF0pKZKrBRsyX1WEOx6M2XStM) {"msg":"We are gonna to save an order with shopify_id: 5074805714"}
[2017-06-22 18:33:55] production.INFO: Order.trySave (sP9IZwqbzXLn4b6EF0pKZKrBRsyX1WEOx6M2XStM) {"msg":"SQL of insert: ","sql":[{"query":"insert into 'orders' ('shopify_id', 'user_id', 'user_id_processed_temp', 'financial_status', 'paid_at', 'accepts_marketing', 'subtotal_local', 'subtotal_eur', 'shipping_local', 'shipping_eur', 'total_local', 'total_eur', 'billing_country', 'billing_street', 'billing_phone', 'billing_zip', 'billing_province', 'billing_city', 'billing_latitude', 'billing_longitude', 'shipping_country', 'shipping_street', 'shipping_province', 'shipping_province_code', 'shipping_phone', 'shipping_city', 'shipping_zip', 'shipping_latitude', 'shipping_longitude', 'name', 'cancelled_at', 'cancel_reason', 'created_at', 'created_at_day', 'gateway', 'source_name', 'draft', 'fulfillment_status', 'updated_at') values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)","bindings":[5074805714,null,1,"paid","2017-06-22T16:32:32+02:00",true,"44.00",44,"7.00",7,"51.00",51,"IT","Via n.34","334 616 6996","60041","AN","Sassoferrato",43.4292,12.8540,"IT","Via n.34","Ancona","AN","334 616 6996","","60041",43.4292,12.8540,"SITEMUERES1660269",null,null,"2017-06-22T16:32:32+02:00","2017-06-22T16:32:32+02:00","braintree","web",0,"fulfilled","2017-06-22T16:32:35+02:00"],"time":4.6}]}
[2017-06-22 18:33:55] production.INFO: Order.trySave (sP9IZwqbzXLn4b6EF0pKZKrBRsyX1WEOx6M2XStM) {"msg":"Order saved with shopify_id: 5074805714"}
[2017-06-22 18:33:55] production.INFO: Order.trySave (sP9IZwqbzXLn4b6EF0pKZKrBRsyX1WEOx6M2XStM) {"msg":"Order in BD with Shopify_ID: 779838418","order":"[object] (App\ModelosRelacionales\Order: {\"id\":252,\"name\":\"SITEMUERES1660269\",\"created_at\":\"2017-06-22 16:32:32\",\"created_at_day\":\"2017-06-22\",\"paid_at\":\"2017-06-22 16:32:32\",\"financial_status\":\"paid\",\"accepts_marketing\":\"1\",\"discount_code\":null,\"cancelled_at\":null,\"cancel_reason\":null,\"refunded_at\":null,\"origen\":null,\"referal\":null,\"gateway\":\"braintree\",\"discount_category\":null,\"is_code_applied\":null,\"is_shipping_code_applied\":null,\"is_shipping_native_applied\":null,\"is_compare_at_price_applied\":null,\"subtotal_local\":\"44.00\",\"subtotal_eur\":\"44.00\",\"shipping_local\":\"7.00\",\"shipping_eur\":\"7.00\",\"total_local\":\"51.00\",\"total_eur\":\"51.00\",\"discount_amount_local\":null,\"discount_amount_eur\":null,\"code_discount_amount_local\":null,\"code_discount_amount_eur\":null,\"refunded_amount_local\":null,\"refunded_amount_eur\":null,\"shipping_discount_amount_local\":null,\"shipping_discount_amount_eur\":null,\"compare_at_discount_amount_local\":null,\"compare_at_discount_amount_eur\":null,\"total_real_discount_local\":null,\"total_real_discount_eur\":null,\"shipping_country\":\"IT\",\"shipping_province\":\"Ancona\",\"shipping_province_code\":\"AN\",\"shipping_phone\":\"334\",\"shipping_city\":\"a\",\"shipping_street\":\"a\",\"shipping_zip\":\"60041\",\"shipping_latitude\":\"43.429\",\"shipping_longitude\":\"12.854\",\"billing_province\":\"AN\",\"billing_zip\":\"6004\",\"billing_phone\":\"33\",\"billing_city\":\"\",\"billing_street\":\"Via n.34\",\"billing_country\":\"IT\",\"billing_latitude\":\"43.429\",\"billing_longitude\":\"12.854\",\"customer_id\":\"0\",\"shopify_id\":\"779838418\",\"updated_at\":\"2017-06-22 16:32:35\",\"fulfillment_status\":\"fulfilled\",\"source_name\":\"web\",\"draft\":\"0\",\"deleted_at\":null,\"user_id\":null,\"user_id_processed_temp\":\"1\"})"}
As you can see in the sql of the insert, the data bindeado to shopify_id in the insert into is 5074805714, and when nothing else to insert it I do a select where shopify_id is 5074805714 it returns me a row with shopify_id 779838418. In the database it really is with the shopify_id 779838418 that is surely missing in the insert.
If I take the query and execute it changing the? so it corresponds correctly inserted so it makes me suspect that the problem is in laravel.
insert into 'orders' ('shopify_id', 'user_id', 'user_id_processed_temp', 'financial_status', 'paid_at', 'accepts_marketing', 'subtotal_local', 'subtotal_eur', 'shipping_local', 'shipping_eur', 'total_local', 'total_eur', 'billing_country', 'billing_street', 'billing_phone', 'billing_zip', 'billing_province', 'billing_city', 'billing_latitude', 'billing_longitude', 'shipping_country', 'shipping_street', 'shipping_province', 'shipping_province_code', 'shipping_phone', 'shipping_city', 'shipping_zip', 'shipping_latitude', 'shipping_longitude', 'name', 'cancelled_at', 'cancel_reason', 'created_at', 'created_at_day', 'gateway', 'source_name', 'draft', 'fulfillment_status', 'updated_at') values (5074805714, null, 1, "paid", "2017-06-22T16:09:31+02:00", true, "24.00", 24, "7.00", 7, "31.00", 31, "es", "Calle", "766", "0311", "a", "busot", 38.4804, -0.4210, "ES", "calle", "a", "a", "6765", "busot", "03111", 38.4804688, -0.4210394, "SITEMUERES1660091", null, null, "2017-06-22T16:09:31+02:00", "2017-06-22T16:09:31+02:00", "braintree", "web", 0, "fulfilled", "2017-06-22T16:09:37+02:00")
The shopify_id field is a bigint (20)
EDIT 1 If I use a raw query like this:
DB::insert('insert into 'orders' ('shopify_id', 'user_id', 'user_id_processed_temp', 'financial_status', 'paid_at', 'accepts_marketing',
'subtotal_local', 'subtotal_eur', 'shipping_local', 'shipping_eur', 'total_local', 'total_eur', 'billing_country',
'billing_street', 'billing_phone', 'billing_zip', 'billing_province', 'billing_city', 'billing_latitude', 'billing_longitude',
'shipping_country', 'shipping_street', 'shipping_province', 'shipping_province_code', 'shipping_phone', 'shipping_city', 'shipping_zip',
'shipping_latitude', 'shipping_longitude', 'name', 'cancelled_at', 'cancel_reason', 'created_at', 'created_at_day', 'gateway', 'source_name',
'draft', 'fulfillment_status', 'updated_at')
values ('.$this->shopify_id.', null, 1, "paid", "2017-06-22T16:09:31+02:00", true, "24.00", 24, "7.00", 7, "31.00", 31, "es", "Calle", "766", "0311", "a", "busot",
38.4804688, -0.4210394, "ES", "calle", "alicante", "a", "6765", "busot", "03111", 38.4804688, -0.4210394, "'.$this->name.'", null, null, "2017-06-22T16:09:31+02:00",
"2017-06-22T16:09:31+02:00", "braintree", "web", 0, "fulfilled", "2017-06-22T16:09:37+02:00")');
It works well.
EDIT 2 If you rest a high amount the shopify id works fine:
$this->shopify_id -= 5000000000;
$this->save();
What could be happening?