public function __construct($customer_id = NULL) { parent::__construct(); if ($customer_id) { $cache_id = 'jeproshop_customer_model_' . $customer_id . ($this->shop_id ? '_' . $this->shop_id : ''); if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_customer') . " AS customer "; /** Get shop informations **/ if (JeproshopShopModelShop::isTableAssociated('order')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_order_shop') . " AS order_shop ON ("; $query .= "ord.order_id = order_shop.order_id AND order_shop.shop_id = " . (int) $this->shop_id . ")"; } $query .= " WHERE customer.customer_id = " . (int) $customer_id; $db->setQuery($query); $customer_data = $db->loadObject(); if ($customer_data) { JeproshopCache::store($cache_id, $customer_data); } } else { $customer_data = JeproshopCache::retrieve($cache_id); } if ($customer_data) { $customer_data->customer_id = $customer_id; foreach ($customer_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } $this->default_group_id = JeproshopSettingModelSetting::getValue('customer_group'); }
public function getOrderStatusList() { $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', 'order_status_id', 'string'); $order_way = $app->getUserStateFromRequest($option . $view . '.order_way', 'order_way', 'ASC', 'string'); $select = $select_shop = $where_shop = $join_shop = ""; $lang_join = " LEFT JOIN " . $db->quoteName('#__jeproshop_order_status_lang') . " AS order_status_lang ON(order_status_lang." . $db->quoteName('order_status_id'); $lang_join .= " = order_status." . $db->quoteName('order_status_id') . " AND order_status_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")"; /*if($shop_lang_id){ if(!JeproshopShopModelShop::isFeaturePublished()){ $lang_join .= " AND order_status_lang." . $db->quoteName('shop_id') . " = 1"; }elseif(JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP){ $lang_join .= " AND order_status_lang." . $db->quoteName('shop_id') . " = " . (int)$shop_lang_id; }else{ $lang_join .= " AND order_status_lang." . $db->quoteName('shop_id') . " = order_status.default_shop_id"; } } $lang_join .= ")"; */ $having_clause = ""; $where = ""; if (JeproshopShopModelShop::isTableAssociated('order_status')) { if (JeproshopShopModelShop::getShopContext() != JeproshopShopModelShop::CONTEXT_ALL || !$context->employee->isSuperAdmin()) { $test_join = ""; if (JeproshopShopModelShop::isFeaturePublished() && $test_join && JeproshopShopModelShop::isTableAssociated('order_status')) { $where .= " AND order_status." . $db->quoteName('order_status_id') . " IN (SELECT orders_status_shop." . $db->quoteName('order_status_id'); $where .= " FROM " . $db->quoteName('#__jeproshop_order_status_shop') . " AS order_status_shop WHERE order_status_shop.shop_id IN ("; $where .= implode(', ', JeproshopShopModelShop::getContextListShopIds()) . ") )"; } } } $use_limit = true; if ($limit === false) { $use_limit = false; } $deleted = $group = $filter = $join = ""; //", order_status." . $db->quoteName('logo') . do { $query = "SELECT SQL_CALC_FOUND_ROWS order_status." . $db->quoteName('order_status_id') . ", order_status_lang." . $db->quoteName('name'); $query .= ", order_status." . $db->quoteName('send_email') . ", order_status."; $query .= $db->quoteName('delivery') . ", order_status." . $db->quoteName('invoice') . ", order_status_lang." . $db->quoteName('template'); $query .= $select . $select_shop . " FROM " . $db->quoteName('#__jeproshop_order_status') . " AS order_status " . $lang_join . $join; $query .= $join_shop . " WHERE 1 " . $where . $deleted . $filter . $where_shop . $group . $having_clause . " ORDER BY "; $query .= (str_replace('`', '', $order_by) == 'order_status_id' ? "order_status." : "") . $order_by . " " . $order_way; $db->setQuery($query); $total = count($db->loadObjectList()); $query .= $use_limit ? " LIMIT " . (int) $limitStart . ", " . (int) $limit : ""; $db->setQuery($query); $orderStatus = $db->loadObjectList(); if ($orderStatus == false) { break; } if ($use_limit) { $limitStart = (int) $limitStart - (int) $limit; if ($limitStart < 0) { break; } } else { break; } } while (empty($orderStatus)); $this->pagination = new JPagination($total, $limitStart, $limit); return $orderStatus; }
public function isMultiShop() { return JeproshopShopModelShop::isTableAssociated('group') || !empty($this->multiLangShop); }
public function getManufacturerList($explicitSelect = TRUE) { jimport('joomla.html.pagination'); $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'); $shop_id = $app->getUserStateFromRequest($option . $view . '.shop_id', 'shop_id', $context->shop->shop_id, 'int'); $shop_group_id = $app->getUserStateFromRequest($option . $view . '.shop_group_id', 'shop_group_id', $context->shop->shop_group_id, 'int'); $category_id = $app->getUserStateFromRequest($option . $view . '.category_id', 'category_id', 0, 'int'); $order_by = $app->getUserStateFromRequest($option . $view . '.order_by', 'order_by', 'manufacturer_id', '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 = " COUNT(" . $db->quoteName('product_id') . ") AS " . $db->quoteName('products') . ", (SELECT "; $select .= "COUNT(address." . $db->quoteName('manufacturer_id') . ") AS " . $db->quoteName('addresses'); $select .= " FROM " . $db->quoteName('#__jeproshop_address') . " AS address WHERE address."; $select .= $db->quoteName('manufacturer_id') . " = manufacturer." . $db->quoteName('manufacturer_id'); $select .= " AND address." . $db->quoteName('deleted') . " = 0 GROUP BY address." . $db->quoteName('manufacturer_id'); $select .= ") AS " . $db->quoteName('addresses'); $join = "LEFT JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON (manufacturer."; $join .= $db->quoteName('manufacturer_id') . " = product." . $db->quoteName('manufacturer_id') . ") "; $group = " GROUP BY manufacturer." . $db->quoteName('manufacturer_id'); if ($context->controller->multishop_context && JeproshopShopModelShop::isTableAssociated('manufacturer')) { if (JeproshopShopModelShop::getShopContext() != JeproshopShopMoelShop::CONTEXT_ALL || !$context->employee->isSuperAdmin()) { $test_join = !preg_match('#`?' . preg_quote('#__jeproshop_manufacturer_shop') . '`? *manufacturer-shop#', $join); if (JeproshopShopModelShop::isFeaturePublished() && $test_join && JeproshopModelShopShop::isTableAssociated('manufacturer')) { $where .= ' AND a.' . $this->identifier . ' IN ( SELECT sa.' . $this->identifier . ' FROM `' . _DB_PREFIX_ . $this->table . '_shop` sa WHERE sa.id_shop IN (' . implode(', ', JeproshopShopModelShop::getContextListShopIds()) . ") )"; } } } /* Query in order to get results with all fields */ $lang_join = ''; if ($context->language->lang_id) { $lang_join = "LEFT JOIN " . $db->quoteName('#__jeproshop_manufacturer_lang') . " AS manufacturer_lang "; $lang_join .= " ON (manufacturer_lang." . $db->quoteName('manufacturer_id') . " = manufacturer."; $lang_join .= $db->quoteName('manufacturer_id') . " AND manufacturer_lang." . $db->quoteName('lang_id'); $lang_join .= " = " . (int) $lang_id . ") "; } $having_clause = ''; if (isset($this->_filterHaving) || isset($this->_having)) { $having_clause = ' HAVING '; if (isset($this->_filterHaving)) { $having_clause .= ltrim($this->_filterHaving, ' AND '); } if (isset($this->_having)) { $having_clause .= $this->_having . ' '; } } do { $query = "SELECT SQL_CALC_FOUND_ROWS "; if (!$explicitSelect) { $query .= " manufacturer.name, manufacturer.published, "; //logo, /* foreach($fields_list as $key => $value){ if(isset($select) && preg_match('/[\s]`?' . preg_quote($key, '/') . '`?\S*,/', $select)){ continue; } if (isset($value['filter_key'])){ $query .= str_replace('!', '.', $value['filter_key']) . " AS " . $key . ", "; }elseif ($key == 'manufacturer_id'){ $query .= "manufacture." . $db->quoteName($db->escape($key)) . ", "; }elseif ($key != 'image' && !preg_match('/'. preg_quote($key, '/').'/i', $select)){ $query .= $db->quoteName($db->escape($key)) .", "; } } $query = rtrim($query, ',') */ } else { $query .= ($lang_id ? "manufacturer_lang.*, " : "") . "manufacturer.*, "; } $query .= (isset($select) ? rtrim($select, ", ") : "") . " FROM " . $db->quoteName('#__jeproshop_manufacturer'); $query .= " AS manufacturer " . $lang_join . (isset($join) ? $join . " " : "") . " WHERE 1 " . (isset($where) ? $where . " " : ""); $query .= (isset($filter) ? $filter : "") . (isset($group) ? $group . " " : ""); $query .= $having_clause . " ORDER BY " . (str_replace('`', '', $order_by) == 'manufacturer_id' ? "manufacturer.manufacturer_id " : ""); //. " manufacturer." . $db->quoteName($order_by) . " "; $query .= $db->escape($order_way) . ($use_limit === true ? " LIMIT " . (int) $limitstart . ", " . (int) $limit : ""); $db->setQuery($query); $manufacturers = $db->loadObjectList(); if ($use_limit == true) { $limitstart = (int) $limitstart - (int) $limit; if ($limitstart < 0) { break; } } else { break; } } while (empty($manufacturers)); $total = count($manufacturers); $this->pagination = new JPagination($total, $limitstart, $limit); return $manufacturers; }
/** * Check if there is more than one entries in associated shop table for current entity * * @since 1.5.0 * @return bool */ public function hasMultishopEntries() { if (!JeproshopShopModelShop::isTableAssociated('product_attribute') || !JeproshopShopModelShop::isFeaturePublished()) { return false; } $db = JFactory::getDBO(); $query = "SELECT COUNT(*) FROM " . $db->quoteName('#__jeproshop_product_attribute_shop') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $this->product_attribute_id; $db->quoteName($query); return (bool) $db->loadResult(); }
/** * @see ObjectModel::add() */ public function add() { $db = JFactory::getDBO(); $this->date_add = date('Y-m-d H:i:s'); $this->date_upd = date('Y-m-d H:i:s'); if (JeproshopShopModelShop::isTableAssociated('address')) { $shopListIds = JeproshopShopModelShop::getContextListShopIds(); if (count($this->shop_list_id) > 0) { $shopListIds = $this->shop_list_id; } } if (JeproshopShopModelShop::checkDefaultShopId('address')) { $this->default_shop_id = min($shopListIds); } $query = "INSERT INTO " . $db->quoteName('#__jeproshop_address'); if (!parent::add($autodate, $null_values)) { return false; } if (JeproshopTools::isUnsignedInt($this->customer_id)) { JeproshopCustomerModelCustomer::resetAddressCache($this->customer_id); } return true; }
public function __construct($carrier_id = null, $lang_id = null) { $db = JFactory::getDBO(); if ($lang_id !== NULL) { $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang'); } if ($carrier_id) { $cache_id = 'jeproshop_carrier_model_' . $carrier_id . '_' . $lang_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_carrier') . " AS carrier "; $where = ""; /** get language information **/ if ($lang_id) { $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_carrier_lang') . " AS carrier_lang ON (carrier."; $query .= "carrier_id = carrier_lang.carrier_id AND carrier_lang.lang_id = " . (int) $lang_id . ") "; /*if($this->shop_id && !(empty($this->multiLangShop))){ $where = " AND carrier_lang.shop_id = " . $this->shop_id; }*/ } /** Get shop informations **/ if (JeproshopShopModelShop::isTableAssociated('carrier')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_carrier_shop') . " AS carrier_shop ON (carrier."; $query .= "carrier_id = carrier_shop.carrier_id AND carrier_shop.shop_id = " . (int) $this->shop_id . ")"; } $query .= " WHERE carrier.carrier_id = " . (int) $carrier_id . $where; $db->setQuery($query); $carrier_data = $db->loadObject(); if ($carrier_data) { if (!$lang_id && isset($this->multiLang) && $this->multiLang) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_carrier_lang'); $query .= " WHERE carrier_id = " . (int) $carrier_id; $db->setQuery($query); $carrier_lang_data = $db->loadObjectList(); if ($carrier_lang_data) { foreach ($carrier_lang_data as $row) { foreach ($row as $key => $value) { if (array_key_exists($key, $this) && $key != 'carrier_id') { if (!isset($carrier_data->{$key}) || !is_array($carrier_data->{$key})) { $carrier_data->{$key} = array(); } $carrier_data->{$key}[$row->lang_id] = $value; } } } } } JeproshopCache::store($cache_id, $carrier_data); } } else { $carrier_data = JeproshopCache::retrieve($cache_id); } if ($carrier_data) { $carrier_data->carrier_id = $carrier_id; foreach ($carrier_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } /** * keep retro-compatibility SHIPPING_METHOD_DEFAULT * @deprecated 1.5.5 */ if ($this->shipping_method == JeproshopCarrierModelCarrier::DEFAULT_SHIPPING_METHOD) { $this->shipping_method = (int) JeproshopSettingModelSetting::getValue('shipping_method') ? JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD : JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD; } /** * keep retro-compatibility id_tax_rules_group * @deprecated 1.5.0 */ if ($this->carrier_id) { $this->tax_rules_group_id = $this->getTaxRulesGroupId(JeproshopContext::getContext()); } if ($this->name == '0') { $this->name = JeproshopSettingModelSetting::getValue('shop_name'); } $this->image_dir = COM_JEPROSHOP_CARRIER_IMAGE_DIR; }
public function __construct($customer_id = NULL) { $this->default_group_id = JeproshopSettingModelSetting::getValue('customer_group'); if ($customer_id) { $cache_id = 'jeproshop_customer_model_' . $customer_id . ($this->shop_id ? '_' . $this->shop_id : ''); if (!JeproshopCache::isStored($cache_id)) { $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_customer') . " AS customer "; $where = ""; /** get language information ** / if($lang_id){ $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_order_lang') . " AS order_lang "; $query .= "ON (ord.order_id = order_lang.order_id AND order_lang.lang_id = " . (int)$lang_id . ") "; if($this->shop_id && !(empty($this->multiLangShop))){ $where = " AND order_lang.shop_id = " . $this->shop_id; } } /** Get shop informations **/ if (JeproshopShopModelShop::isTableAssociated('order')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_order_shop') . " AS order_shop ON ("; $query .= "ord.order_id = order_shop.order_id AND order_shop.shop_id = " . (int) $this->shop_id . ")"; } $query .= " WHERE customer.customer_id = " . (int) $customer_id . $where; $db->setQuery($query); $customer_data = $db->loadObject(); if ($customer_data) { /*if(!$lang_id && isset($this->multiLang) && $this->multiLang){ $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_order_lang'); $query .= " WHERE order_id = " . (int)$order_id; $db->setQuery($query); $order_lang_data = $db->loadObjectList(); if($order_lang_data){ foreach ($order_lang_data as $row){ foreach($row as $key => $value){ if(array_key_exists($key, $this) && $key != 'order_id'){ if(!isset($order_data->{$key}) || !is_array($order_data->{$key})){ $order_data->{$key} = array(); } $order_data->{$key}[$row->lang_id] = $value; } } } } }*/ JeproshopCache::store($cache_id, $customer_data); } } else { $customer_data = JeproshopCache::retrieve($cache_id); } if ($customer_data) { $customer_data->order_id = $customer_id; foreach ($customer_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } }
public function deleteLite() { $db = JFactory::getDBO(); // @hook actionObject*DeleteBefore Hook::exec('actionObjectDeleteBefore', array('object' => $this)); Hook::exec('actionObject' . get_class($this) . 'DeleteBefore', array('object' => $this)); $this->clearCache(); $result = true; // Remove association to multishop table if (JeproshopShopModelShop::isTableAssociated('category')) { $shop_list_ids = JeproshopShopModelShop::getContextListShopIds(); if (count($this->shop_list_ids)) { $shop_list_ids = $this->shop_list_ids; } $query = "DELETE FROM " . $db->quoteName('#__jeproshop_category_shop') . " WHERE " . $db->quoteName('category_id') . " = " . (int) $this->category_id . " AND " . $db->quoteName('shop_id') . " IN(" . implode(', ', $shop_list_ids) . ")"; $db->setQuery($query); $result &= $db->query(); } // Database deletion $has_multishop_entries = $this->hasMultishopEntries(); if ($result && !$has_multishop_entries) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_category') . " WHERE " . $db->quoteName('category_id') . " = " . (int) $this->category_id; $db->setQuery($query); $result &= $db->query(); } if (!$result) { return false; } // Database deletion for multilingual fields related to the object if (!empty($this->def['multilang']) && !$has_multishop_entries) { $query = "DELETE FROM " . $db->quoteName('#__jeproshop_category_lang') . " WHERE " . $db->quoteName('category_id') . " = " . (int) $this->category_id; $db->setQuery($query); $result &= $db->query(); } // @hook actionObject*DeleteAfter Hook::exec('actionObjectDeleteAfter', array('object' => $this)); Hook::exec('actionObject' . get_class($this) . 'DeleteAfter', array('object' => $this)); return $result; }
public function __construct($product_download_id = NULL) { $db = JFactory::getDBO(); if ($product_download_id) { $cache_id = 'jeproshop_product_download_model_' . $product_download_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_product_download') . " AS product_download "; /** Get shop informations **/ if (JeproshopShopModelShop::isTableAssociated('product')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_product_shop') . " AS product_shop ON ("; $query .= "product.product_id = product_shop.product_id AND product_shop.shop_id = " . (int) $this->shop_id . ")"; } $query .= " WHERE product_download." . $db->quoteName('product_download_id') . " = " . (int) $product_download_id; $db->setQuery($query); $product_download_data = $db->loadObject(); if ($product_download_data) { JeproshopCache::store($cache_id, $product_download_data); } } else { $product_download_data = JeproshopCache::retrieve($cache_id); } if ($product_download_data) { $product_download_data->product_download_id = $product_download_id; foreach ($product_download_data as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } } } }
public function __construct($tax_rule_group_id = null) { $db = JFactory::getDBO(); if ($tax_rule_group_id) { $cache_id = 'jeproshop_tax_rule_group_model_' . $tax_rule_group_id; if (!JeproshopCache::isStored($cache_id)) { $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_tax_rules_group') . " AS tax_rules_group "; /** Get Shop information **/ if (JeproshopShopModelShop::isTableAssociated('tax_rules_group')) { $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_tax_rules_group_shop') . " AS tax_rules_group_shop ON ( tax_rules_group."; $query .= "tax_rules_group_id = tax_rules_group_shop.tax_rules_group_id AND tax_rules_group_shop.shop_id = " . (int) $this->shop_id . ")"; } $query .= " WHERE tax_rules_group." . $db->quoteName('tax_rules_group_id') . " = " . (int) $tax_rule_group_id; $db->setQuery($query); $taxRuleGroupData = $db->loadObject(); } else { $taxRuleGroupData = JeproshopCache::retrieve($cache_id); } if ($taxRuleGroupData) { foreach ($taxRuleGroupData as $key => $value) { if (array_key_exists($key, $this)) { $this->{$key} = $value; } } $this->tax_rules_group_id = $tax_rule_group_id; } } }