/** * Get an order by its cart id * * @param integer $cart_id JeproshopCartModelCart id * @return array Order details */ public static function getOrderIdByCartId($cart_id) { $db = JFactory::getDBO(); $query = "SELECT " . $db->quoteName('order_id') . " FROM " . $db->quoteName('#__jeproshop_orders') . " WHERE " . $db->quoteName('cart_id') . " = "; $query .= (int) $cart_id . JeproshopShopModelShop::addSqlRestriction(); $db->setQuery($query); $result = $db->loadOject(); return isset($result['id_order']) ? $result['id_order'] : false; }
public function getAddressList() { $db = JFactory::getDBO(); $app = JFactory::getApplication(); $option = $app->input->get('option'); $view = $app->input->get('view'); $context = JeproshopContext::getContext(); $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int'); $limitStart = $app->getUserStateFromRequest($option . $view . '.limit_start', 'limit_start', 0, 'int'); $lang_id = $app->getUserStateFromRequest($option . $view . '.lang_id', 'lang_id', $context->language->lang_id, 'int'); $order_by = $app->getUserStateFromRequest($option . $view . '.order_by', 'order_by', 'address_id', 'string'); $order_way = $app->getUserStateFromRequest($option . $view . '.order_way', 'order_way', 'ASC', 'string'); $use_limit = true; if ($limit === false) { $use_limit = false; } do { $query = "SELECT SQL_CALC_FOUND_ROWS address." . $db->quoteName('address_id') . ", address." . $db->quoteName('firstname') . ", address."; $query .= $db->quoteName('lastname') . ", address." . $db->quoteName('address1') . ", address." . $db->quoteName('postcode') . ", address."; $query .= $db->quoteName('city') . ", country_lang." . $db->quoteName('name') . " AS country FROM " . $db->quoteName('#__jeproshop_address'); $query .= " AS address LEFT JOIN " . $db->quoteName('#__jeproshop_country_lang') . "country_lang ON (country_lang." . $db->quoteName('country_id'); $query .= " = address." . $db->quoteName('country_id') . " AND country_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_customer') . " AS customer ON address." . $db->quoteName('customer_id') . " = customer." . $db->quoteName('customer_id'); $query .= " WHERE address.customer_id != 0 " . JeproshopShopModelShop::addSqlRestriction(JeproshopShopModelShop::SHARE_CUSTOMER, 'customer'); $query .= " ORDER BY " . (str_replace('`', '', $order_by) == 'address_id' ? "address." : "") . $order_by . " " . $order_way; $db->setQuery($query); $total = count($db->loadObjectList()); $query .= $use_limit == true ? " LIMIT " . (int) $limitStart . ", " . (int) $limit : " "; $db->setQuery($query); $addresses = $db->loadObjectList(); if ($use_limit == true) { $limitStart = (int) $limitStart - (int) $limit; if ($limitStart < 0) { break; } } else { break; } } while (empty($addresses)); $this->pagination = new JPagination($total, $limitStart, $limit); return $addresses; }
public function getGroupList(JeproshopContext $context = NULL) { jimport('joomla.html.pagination'); $context = JeproshopContext::getContext(); $db = JFactory::getDBO(); $app = JFactory::getApplication(); $option = $app->input->get('option'); $view = $app->input->get('view'); $lang_id = $app->getUserStateFromRequest($option . $view . '.lang_id', 'lang_id', $context->language->lang_id, 'int'); $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->getCfg('list_limit'), 'int'); $limit_start = $app->getUserStateFromRequest($option . $view . '.limit_start', 'limit_start', 0, 'int'); $order_by = $app->getUserStateFromRequest($option . $view . '.order_by', 'order_by', 'date_add', 'string'); $order_way = $app->getUserStateFromRequest($option . $view . '.order_way', 'order_way', 'ASC', 'string'); $published = $app->getUserStateFromRequest($option . $view . '.published', 'published', 0, 'string'); /* Manage default params values */ $use_limit = true; if ($limit === false) { $use_limit = false; } $select = "(SELECT COUNT(customer_group." . $db->quoteName('customer_id') . ") FROM " . $db->quoteName('#__jeproshop_customer_group'); $select .= " AS customer_group LEFT JOIN " . $db->quoteName('#__jeproshop_customer') . " AS customer ON (customer."; $select .= $db->quoteName('customer_id') . " = customer_group." . $db->quoteName('customer_id') . ") WHERE customer."; $select .= $db->quoteName('deleted') . " != 1 " . JeproshopShopModelShop::addSqlRestriction(JeproshopShopModelShop::SHARE_CUSTOMER); $select .= " AND customer_group." . $db->quoteName('group_id') . " = groupe." . $db->quoteName('group_id') . ") AS nb"; $lang_join = " LEFT JOIN " . $db->quoteName('#__jeproshop_group_lang') . " AS group_lang ON (group_lang." . $db->quoteName('group_id'); $lang_join .= " = groupe." . $db->quoteName('group_id') . " AND group_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")"; $tmpTableFilter = ""; // Add SQL shop restriction $select_shop = $join_shop = $where_shop = ''; $explicit_select = true; do { $query = "SELECT SQL_CALC_FOUND_ROWS " . ($tmpTableFilter ? " * FROM (SELECT " : ""); if ($explicit_select) { $query .= "groupe.group_id, group_lang.name, groupe.reduction, groupe.show_prices, groupe.date_add,"; } else { $query .= "groupe.*"; } $query .= $select . $select_shop . " FROM " . $db->quoteName('#__jeproshop_group') . " AS groupe " . $lang_join; $query .= $join_shop; $query .= " ORDER BY " . (str_replace('`', '', $order_by) == 'group_id' ? "group_id" : "") . " groupe." . $db->quoteName($order_by) . " "; $query .= $db->escape($order_way) . ($tmpTableFilter ? ") tmpTable WHERE 1" . $tmpTableFilter : ""); $db->setQuery($query); $total = count($db->loadObjectList()); $query .= $use_limit === true ? " LIMIT " . (int) $limit_start . ", " . (int) $limit : ""; $db->setQuery($query); $groups = $db->loadObjectList(); if ($use_limit == true) { $limit_start = (int) $limit_start - (int) $limit; if ($limit_start < 0) { break; } } else { break; } } while (empty($groups)); $this->pagination = new JPagination($total, $limit_start, $limit); return $groups; }
/** * Check if e-mail is already registered in database * * @param string $email e-mail * @param $return_id boolean * @param $ignore_guest boolean, to exclude guest customer * @return Customer ID if found, false otherwise */ public static function customerExists($email, $return_id = false, $ignore_guest = true) { if (!JeproshopTools::isEmail($email)) { if (defined('COM_JEPROSHOP_DEV_MODE') && COM_JEPROSHOP_DEV_MODE) { die(JError::raiseError('Invalid email')); } else { return false; } } $db = JFactory::getDBO(); $query = "SELECT " . $db->quoteName('customer_id') . " FROM " . $db->quoteName('#__jeproshop_customer'); $query .= " WHERE " . $db->quoteName('email') . " = " . $db->quote($db->escape($email)); $query .= JeproshopShopModelShop::addSqlRestriction(JeproshopShopModelShop::SHARE_CUSTOMER); $query .= $ignore_guest ? " AND " . $db->quoteName('is_guest') . " = 0" : ""; $db->setQuery($query); $result = $db->loadObject(); if ($return_id) { return $result->customer_id; } return isset($result->customer_id); }
public static function getContacts() { $db = JFactory::getDBO(); $query = "SELECT contact_lang.*, COUNT(*) as total, ( SELECT " . $db->quoteName('customer_thread_id') . " FROM " . $db->quoteName('#__jeproshop_customer_thread') . " AS customer_thread_2 WHERE status = 'open' AND customer_thread."; $query .= $db->quoteName('contact_id') . " = customer_thread_2." . $db->quoteName('contact_id') . JeproshopShopModelShop::addSqlRestriction() . " ORDER BY date_upd ASC LIMIT 1 ) AS customer_thread_id FROM " . $db->quoteName('#__jeproshop_customer_thread'); $query .= " AS customer_thread LEFT JOIN " . $db->quoteName('#__jeproshop_contact_lang') . " AS contact_lang ON (contact_lang.contact_id = customer_thread.contact_id AND contact_lang.lang_id = " . (int) JeproshopContext::getContext()->language->lang_id; $query .= ") WHERE customer_thread.status = 'open' AND customer_thread.contact_id IS NOT NULL AND contact_lang.contact_id IS NOT NULL " . JeproshopShopModelShop::addSqlRestriction() . " GROUP BY customer_thread.contact_id HAVING COUNT(*) > 0"; $db->setQuery($query); return $db->loadObjectList(); }
/** * Check if there is no default attribute and create it if not */ public function checkDefaultAttributes() { if (!$this->product_id) { return false; } $db = JFactory::getDBO(); $query = "SELECT COUNT(*) FROM " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute " . JeproshopShopModelShop::addSqlRestriction('product_attribute') . " WHERE product_attribute_shop."; $query .= $db->quoteName('default_on') . " = 1 AND product_attribute_attribute." . $db->quoteName('product_id') . " = " . (int) $this->product_id; $db->setQuery($query); if ($db->loadResult() > 1) { /*$query = "UPDATE " . $db->quoteName('#__jeproshop_product_attribute_shop') . " SET " . $db->quoteName('default_on') . " WHERE " . $db->quoteName('product_attribute_id'), ' . _DB_PREFIX_ . 'product_attribute pa SET product_attribute_shop.default_on=0, pa.default_on = 0 WHERE product_attribute_shop.id_product_attribute=pa.id_product_attribute AND pa.id_product=' . (int)$this->id . Shop::addSqlRestriction(false, 'product_attribute_shop')); $db->setQuery($query); $db->query();*/ } $query = "SELECT product_attribute." . $db->quoteName('product_id') . " FROM " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute " . JeproshopShopModelShop::addSqlAssociation('product_attribute'); $query .= " WHERE product_attribute_shop." . $db->quoteName('default_on') . " = 1 AND product_attribute." . $db->quoteName('product_id') . " = " . (int) $this->product_id; $db->setQuery($query); $row = $db->loadObject(); if ($row) { return true; } $query = "SELECT MIN (product_attribute." . $db->quoteName('product_attribute_id') . ") AS attribute_id FROM " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute WHERE " . $db->quoteName('product_id') . " = " . (int) $this->product_id; $db->setQuery($query); $mini = $db->loadObject(); if (!$mini) { return false; } if (!ObjectModel::updateMultishopTable('Combination', array('default_on' => 1), 'a.id_product_attribute = ' . (int) $mini['id_attr'])) { return false; } return true; }