Index: units/orders/orders_config.php =================================================================== --- units/orders/orders_config.php (revision 14653) +++ units/orders/orders_config.php (working copy) @@ -88,6 +88,16 @@ 'DoSpecial' => '', 'DoEvent' => 'OnUserLogin', ), + Array( + 'Mode' => hAFTER, + 'Conditional' => false, + 'HookToPrefix' => 'adm', + 'HookToSpecial' => '*', + 'HookToEvent' => Array('OnStartup'), + 'DoPrefix' => '', + 'DoSpecial' => '', + 'DoEvent' => 'OnRestoreOrder', + ), ), 'AggregateTags' => Array ( Array ( Index: units/orders/orders_event_handler.php =================================================================== --- units/orders/orders_event_handler.php (revision 14653) +++ units/orders/orders_event_handler.php (working copy) @@ -438,6 +438,7 @@ $this->Application->StoreVar('front_order_id', $order_id); $this->Application->RemoveVar('ord_id'); + $this->Application->Session->SetCookie('shop_cart_cookie', '', strtotime('-1 month')); } /** @@ -542,6 +543,35 @@ } /** + * Restores order from cookie + * + * @param kEvent $event + */ + function OnRestoreOrder(&$event) + { + if ( $this->Application->isAdmin || $this->Application->RecallVar('ord_id') || $this->Application->LoggedIn() ) { + // admin OR there is an active order OR logged-in user -> don't restore from cookie + return; + } + + $cookies = $this->Application->HttpQuery->Cookie; + $shop_cart_cookie = array_key_exists('shop_cart_cookie', $cookies) ? $cookies['shop_cart_cookie'] : false; + + if ( !$shop_cart_cookie ) { + return; + } + + $sql = 'SELECT OrderId + FROM ' . TABLE_PREFIX . 'Orders + WHERE (OrderId = ' . (int)$shop_cart_cookie . ') AND (Status = ' . ORDER_STATUS_INCOMPLETE . ') AND (PortalUserId = ' . USER_GUEST . ')'; + $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 @@ -1140,6 +1170,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; }