public static function mergeClientToUser() { if ($user = Ajde_User::getLoggedIn()) { // Do we have a saved client cart? $clientCart = new CartModel(); if ($clientCart->loadByClient()) { // Do we have a saved cart for logged in user? $userCart = new CartModel(); if ($userCart->loadByUser($user) === false) { $userCart->user = $user->getPK(); $userCart->insert(); } if ($userCart->hasItems()) { // Set alert message Ajde_Session_Flash::alert(trans('Your items are still in the shopping cart')); } // Merge items foreach ($clientCart->getItems() as $item) { /* @var $item Ajde_Shop_Cart_Item */ $userCart->addItem($item->getEntity(), null, $item->getQty()); } // And delete client $clientCart->delete(); } } }
public static function mergeClientToUser() { Ajde_Model::register('user'); Ajde_Model::register('shop'); if ($user = Ajde_User::getLoggedIn()) { // Do we have a saved client cart? $clientCart = new CartModel(); if ($clientCart->loadByClient()) { // Do we have a saved cart for logged in user? $userCart = new CartModel(); if ($userCart->loadByUser($user) === false) { $userCart->user = $user->getPK(); $userCart->insert(); } if ($userCart->hasItems()) { // Set alert message Ajde_Session_Flash::alert(__('We updated your shopping cart now you\'re logged in')); } // Merge items foreach ($clientCart->getItems() as $item) { /* @var $item Ajde_Shop_Cart_Item */ $userCart->addItem($item->getEntity(), null, $item->getQty()); } // And delete client $clientCart->delete(); } } }
public function checkout() { // Get existing transaction $transaction = new TransactionModel(); $session = new Ajde_Session('AC.Shop'); $session->has('currentTransaction') && $transaction->loadByPK($session->get('currentTransaction')); $cart = new CartModel(); $cart->loadCurrent(); // Can we skip this step? if (!$transaction->hasLoaded() && !config('shop.offerLogin') && $cart->hasItems()) { $this->redirect('shop/transaction:setup'); } $this->getView()->assign('cart', $cart); $this->getView()->assign('user', $this->getLoggedInUser()); $this->getView()->assign('transaction', $transaction); return $this->render(); }