@@ -244,7 +244,7 @@ public function sendAbandonedCartData($quoteId = null): array
244244 if ($ quoteId ) {
245245 $ abandonedCarts ->addFieldToFilter ('entity_id ' , ['eq ' => $ quoteId ]);
246246 }
247- $ abandonedCarts ->setPageSize ($ numberOfAbandonedCart );
247+ $ abandonedCarts ->setPageSize ($ numberOfAbandonedCart )-> setOrder ( ' main_table.updated_at ' , " desc " ) ;
248248 $ abandonedCarts ->getSelect ()->join (array ('address ' => $ abandonedCarts ->getResource ()->getTable ('quote_address ' )), 'main_table.entity_id = address.quote_id ' )
249249 ->where ("address.address_type='billing' and (main_table.customer_email is not null or address.email is not null) " );
250250 foreach ($ abandonedCarts as $ abandonedCart ) {
@@ -288,7 +288,7 @@ public function sendAbandonedCartData($quoteId = null): array
288288 "orderDiscounts " => [
289289 "discountAmount " => $ this ->coreHelper ->priceToCents ($ abandonedCart ->getDiscountAmount ())
290290 ],
291- "orderUrl " => $ this ->urlBuilder ->getDirectUrl ('checkout/cart ' ),
291+ "orderUrl " => $ this ->urlBuilder ->setScope ( $ abandonedCart -> getStoreId ())-> getDirectUrl ('checkout/cart ' ),
292292 "abandonedDate " => $ this ->dateTime ->date (strtotime ($ abandonedUpdateDate ),NULL ,$ timezone )->format ('Y-m-d\TH:i:sP ' ),
293293 "externalCreatedDate " => $ this ->dateTime ->date (strtotime ($ abandonedCartRepository ->getCreatedAt ()),NULL ,$ timezone )->format ('Y-m-d\TH:i:sP ' ),
294294 "externalUpdatedDate " => $ this ->dateTime ->date (strtotime ($ abandonedUpdateDate ),NULL ,$ timezone )->format ('Y-m-d\TH:i:sP ' ),
@@ -361,17 +361,26 @@ public function sendAbandonedCartData($quoteId = null): array
361361 */
362362 private function getQuoteItemsData ($ entityId , $ storeId ): array
363363 {
364+
364365 $ quoteItemsData = [];
366+ $ this ->appEmulation ->startEnvironmentEmulation ($ storeId , Area::AREA_FRONTEND , true );
365367 $ quoteItems = $ this ->getQuoteItems ($ entityId );
366368 foreach ($ quoteItems as $ quoteItem ) {
367- $ this -> appEmulation -> startEnvironmentEmulation ( $ storeId , Area:: AREA_FRONTEND , true );
369+
368370
369371 $ product = $ this ->_productRepositoryFactory ->create ()
370- ->getById ($ quoteItem ->getProductId ());
372+ ->getById ($ quoteItem ->getProductId (), false , $ storeId );
371373
372374 $ imageUrl = $ this ->imageHelperFactory ->create ()
373375 ->init ($ product , 'product_page_image_medium ' )->getUrl ();
374376 $ this ->appEmulation ->stopEnvironmentEmulation ();
377+ $ categories = $ product ->getCategoryCollection ()->addAttributeToSelect ('name ' );
378+ $ categoriesName = [];
379+ foreach ($ categories as $ category )
380+ {
381+ $ categoriesName [] = $ category ->getName ();
382+ }
383+ $ categoriesName = implode (', ' , $ categoriesName );
375384 $ quoteItemsData [] = [
376385 "externalid " => $ quoteItem ->getItemId (),
377386 "name " => $ quoteItem ->getName (),
@@ -380,7 +389,8 @@ private function getQuoteItemsData($entityId, $storeId): array
380389 "sku " => $ quoteItem ->getSku (),
381390 "description " => $ product ->getDescription (),
382391 "imageUrl " => $ imageUrl ,
383- "productUrl " => $ product ->getProductUrl ()
392+ "productUrl " => $ product ->getProductUrl (),
393+ "category " => $ categoriesName
384394 ];
385395 }
386396 return $ quoteItemsData ;
0 commit comments