Index: units/orders/orders_event_handler.php =================================================================== --- units/orders/orders_event_handler.php (revision 14845) +++ units/orders/orders_event_handler.php (revision 14846) @@ -505,6 +505,7 @@ $this->Application->StoreVar('front_order_id', $order_id); $this->Application->RemoveVar('ord_id'); + $this->Application->Session->SetCookie('shop_cart_cookie', '', strtotime('-1 month')); } /** @@ -613,6 +614,38 @@ } /** + * Restores order from cookie + * + * @param kEvent $event + * @return void + * @access protected + */ + protected function OnRestoreOrder(kEvent &$event) + { + if ( $this->Application->isAdmin || $this->Application->RecallVar('ord_id') ) { + // admin OR there is an active order -> don't restore from cookie + return; + } + + $shop_cart_cookie = $this->Application->GetVarDirect('shop_cart_cookie', 'Cookie'); + + if ( !$shop_cart_cookie ) { + return; + } + + $user_id = $this->Application->RecallVar('user_id'); + + $sql = 'SELECT OrderId + FROM ' . TABLE_PREFIX . 'Orders + WHERE (OrderId = ' . (int)$shop_cart_cookie . ') AND (Status = ' . ORDER_STATUS_INCOMPLETE . ') AND (PortalUserId = ' . $user_id . ')'; + $order_id = $this->Conn->GetOne($sql); + + if ( $order_id ) { + $this->Application->StoreVar('ord_id', $order_id); + } + } + + /** * Redirect user to Billing checkout step * * @param kEvent $event @@ -1402,6 +1435,7 @@ $this->Application->SetVar($event->getPrefixSpecial(true) . '_id', $id); $this->Application->StoreVar($event->getPrefixSpecial(true) . '_id', $id); + $this->Application->Session->SetCookie('shop_cart_cookie', $id, strtotime('+1 month')); return $id; } Index: units/orders/orders_config.php =================================================================== --- units/orders/orders_config.php (revision 14845) +++ units/orders/orders_config.php (revision 14846) @@ -106,6 +106,16 @@ 'DoSpecial' => '', 'DoEvent' => 'OnUserLogin', ), + Array( + 'Mode' => hAFTER, + 'Conditional' => false, + 'HookToPrefix' => 'adm', + 'HookToSpecial' => '*', + 'HookToEvent' => Array('OnStartup'), + 'DoPrefix' => '', + 'DoSpecial' => '', + 'DoEvent' => 'OnRestoreOrder', + ), ), 'AggregateTags' => Array ( Array (