Index: branches/5.2.x/units/orders/orders_event_handler.php =================================================================== diff -u -N -r14827 -r14846 --- branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14827) +++ branches/5.2.x/units/orders/orders_event_handler.php (.../orders_event_handler.php) (revision 14846) @@ -1,6 +1,6 @@ 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; }