@@ -110,7 +110,8 @@ public function fetchCreatedAt(int $visitorId): ?int
110
110
['created_at ' => 'visitor_table.created_at ' ]
111
111
)->where (
112
112
'visitor_table.visitor_id = ? ' ,
113
- (string ) $ visitorId
113
+ $ visitorId ,
114
+ \Zend_Db::BIGINT_TYPE
114
115
)->limit (
115
116
1
116
117
);
@@ -121,6 +122,62 @@ public function fetchCreatedAt(int $visitorId): ?int
121
122
return strtotime ($ lookup ['created_at ' ]);
122
123
}
123
124
125
+ /**
126
+ * Gets created at value for the visitor id by customer id
127
+ *
128
+ * @param int $customerId
129
+ * @return int|null
130
+ */
131
+ public function fetchCreatedAtByCustomer (int $ customerId ): ?int
132
+ {
133
+ $ connection = $ this ->getConnection ();
134
+ $ select = $ connection ->select ()->from (
135
+ ['visitor_table ' => $ this ->getTable ('customer_visitor ' )],
136
+ ['created_at ' => 'visitor_table.created_at ' ]
137
+ )->where (
138
+ 'visitor_table.customer_id = ? ' ,
139
+ $ customerId ,
140
+ \Zend_Db::INT_TYPE
141
+ )->order (
142
+ 'visitor_table.visitor_id DESC '
143
+ )->limit (
144
+ 1
145
+ );
146
+ $ lookup = $ connection ->fetchRow ($ select );
147
+ if (empty ($ lookup ) || $ lookup ['created_at ' ] == null ) {
148
+ return null ;
149
+ }
150
+ return strtotime ($ lookup ['created_at ' ]);
151
+ }
152
+
153
+ /**
154
+ * Gets created at value for the visitor id by customer id
155
+ *
156
+ * @param int $customerId
157
+ * @return int|null
158
+ */
159
+ public function fetchLastVisitAtByCustomer (int $ customerId ): ?int
160
+ {
161
+ $ connection = $ this ->getConnection ();
162
+ $ select = $ connection ->select ()->from (
163
+ ['visitor_table ' => $ this ->getTable ('customer_visitor ' )],
164
+ ['last_visit_at ' => 'visitor_table.last_visit_at ' ]
165
+ )->where (
166
+ 'visitor_table.customer_id = ? ' ,
167
+ $ customerId ,
168
+ \Zend_Db::INT_TYPE
169
+ )->order (
170
+ 'visitor_table.visitor_id DESC '
171
+ )->limit (
172
+ 1
173
+ );
174
+ $ lookup = $ connection ->fetchRow ($ select );
175
+ if (empty ($ lookup ) || $ lookup ['last_visit_at ' ] == null ) {
176
+ return null ;
177
+ }
178
+ return strtotime ($ lookup ['last_visit_at ' ]);
179
+ }
180
+
124
181
/**
125
182
* Update visitor session created at column value
126
183
*
@@ -136,4 +193,20 @@ public function updateCreatedAt(int $visitorId, int $timestamp): void
136
193
$ this ->getConnection ()->quoteInto ('visitor_id = ? ' , $ visitorId )
137
194
);
138
195
}
196
+
197
+ /**
198
+ * Update visitor session visitor id column value
199
+ *
200
+ * @param int $visitorId
201
+ * @param int $customerId
202
+ * @return void
203
+ */
204
+ public function updateCustomerId (int $ visitorId , int $ customerId ): void
205
+ {
206
+ $ this ->getConnection ()->update (
207
+ $ this ->getTable ('customer_visitor ' ),
208
+ ['customer_id ' => $ customerId ],
209
+ $ this ->getConnection ()->quoteInto ('visitor_id = ? ' , $ visitorId )
210
+ );
211
+ }
139
212
}
0 commit comments