Beispiel #1
0
 /**
  * When the user logs in, their session cart should override their db-stored cart.
  * Current actions take precedence
  *
  * @param $user
  * @param $options
  * @return unknown_type
  */
 private function doLoginUser($user, $options = array())
 {
     $session = JFactory::getSession();
     $old_sessionid = $session->get('old_sessionid');
     $user['id'] = intval(JUserHelper::getUserId($user['username']));
     // Should check that Tienda is installed first before executing
     if (!$this->_isInstalled()) {
         return;
     }
     Tienda::load('TiendaHelperCarts', 'helpers.carts');
     $helper = new TiendaHelperCarts();
     if (!empty($old_sessionid)) {
         $helper->mergeSessionCartWithUserCart($old_sessionid, $user['id']);
         JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
         $wishlist_model = JModel::getInstance('WishlistItems', 'TiendaModel');
         $wishlist_model->setUserForSessionItems($old_sessionid, $user['id']);
     } else {
         $helper->updateUserCartItemsSessionId($user['id'], $session->getId());
     }
     $this->checkUserGroup();
     return true;
 }
Beispiel #2
0
 /**
  * Smartly updates the carts db table,
  * updating quantity if a product_id+product_attributes entry exists for the user
  * otherwise creating a new entry
  *
  * @deprecated as of version 6.3, will be removed in v6.4.0
  *
  * @param array
  * @param boolean
  * @param string
  */
 function updateCart($cart = array(), $sync = false, $old_sessionid = '', $new_userid = '')
 {
     $session = JFactory::getSession();
     $user = JFactory::getUser();
     if ($sync) {
         // get the cart based on session id
         if (!empty($old_sessionid)) {
             $session_id2use = $old_sessionid;
         } else {
             $session_id2use = $session->getId();
         }
         JModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/models');
         $model = JModel::getInstance('Carts', 'TiendaModel');
         $model->setState('filter_user', '0');
         $model->setState('filter_session', $session_id2use);
         $cart = $model->getList();
         $user_id = empty($new_userid) ? JFactory::getUser()->id : $new_userid;
         TiendaHelperCarts::updateUserCartItemsSessionId($user_id, $session_id);
     }
     if (!empty($cart)) {
         JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_tienda/tables');
         foreach ($cart as $item) {
             $table = JTable::getInstance('Carts', 'TiendaTable');
             $user_id = empty($new_userid) ? JFactory::getUser()->id : $new_userid;
             $item->user_id = empty($item->user_id) ? $user_id : $item->user_id;
             $keynames = array();
             $keynames['user_id'] = $item->user_id;
             if (empty($item->user_id)) {
                 $keynames['session_id'] = $session->getId();
             }
             $keynames['product_id'] = $item->product_id;
             $keynames['product_attributes'] = $item->product_attributes;
             // fire plugin event: onGetAdditionalCartKeyValues
             //this event allows plugins to extend the multiple-column primary key of the carts table
             $additionalKeyValues = TiendaHelperCarts::getAdditionalKeyValues($item, null, null);
             if (!empty($additionalKeyValues)) {
                 $keynames = array_merge($keynames, $additionalKeyValues);
                 //$table->setKeyNames($keynames); // not necessary
             }
             if ($table->load($keynames)) {
                 if ($sync) {
                     // if syncing, the quantity as set in the session takes precedence
                     $table->product_qty = $item->product_qty;
                 } else {
                     $table->product_qty = $table->product_qty + $item->product_qty;
                 }
             } else {
                 foreach ($item as $key => $value) {
                     if (property_exists($table, $key)) {
                         $table->set($key, $value);
                     }
                 }
                 $table->session_id = $session->getId();
             }
             $date = JFactory::getDate();
             $table->last_updated = $date->toMysql();
             if (!$table->save()) {
                 JError::raiseNotice('updateCart', $table->getError());
             }
         }
     }
     TiendaHelperCarts::fixQuantities();
     return true;
 }