示例#1
0
 public static function getUserGroups()
 {
     $app = JFactory::getApplication();
     $view = JRequest::getVar('view', 'users');
     $context = 'com_ksen.' . $view;
     if ($layout = JRequest::getVar('layout', 'default')) {
         $context .= '.' . $layout;
     }
     $selected_usergroups = $app->getUserStateFromRequest($context . '.usergroups', 'usergroups', array());
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->select('a.*')->from(KSDb::quoteName('#__usergroups') . ' AS a');
     $query->select('COUNT(DISTINCT c2.id) AS level');
     $query->join('LEFT OUTER', KSDb::quoteName('#__usergroups') . ' AS c2 ON a.lft > c2.lft AND a.rgt < c2.rgt');
     $query->group('a.id, a.lft, a.rgt, a.parent_id, a.title');
     $query->order($db->escape('a.lft'));
     $db->setQuery($query);
     $usergroups = $db->loadObjectList();
     foreach ($usergroups as &$usergroup) {
         if (in_array($usergroup->id, $selected_usergroups)) {
             $usergroup->selected = true;
         } else {
             $usergroup->selected = false;
         }
     }
     return $usergroups;
 }
示例#2
0
 private function removeIrrelevantSearches($value)
 {
     $this->onExecuteBefore('removeIrrelevantSearches', array(&$value));
     $query = $this->_db->getQuery(true);
     $value_length = mb_strlen($value);
     $conditions = array();
     for ($i = 1; $i <= $value_length - 1; $i++) {
         $title = mb_substr($value, 0, $i * -1);
         $conditions[] = $this->_db->quote($title);
     }
     $query->delete(KSDb::quoteName('#__ksenmart_searches_query'));
     $query->where('title IN(' . implode(', ', $conditions) . ')');
     $this->_db->setQuery($query);
     $result = $this->_db->query();
     $this->onExecuteAfter('removeIrrelevantSearches', array(&$result));
 }
示例#3
0
文件: cart.php 项目: JexyRu/Ksenmart
 public function updateCart()
 {
     $this->onExecuteBefore('updateCart');
     $params = JComponentHelper::getParams('com_ksenmart');
     $jinput = JFactory::getApplication()->input;
     $count = $jinput->get('count', 0, 'float');
     $price = $jinput->get('price', 0, 'float');
     $item_id = $jinput->get('item_id', 0, 'int');
     $item = KSSystem::getTableByIds(array($item_id), 'order_items', array('t.id', 't.order_id', 't.price', 't.count', 't.product_id'), false, false, true);
     if ($price != 0 && $price != $item->price) {
         $order_item_object = new stdClass();
         $order_item_object->id = $item_id;
         $order_item_object->price = $price;
         $order_item_object->count = $count;
         try {
             $result = $this->_db->updateObject('#__ksenmart_order_items', $order_item_object, 'id');
         } catch (Exception $e) {
         }
         $diff = ($price - $item->price) * $item->count;
         $item->price = $price;
         $order_object = new stdClass();
         $order_object->id = $item->order_id;
         $order_object->cost = $this->getOrderCost($this->order_id) + $diff;
         try {
             $result = $this->_db->updateObject('#__ksenmart_orders', $order_object, 'id');
         } catch (Exception $e) {
         }
     }
     $prd = KSMProducts::getProduct($item->product_id);
     $item_properties = array();
     foreach ($prd->properties as $property) {
         $value = JRequest::getVar('property_' . $property->id, '');
         if (!empty($value)) {
             $item_properties[] = $property->id . ':' . $value;
         }
     }
     $order_item_object = new stdClass();
     $order_item_object->id = $item_id;
     $order_item_object->properties = json_encode($item_properties);
     try {
         $result = $this->_db->updateObject('#__ksenmart_order_items', $order_item_object, 'id');
     } catch (Exception $e) {
     }
     $diff_count = $count - $item->count;
     $diff = ($count - $item->count) * $item->price;
     if ($count == 0) {
         $query = $this->_db->getQuery(true);
         $conditions = array('id=' . $this->_db->escape($item_id));
         $query->delete(KSDb::quoteName('#__ksenmart_order_items'))->where($conditions);
         $this->_db->setQuery($query);
         try {
             $result = $this->_db->query();
             // $this->_db->execute(); for Joomla 3.0.
         } catch (Exception $e) {
         }
     } else {
         $order_item_object = new stdClass();
         $order_item_object->id = $item_id;
         $order_item_object->count = $count;
         try {
             $result = $this->_db->updateObject('#__ksenmart_order_items', $order_item_object, 'id');
         } catch (Exception $e) {
         }
     }
     if ($params->get('use_stock', 1)) {
         $product_object = new stdClass();
         $product_object->id = $item->product_id;
         $product_object->in_stock = $prd->in_stock - $diff_count;
         try {
             $result = $this->_db->updateObject('#__ksenmart_products', $product_object, 'id');
         } catch (Exception $e) {
         }
     }
     $order_object = new stdClass();
     $order_object->id = $item->order_id;
     $order_object->cost = $this->getOrderCost($item->order_id) + $diff;
     try {
         $result = $this->_db->updateObject('#__ksenmart_orders', $order_object, 'id');
     } catch (Exception $e) {
     }
     $orderItem = $this->getOrderUpdateItems($item->order_id, $item->id);
     $this->onExecuteAfter('updateCart', array(&$orderItem));
     return $orderItem;
 }
示例#4
0
 /**
  * KsenMartModelProfile::deleteAddress()
  * 
  * @return
  */
 public function deleteAddress()
 {
     $this->onExecuteBefore('deleteAddress');
     $id = JFactory::getApplication()->input->get('id', 0, 'int');
     $user = KSUsers::getUser();
     $query = $this->_db->getQuery(true);
     $conditions = array('id=' . $this->_db->escape($id), 'user_id=' . $user->id);
     $query->delete(KSDb::quoteName('#__ksen_user_addresses'));
     $query->where($conditions);
     $this->_db->setQuery($query);
     try {
         $result = $this->_db->query();
         // $this->_db->execute(); for Joomla 3.0.
         $this->onExecuteAfter('onExecuteBefore', array(&$result));
         return true;
     } catch (Exception $e) {
     }
     return false;
 }
示例#5
0
 public static function getOrderField($oid, $field)
 {
     self::onExecuteBefore(array(&$oid, &$field));
     if (!empty($oid) && !empty($field)) {
         $db = JFactory::getDBO();
         $query = $db->getQuery(true);
         $query->select(KSDb::quoteName('o.' . $field))->from('#__ksenmart_orders AS o')->where(KSDb::quoteName('o.id') . '=' . $db->escape($oid));
         $db->setQuery($query);
         $orderField = $db->loadObject();
         self::onExecuteAfter(array($orderField));
         return $orderField;
     }
     return false;
 }
示例#6
0
文件: users.php 项目: JexyRu/Ksenmart
 public function removeUserSubscribeGroup($uid)
 {
     if (!empty($uid) && $uid > 0) {
         $db = JFactory::getDBO();
         $query = $db->getQuery(true);
         $conditions = array('user_id=' . $db->escape($uid), 'group_id=' . $db->escape(KSUsers::getSubscribersGroupID()));
         $query->delete(KSDb::quoteName('#__user_usergroup_map'));
         $query->where($conditions);
         $db->setQuery($query);
         try {
             $result = $db->query();
             return true;
         } catch (exception $e) {
         }
     }
     return false;
 }