public static function addShopRestriction($shop = NULL, $alias = NULL) { $context = JeproshopContext::getContext(); if (!empty($alias)) { $alias .= '.'; } /** If there is no shop id, get the context one **/ if ($shop === null) { if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_GROUP) { $shop_group = JeproshopShopModelShop::getContextShopGroup(); } else { $shop_group = $context->shop->getShopGroup(); } $shop = $context->shop; } elseif (is_object($shop)) { $shop_group = $shop->getShopGroup(); } else { $shop = new JeproshopShopModelShop($shop); $shop_group = $shop->getShopGroup(); } /* if quantities are shared between shops of the group */ $db = JFactory::getDBO(); if ($shop_group->share_stock) { $query = " AND " . $db->escape($alias) . "shop_group_id = " . (int) $shop_group->shop_group_id . " AND " . $db->escape($alias) . "shop_id = 0 "; } else { $query = " AND " . $db->escape($alias) . "shop_id = " . (int) $shop->shop_id . ' '; } return $query; }
/** * Get all scenes of a category * * @param $category_id * @param null $lang_id * @param bool $only_published * @param bool $lite_result * @param bool $hide_scene_position * @param JeproshopContext $context * @return array Products */ public static function getScenes($category_id, $lang_id = null, $only_published = true, $lite_result = true, $hide_scene_position = true, JeproshopContext $context = null) { if (!JeproshopSceneModelScene::isFeaturePublished()) { return array(); } $cache_key = 'jeproshop_scene_get_scenes_' . $category_id . '_' . (int) $lite_result; if (!JeproshopCache::isStored($cache_key)) { if (!$context) { $context = JeproshopContext::getContext(); } $lang_id = is_null($lang_id) ? $context->language->lang_id : $lang_id; $db = JFactory::getDBO(); $query = "SELECT scene.* FROM " . $db->quoteName('#__jeproshop_scene_category') . " scene_category LEFT JOIN " . $db->quoteName('#__jeproshop_scene'); $query .= " AS scene ON (scene_category.scene_id = scene.scene_id) " . JeproshopShopModelShop::addSqlAssociation('scene') . " LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_scene_lang') . " AS scene_lang ON (scene_lang.scene_id = scene.scene_id) WHERE scene_category.category_id = "; $query .= (int) $category_id . "\tAND scene_lang.lang_id = " . (int) $lang_id . ($only_published ? " AND scene.published = 1" : "") . " ORDER BY scene_lang.name ASC"; $db->setQuery($query); $scenes = $db->loadObjectList(); if (!$lite_result && $scenes) { foreach ($scenes as &$scene) { $scene = new Scene($scene->scene_id, $lang_id, false, $hide_scene_position); } } JeproshopCache::store($cache_key, $scenes); } $scenes = JeproshopCache::retrieve($cache_key); return $scenes; }
public function renderDetails($tpl = null) { $app = JFactory::getApplication(); $category_id = $app->input->get('category_id'); if (!isset($this->context) || empty($this->context)) { $this->context = JeproshopContext::getContext(); } if (!JeproshopShopModelShop::isFeaturePublished() && count(JeproshopCategoryModelCategory::getCategoriesWithoutParent()) > 1 && $category_id) { $categories_tree = array(get_object_vars($this->context->controller->category->getTopCategory())); } else { $categories_tree = $this->context->controller->category->getParentsCategories(); $end = end($categories_tree); if (isset($categories_tree) && !JeproshopShopModelShop::isFeaturePublished() && (isset($end) && $end->parent_id != 0)) { $categories_tree = array_merge($categories_tree, array(get_object_vars($this->context->controller->category->getTopCategory()))); } } $count_categories_without_parent = count(JeproshopCategoryModelCategory::getCategoriesWithoutParent()); if (empty($categories_tree) && ($this->context->controller->category->category_id != 1 || $category_id) && (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP && !JeproshopShopModelShop::isFeaturePublished() && $count_categories_without_parent > 1)) { $categories_tree = array(array('name' => $this->context->controller->category->name[$this->context->language->lang_id])); } $categories_tree = array_reverse($categories_tree); $this->assignRef('categories_tree', $categories_tree); $this->assignRef('categories_tree_current_id', $this->context->controller->category->category_id); $categoryModel = new JeproshopCategoryModelCategory(); $categories = $categoryModel->getCategoriesList(); $pagination = $categoryModel->getPagination(); $this->assignRef('pagination', $pagination); $this->assignRef('categories', $categories); $this->setLayout('default'); $this->addToolBar(); $this->sideBar = JHtmlSideBar::render(); parent::display($tpl); }
public function initialize() { parent::initialize(); // Check if we can add a customer if (JeproshopShopModelShop::isFeaturePublished() && (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_ALL || JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_GROUP)) { $this->can_add_customer = false; } }
protected function getWarningDomainName() { $warning = false; if (JeproshopShopModelShop::isFeaturePublished()) { return null; } $shop = JeproshopContext::getContext()->shop; return $warning; }
/** * Retrieve the price of combination * * @param int $product_attribute_id * @return float mixed */ public static function getPrice($product_attribute_id) { $db = JFactory::getDBO(); $query = "SELECT product_attribute_shop." . $db->quoteName('price') . " FROM " . $db->quoteName('#__jeproshop_product_attribute'); $query .= " AS product_attribute " . JeproshopShopModelShop::addSqlAssociation('product_attribute') . "\tWHERE product_attribute."; $query .= $db->quoteName('product_attribute_id') . " = " . (int) $product_attribute_id; $db->setQuery($query); return $db->loadResult(); }
public static function getTaxRulesGroups($published = TRUE) { $db = JFactory::getDBO(); $query = "SELECT DISTINCT tax_rules_group.tax_rules_group_id, tax_rules_group.name, tax_rules_group.published FROM "; $query .= $db->quoteName('#__jeproshop_tax_rules_group') . " AS tax_rules_group " . JeproshopShopModelShop::addSqlAssociation('tax_rules_group'); $query .= ($published ? " WHERE tax_rules_group." . $db->quoteName('published') . " = 1" : "") . " ORDER BY name ASC"; $db->setQuery($query); return $db->loadObjectList(); }
/** * For a given {product, product attribute} gets warehouse list * * @param int $product_id ID of the product * @param int $product_attribute_id Optional, uses 0 if this product does not have attributes * @param int $shop_id Optional, ID of the shop. Uses the context shop id (@see JeproshopContext::shop) * @return array Warehouses (ID, reference/name concatenated) */ public static function getProductWarehouseList($product_id, $product_attribute_id = 0, $shop_id = null) { $db = JFactory::getDBO(); // if it's a pack, returns warehouses if and only if some products use the advanced stock management if (JeproshopProductPack::isPack($product_id)) { $warehouses = JeproshopWarehouseModelWarehouse::getPackWarehouses($product_id); /*$res = array(); foreach ($warehouses as $warehouse) $res[]['id_warehouse'] = $warehouse; */ return $warehouses; } $share_stock = false; if ($shop_id === null) { if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_GROUP) { $shop_group = JeproshopShopModelShop::getContextShopGroup(); } else { $shop_group = JeproshopContext::getContext()->shop->getShopGroup(); $shop_id = (int) JeproshopContext::getContext()->shop->shop_id; } $share_stock = $shop_group->share_stock; } else { $shop_group = JeproshopShopModelShop::getGroupFromShop($shop_id); $share_stock = $shop_group->share_stock; } if ($share_stock) { $shop_ids = JeproshopShopModelShop::getShops(true, (int) $shop_group->shop_group_id, true); } else { $shop_ids = array((int) $shop_id); } $query = "SELECT warehouse_product_location.warehouse_id, CONCAT(warehouse.reference, ' - ', warehouse.name)"; $query .= " AS name FROM " . $db->QuoteName('#__jeproshop_warehouse_product_location') . " AS warehouse_product_location"; $query .= " INNER JOIN " . $db->quoteName('#__jeproshop_warehouse_shop') . " AS warehouse_shop ON(warehouse_shop."; $query .= "warehouse_id = warehouse_product_location.warehouse_id AND shop_id IN (" . implode(',', array_map('intval', $shop_ids)); $query .= " )) INNER JOIN " . $db->quoteName('#__jeproshop_warehouse') . " AS warehouse ON (warehouse.warehouse_id = warehouse_shop."; $query .= "warehouse_id ) WHERE product_id = " . (int) $product_id . " AND product_attribute_id = " . (int) $product_attribute_id; $query .= " AND warehouse.deleted = 0 GROUP BY warehouse_product_location.warehouse_id"; $db->setQuery($query); return $db->loadObjectList(); }
public function initialize() { $app = JFactory::getApplication(); $context = JeproshopContext::getContext(); parent::initialize(); $category_id = $app->input->get('category_id'); $task = $app->input->get('task'); if ($category_id && $task != 'delete') { $this->category = new JeproshopCategoryModelCategory($category_id); } else { if (JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) { $this->category = new JeproshopCategoryModelCategory($context->shop->category_id); } elseif (count(JeproshopCategoryModelCategory::getCategoriesWithoutParent()) > 1 && JeproshopSettingModelSetting::getValue('multishop_feature_active') && count(JeproshopShopModelShop::getShops(true, null, true)) != 1) { $this->category = JeproshopCategoryModelCategory::getTopCategory(); } else { $this->category = new JeproshopCategoryModelCategory(JeproshopSettingModelSetting::getValue('root_category')); } } if (JeproshopTools::isLoadedObject($this->category, 'category_id') && !$this->category->isAssociatedToShop() && JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) { $app->redirect('index.php?option=com_jeproshop&view=category&task=edit&category_id=' . (int) $context->shop->getCategoryId() . '&' . JeproshopTools::getCategoryToken() . '=1'); } }
public static function getProducts($lang_id, $limit_start, $limit, $order_by = null, $order_way = null, $get_total = false, $published = true, $random = false, $random_number_products = 1, $check_access = true, JeproshopContext $context = null) { if (!$context) { $context = JeproshopContext::getContext(); } $db = JFactory::getDBO(); $app = JFactory::getApplication(); jimport('joomla.html.pagination'); //if ($check_access && !$context->controller->checkAccess($context->customer->customer_id, $category_id)){ return false; } if ($limit_start < 1) { $limit_start = 0; } if (empty($order_by)) { $order_by = 'position'; } else { /* Fix for all modules which are now using lowercase values for 'orderBy' parameter */ $order_by = strtolower($order_by); } if (empty($order_way)) { $order_way = "DESC"; } $order_by_prefix = false; if ($order_by == 'product_id' || $order_by == 'date_add' || $order_by == 'date_upd') { $order_by_prefix = "product"; } elseif ($order_by == 'name') { $order_by_prefix = "product_lang"; } elseif ($order_by == 'manufacturer') { $order_by_prefix = "manufacturer"; $order_by = "name"; } elseif ($order_by == 'position') { $order_by_prefix = "product"; } if ($order_by == 'price') { $order_by = 'order_price'; } if (!JeproshopTools::isOrderBy($order_by) || !JeproshopTools::isOrderWay($order_way)) { die(JError::raiseError()); } $supplier_id = (int) $app->input->get('supplier_id'); /* Return only the number of products */ $query = "SELECT COUNT(product." . $db->quoteName('product_id') . ") AS total FROM " . $db->quoteName('#__jeproshop_product') . " AS product "; $query .= JeproshopShopModelShop::addSqlAssociation('product') . " WHERE product_shop." . $db->quoteName('visibility') . " IN ('both', 'catalog')"; $query .= " AND product_shop." . $db->quoteName('published') . " = 1 " . ($supplier_id ? " AND product.supplier_id = " . (int) $supplier_id : ""); $db->setQuery($query); $total = (int) $db->loadResult(); $number_days_new_product = JeproshopSettingModelSetting::getValue('number_days_new_product'); $query = "SELECT product.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, MAX(product_attribute_shop.product_attribute_id) AS "; $query .= "product_attribute_id, product_attribute_shop.minimal_quantity AS product_attribute_minimal_quantity, product_lang." . $db->quoteName('description'); $query .= ", product_lang." . $db->quoteName('short_description') . ", product_lang." . $db->quoteName('available_now') . ", product_lang." . $db->quoteName('available_later'); $query .= ", product_lang." . $db->quoteName('link_rewrite') . ", product_lang." . $db->quoteName('meta_description') . ", product_lang." . $db->quoteName('meta_keywords'); $query .= ", product_lang." . $db->quoteName('meta_title') . ", product_lang." . $db->quoteName('name') . ", MAX(image_shop." . $db->quoteName('image_id') . " ) AS "; $query .= "image_id, image_lang." . $db->quoteName('legend') . ", manufacturer." . $db->quoteName('name') . " AS manufacturer_name, DATEDIFF(product_shop." . $db->quoteName('date_add'); $query .= ", DATE_SUB(NOW(), INTERVAL " . (JeproshopTools::isUnsignedInt($number_days_new_product) ? $number_days_new_product : 20) . "\tDAY)) > 0 AS new, product_shop.price AS"; $query .= " order_price FROM " . $db->quoteName('#__jeproshop_product') . " AS product " . JeproshopShopModelShop::addSqlAssociation('product') . " LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON (product." . $db->quoteName('product_id') . " = product_attribute." . $db->quoteName('product_id'); $query .= ") " . JeproshopShopModelShop::addSqlAssociation('product_attribute', false, 'product_attribute_shop.`default_on` = 1'); $query .= JeproshopProductModelProduct::sqlStock('product', 'product_attribute_shop', false, $context->shop) . " LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang'); $query .= " AS product_lang ON (product." . $db->quoteName('product_id') . " = product_lang." . $db->quoteName('product_id') . " AND product_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang'); $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_image') . " AS image ON (image." . $db->quoteName('product_id') . " = product." . $db->quoteName('product_id') . ") " . JeproshopShopModelShop::addSqlAssociation('image', false, 'image_shop.cover=1') . " LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image_shop." . $db->quoteName('image_id') . " = image_lang." . $db->quoteName('image_id') . " AND image_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_manufacturer') . " AS manufacturer ON manufacturer." . $db->quoteName('manufacturer_id') . " = product." . $db->quoteName('manufacturer_id') . "\tWHERE product_shop." . $db->quoteName('shop_id') . " = " . (int) $context->shop->shop_id; $query .= " AND product_shop." . $db->quoteName('published') . " = 1 AND product_shop." . $db->quoteName('visibility') . " IN ('both', 'catalog') "; $query .= ($supplier_id ? " AND product.supplier_id = " . (int) $supplier_id : "") . " GROUP BY product_shop.product_id"; if ($random === true) { $query .= " ORDER BY RAND() LIMIT " . (int) $random_number_products; } else { //$query .= " ORDER BY " . (!empty($order_by_prefix) ? $order_by_prefix. "." : "") . $db->quoteName($order_by); $query .= " " . $order_way . " LIMIT " . (int) $limit_start . ", " . (int) $limit; } $db->setQuery($query); $result = $db->loadObjectList(); if ($order_by == 'order_price') { JeproshopTools::orderbyPrice($result, $order_way); } if (!$result) { return array(); } self::$_pagination = new JPagination($total, $limit_start, $limit); /* Modify SQL result */ return JeproshopProductModelProduct::getProductsProperties($lang_id, $result); }
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(); }
/** * Get current ID of shop group if context is CONTEXT_SHOP or CONTEXT_GROUP * * @param bool $null_value_without_multishop * @return int */ public static function getContextShopGroupId($null_value_without_multishop = false) { if ($null_value_without_multishop && !JeproshopShopModelShop::isFeaturePublished()) { return null; } return self::$context_shop_group_id; }
public static function searchTag($id_lang, $tag, $count = false, $pageNumber = 0, $pageSize = 10, $orderBy = false, $orderWay = false, $useCookie = true, JeproshopContext $context = null) { if (!$context) { $context = JeproshopContext::getContext(); } // Only use cookie if id_customer is not present if ($useCookie) { $customer_id = (int) $context->customer->customer_id; } else { $customer_id = 0; } if (!is_numeric($pageNumber) || !is_numeric($pageSize) || !Validate::isBool($count) || !Validate::isValidSearch($tag) || $orderBy && !$orderWay || $orderBy && !Validate::isOrderBy($orderBy) || $orderWay && !Validate::isOrderBy($orderWay)) { return false; } if ($pageNumber < 1) { $pageNumber = 1; } if ($pageSize < 1) { $pageSize = 10; } $shop_id = JeproshopContext::getContext()->shop->shop_id; $shop_id = $shop_id ? $shop_id : JeproshopSettingModelSetting::getValue('default_shop'); $sql_groups = ''; if (JeproshopGroupModelGroup::isFeaturePublished()) { $groups = JeproshopController::getCurrentCustomerGroups(); $sql_groups = " AND customer_group." . $db->quoteName('group_id') . (count($groups) ? " IN (" . implode(',', $groups) . ")" : "= 1"); } if ($count) { $query = "SELECT COUNT(DISTINCT product_tag." . $db->quoteName('product_id') . ") nb FROM " . $db->quoteName('#__jeproshop_product'); $query .= " AS product " . JeproshopShopModelShop::addSqlAssociation('product') . "\tLEFT JOIN " . $db->quoteName('#__jeproshop_product_tag'); $query .= " AS product_tag ON (product." . $db->quoteName('product_id') . " = product_tag." . $db->quoteName('product_id') . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_tag') . " AS tag ON (product_tag." . $db->quoteName('tag_id') . " = tag." . $db->quoteName('tag_id'); $query .= " AND tag." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_category'); $query .= " AS product_category ON (product_category." . $db->quoteName('product_id') . " = product." . $db->quoteName('product_id') . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_category_shop') . " AS category_shop ON (product_category." . $db->quoteName('category_id') . " = category_shop."; $query .= $db->quoteName('category_id') . " AND category_shop." . $db->quoteName('shop_id') . " = " . (int) $shop_id . ") "; $query .= JeproshopGroupModelGroup::isFeaturePublished() ? " LEFT JOIN " . $db->quoteName('#__jeproshop_category_group') . " AS category_group ON (category_group." . $db->quoteName('category_id') . " = product_category." . $db->quoteName('category_id') . ")" : ""; $query .= "\tWHERE product_shop." . $db->quoteName('publishd') . " = 1 AND product.visibility IN ('both', 'search') AND category_shop." . $db->quoteName('shop_id'); $query .= " = " . (int) JeproshopContext::getContext()->shop->shop_id . $sql_groups . " AND tag." . $db->quoteName('name') . " LIKE '%'" . $db->quote($tag) . "'%')"; /*$query .= " } $sql = 'SELECT DISTINCT p.*, product_shop.*, stock.out_of_stock, IFNULL(stock.quantity, 0) as quantity, pl.`description_short`, pl.`link_rewrite`, pl.`name`, MAX(image_shop.`id_image`) id_image, il.`legend`, m.`name` manufacturer_name, 1 position, DATEDIFF( p.`date_add`, DATE_SUB( NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY ) ) > 0 new FROM `' $db->quoteName('#__jeproshop_product` p INNER JOIN `'.$db->quoteName('#__jeproshop_product_lang` pl ON ( p.`id_product` = pl.`id_product` AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').' )'.Shop::addSqlAssociation('product', 'p', false).' LEFT JOIN `'.$db->quoteName('#__jeproshop_image` i ON (i.`id_product` = p.`id_product`)'. Shop::addSqlAssociation('image', 'i', false, 'image_shop.cover=1').' LEFT JOIN `' . $db->quoteName('#__jeproshop_image_lang` il ON (i.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'. $db->quoteName('#__jeproshop_manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) LEFT JOIN `'. $db->quoteName('#__jeproshop_product_tag` pt ON (p.`id_product` = pt.`id_product`) LEFT JOIN `'. $db->quoteName('#__jeproshop_tag` t ON (pt.`id_tag` = t.`id_tag` AND t.`id_lang` = '.(int)$id_lang.') LEFT JOIN `'. $db->quoteName('#__jeproshop_category_product` cp ON (cp.`id_product` = p.`id_product`) '.(Group::isFeatureActive() ? 'LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = cp.`id_category`)' : '').' LEFT JOIN `'. $db->quoteName('#__jeproshop_category_shop` cs ON (cp.`id_category` = cs.`id_category` AND cs.`id_shop` = '.(int)$id_shop.') '.Product::sqlStock('p', 0).' WHERE product_shop.`active` = 1 AND cs.`id_shop` = '.(int)Context::getContext()->shop->id.' '.$sql_groups.' AND t.`name` LIKE \'%'.pSQL($tag).'%\' return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue( GROUP BY product_shop.id_product ORDER BY position DESC'.($orderBy ? ', '.$orderBy : '').($orderWay ? ' '.$orderWay : '').' LIMIT '.(int)(($pageNumber - 1) * $pageSize).','.(int)$pageSize; $db->setQuery($query); $result = $db->loadObjectList(); if (!$result) return false; */ } return JeproshopProductModelProduct::getProductsProperties((int) $lang_id, $result); }
/** * @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; }
/** * Get the user's journey * * @param integer $category_id Category ID * @param string $path Path end * @param bool $link_on_the_item * @param string $category_type * @param JeproshopContext $context * @return string * @internal param bool $linkOnTheLastItem Put or not a link on the current category * @internal param $string [optional] $categoryType defined what type of categories is used (products or cms) */ public static function getPath($category_id, $path = '', $link_on_the_item = false, $category_type = 'products', JeproshopContext $context = null) { if (!$context) { $context = JeproshopContext::getContext(); } $category_id = (int) $category_id; if ($category_id == 1) { return '<span class="navigation_end">' . $path . '</span>'; } $pipe = '>'; //Configuration::get('PS_NAVIGATION_PIPE'); if (empty($pipe)) { $pipe = '>'; } $full_path = ''; if ($category_type === 'products') { $interval = JeproshopCategoryModelCategory::getInterval($category_id); $root_category_id = $context->shop->getCategoryId(); $interval_root = JeproshopCategoryModelCategory::getInterval($root_category_id); $db = JFactory::getDBO(); if ($interval) { $query = "SELECT category.category_id, category_lang.name, category_lang.link_rewrite FROM " . $db->quoteName('#__jeproshop_category'); $query .= " AS category LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang') . " AS category_lang ON (category_lang.category_id ="; $query .= "category.category_id" . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang') . ")" . JeproshopShopModelShop::addSqlAssociation('category'); $query .= "\tWHERE category.n_left <= " . $interval->n_left . " AND category.n_right >= " . $interval->n_right . "\tAND category.n_left >= "; $query .= $interval_root->n_left . " AND category.n_right <= " . $interval_root->n_right . " AND category_lang.lang_id = " . (int) $context->language->lang_id; $query .= "\tAND category.published = 1 AND category.depth_level > " . (int) $interval_root->depth_level . " ORDER BY category.depth_level ASC"; $db->setQuery($query); $categories = $db->loadObjectList(); $n = 1; $n_categories = count($categories); foreach ($categories as $category) { $full_path .= ($n < $n_categories || $link_on_the_item ? '<a href="' . JeproshopTools::safeOutput($context->controller->getCategoryLink((int) $category->category_id, $category->link_rewrite)) . '" title="' . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . '">' : '') . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . ($n < $n_categories || $link_on_the_item ? '</a>' : '') . ($n++ != $n_categories || !empty($path) ? '<span class="navigation-pipe">' . $pipe . '</span>' : ''); } return $full_path . $path; } } else { if ($category_type === 'CMS') { $category = new CMSCategory($category_id, $context->language->id); if (!Validate::isLoadedObject($category)) { die(Tools::displayError()); } $category_link = $context->link->getCMSCategoryLink($category); if ($path != $category->name) { $full_path .= '<a href="' . Tools::safeOutput($category_link) . '">' . htmlentities($category->name, ENT_NOQUOTES, 'UTF-8') . '</a><span class="navigation-pipe">' . $pipe . '</span>' . $path; } else { $full_path = ($link_on_the_item ? '<a href="' . Tools::safeOutput($category_link) . '">' : '') . htmlentities($path, ENT_NOQUOTES, 'UTF-8') . ($link_on_the_item ? '</a>' : ''); } return Tools::getPath($category->parent_id, $full_path, $link_on_the_item, $category_type); } } }
public function renderView($tpl = null) { if ($this->getLayout() !== 'modal') { } if ($this->context == null) { $this->context = JeproshopContext::getContext(); } $db = JFactory::getDBO(); $this->setLayout('view'); $this->loadObject(); if (!JeproshopTools::isLoadedObject($this->customer, 'customer_id')) { return; } $this->context->customer = $this->customer; $customer_stats = $this->customer->getStats(); $query = "SELECT SUM(total_paid_real) FROM " . $db->quoteName('#__jeproshop_orders'); $query .= " WHERE customer_id = " . (int) $this->customer->customer_id . " AND valid = 1"; $db->setQuery($query); $total_customer = $db->loadResult(); if ($total_customer) { $query = "SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM " . $db->quoteName('#__jeproshop_orders'); $query .= " WHERE valid = 1 AND customer_id != " . (int) $this->customer->customer_id . " GROUP BY "; $query .= "customer_id HAVING SUM(total_paid_real) > " . (int) $total_customer; $db->setQuery($query); $db->loadResult(); $count_better_customers = (int) $db->loadResult('SELECT FOUND_ROWS()') + 1; } else { $count_better_customers = '-'; } $orders = JeproshopOrderModelOrder::getCustomerOrders($this->customer->customer_id, true); $total_orders = count($orders); for ($i = 0; $i < $total_orders; $i++) { $orders[$i]->total_paid_real_not_formated = $orders[$i]->total_paid_real; $orders[$i]->total_paid_real = JeproshopTools::displayPrice($orders[$i]->total_paid_real, new JeproshopCurrencyModelCurrency((int) $orders[$i]->currency_id)); } $messages = JeproshopCustomerThreadModelCustomerThread::getCustomerMessages((int) $this->customer->customer_id); $total_messages = count($messages); for ($i = 0; $i < $total_messages; $i++) { $messages[$i]->message = substr(strip_tags(html_entity_decode($messages[$i]->message, ENT_NOQUOTES, 'UTF-8')), 0, 75); $messages[$i]->date_add = Tools::displayDate($messages[$i]->date_add, null, true); } $groups = $this->customer->getGroups(); $total_groups = count($groups); for ($i = 0; $i < $total_groups; $i++) { $group = new JeproshopGroupModelGroup($groups[$i]); $groups[$i] = array(); $groups[$i]['group_id'] = $group->group_id; $groups[$i]['name'] = $group->name[$this->context->controller->default_form_language]; } $total_ok = 0; $orders_ok = array(); $orders_ko = array(); foreach ($orders as $order) { if (!isset($order->order_state)) { $order->order_state = JText::_('COM_JEPROSHOP_THERE_IS_NO_STATUS_DEFINED_FOR_THIS_ORDER_MESSAGE'); } if ($order->valid) { $orders_ok[] = $order; $total_ok += $order->total_paid_real_not_formated; } else { $orders_ko[] = $order; } } $products = $this->customer->getBoughtProducts(); $carts = JeproshopCartModelCart::getCustomerCarts($this->customer->customer_id); $total_carts = count($carts); for ($i = 0; $i < $total_carts; $i++) { $cart = new JeproshopCartModelCart((int) $carts[$i]->cart_id); $this->context->cart = $cart; $summary = $cart->getSummaryDetails(); $currency = new JeproshopCurrencyModelCurrency((int) $carts[$i]->currency_id); $carrier = new JeproshopCarrierModelCarrier((int) $carts[$i]->carrier_id); $carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']); $carts[$i]['date_add'] = JeproshopValidator::displayDate($carts[$i]->date_add, null, true); $carts[$i]['total_price'] = Tools::displayPrice($summary->total_price, $currency); $carts[$i]->name = $carrier->name; } $query = "SELECT DISTINCT cart_product.product_id, cart.cart_id, cart.shop_id, cart_product.shop_id "; $query .= " AS cart_product_shop_id FROM " . $db->quoteName('#__jeproshop_cart_product') . " AS cart_product"; $query .= " JOIN " . $db->quoteName('#__jeproshop_cart') . " AS cart ON (cart.cart_id = cart_product.cart_id) "; $query .= "JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON (cart_product.product_id = product."; $query .= "product_id) WHERE cart.customer_id = " . (int) $this->customer->customer_id . " AND cart_product.product_id"; $query .= " NOT IN ( SELECT product_id FROM " . $db->quoteName('#__jeproshop_orders') . " AS ord JOIN "; $query .= $db->quoteName('#__jeproshop_order_detail') . " AS ord_detail ON (ord.order_id = ord_detail.order_id ) WHERE "; $query .= "ord.valid = 1 AND ord.customer_id = " . (int) $this->customer->customer_id . ")"; $db->setQuery($query); $interested = $db->loadObjectList(); $total_interested = count($interested); for ($i = 0; $i < $total_interested; $i++) { $product = new JeproshopProductModelProduct($interested[$i]->product_id, false, $this->context->controller->default_form_language, $interested[$i]->shop_id); if (!Validate::isLoadedObject($product, 'product_id')) { continue; } $interested[$i]->url = $this->context->controller->getProductLink($product->product_id, $product->link_rewrite, JeproshopCategoryModelCategory::getLinkRewrite($product->default_category_id, $this->context->controller->default_form_language), null, null, $interested[$i]->cp_shop_id); $interested[$i]->product_id = (int) $product->product_id; $interested[$i]->name = htmlentities($product->name); } $connections = $this->customer->getLastConnections(); if (!is_array($connections)) { $connections = array(); } $total_connections = count($connections); for ($i = 0; $i < $total_connections; $i++) { $connections[$i]->http_referer = $connections[$i]->http_referer ? preg_replace('/^www./', '', parse_url($connections[$i]->http_referer, PHP_URL_HOST)) : JText::_('COM_JEPROSHOP_DIRECT_LINK_LABEL'); } $referrers = JeproshopReferrerModelReferrer::getReferrers($this->customer->customer_id); $total_referrers = count($referrers); for ($i = 0; $i < $total_referrers; $i++) { $referrers[$i]->date_add = JeproshopTools::displayDate($referrers[$i]->date_add, null, true); } $customerLanguage = new JeproshopLanguageModelLanguage($this->customer->lang_id); $shop = new JeproshopShopModelShop($this->customer->shop_id); //$this->assignRef('customer', $customer); /*'gender' => $gender, /* 'gender_image' => $gender_image, // General information of the customer */ $registration = JeproshopTools::displayDate($this->customer->date_add, null, true); $this->assignRef('registration_date', $registration); $this->assignRef('customer_stats', $customer_stats); $last_visit = JeproshopTools::displayDate($customer_stats->last_visit, null, true); $this->assignRef('last_visit', $last_visit); $this->assignRef('count_better_customers', $count_better_customers); $shop_feature_active = JeproshopShopModelShop::isFeaturePublished(); $this->assignRef('shop_is_feature_active', $shop_feature_active); $this->assignRef('shop_name', $shop->shop_name); $customerBirthday = JeproshopTools::displayDate($this->customer->birthday); $this->assignRef('customer_birthday', $customerBirthday); $last_update = JeproshopTools::displayDate($this->customer->date_upd, null, true); $this->assignRef('last_update', $last_update); $customerExists = JeproshopCustomerModelCustomer::customerExists($this->customer->email); $this->assignRef('customer_exists', $customerExists); $this->assignRef('lang_id', $this->customer->lang_id); $this->assignRef('customerLanguage', $customerLanguage); // Add a Private note $customerNote = JeproshopTools::htmlentitiesUTF8($this->customer->note); $this->assignRef('customer_note', $customerNote); // Messages $this->assignRef('messages', $messages); // Groups $this->assignRef('groups', $groups); // Orders $this->assignRef('orders', $orders); $this->assignRef('orders_ok', $orders_ok); $this->assignRef('orders_ko', $orders_ko); $total_ok = JeproshopTools::displayPrice($total_ok, $this->context->currency->currency_id); $this->assignRef('total_ok', $total_ok); // Products $this->assignRef('products', $products); // Addresses $addresses = $this->customer->getAddresses($this->context->controller->default_form_language); $this->assignRef('addresses', $addresses); // Discounts $discounts = JeproshopCartRuleModelCartRule::getCustomerCartRules($this->context->controller->default_form_language, $this->customer->customer_id, false, false); $this->assignRef('discounts', $discounts); // Carts $this->assignRef('carts', $carts); // Interested $this->assignRef('interested_products', $interested); // Connections $this->assignRef('connections', $connections); // Referrers $this->assignRef('referrers', $referrers); if ($this->getLayout() != 'modal') { $this->addToolBar(); $this->sideBar = JHtmlSidebar::render(); } parent::display($tpl); }
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 static function getItemTable($product_id, $lang_id, $full = false) { if (!JeproshopProductPack::isFeaturePublished()) { return array(); } $db = JFactory::getDBO(); $query = "SELECT product.*, product_shop.*, product_lang.*, MAX(image_shop." . $db->quoteName('image_id') . ") image_id, image_lang." . $db->quoteName('legend'); $query .= ", category_lang." . $db->quoteName('name') . " AS default_category, pack.quantity AS pack_quantity, product_shop." . $db->quoteName('default_category_id'); $query .= ", pack.product_pack_id FROM " . $db->quoteName('#__jeproshop_pack') . " AS pack LEFT JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON("; $query .= "product.product_id = pack.product_item_id) LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang') . " AS product_lang ON(product.product_id = product_lang."; $query .= "product_id AND product_lang.lang_id = " . (int) $lang_id . JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang') . ") LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_image') . " AS image ON( image.product_id = product.product_id )" . JeproshopShopModelShop::addSqlAssociation('product', FALSE, 'image_shop.cover = 1'); $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_image_lang') . " AS image_lang ON (image.image_id = image_lang.image_id AND image_lang.lang_id = " . (int) $lang_id . " ) "; $query .= JeproshopShopModelShop::addSqlAssociation('product') . " LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang') . " AS category_lang ON product_shop."; $query .= $db->quoteName('default_category_id') . " = category_lang." . $db->quoteName('category_id') . " AND category_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id; $query .= JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang') . " WHERE product_shop." . $db->quoteName('shop_id') . " = " . (int) JeproshopContext::getContext()->shop->shop_id; $query .= " AND pack." . $db->quoteName('product_pack_id') . " = " . (int) $product_id . " GROUP BY product_shop.product_id"; $db->setQuery($query); $result = $db->loadObjectList(); foreach ($result as &$line) { $line = JeproshopProductModelProduct::getTaxesInformations($line); } if (!$full) { return $result; } $array_result = array(); foreach ($result as $prow) { if (!JeproshopProductPack::isPack($prow->product_id)) { $array_result[] = JeproshopProductModelProduct::getProductProperties($lang_id, $prow); } } return $array_result; }
/** * Load list of groups and shops, and cache it * * @param bool $refresh */ public static function cacheShops($refresh = false) { if (!is_null(self::$shops) && !$refresh) { return; } self::$shops = array(); $db = JFactory::getDBO(); $from = ""; $where = ""; $employee = JeproshopContext::getContext()->employee; // If the profile isn't a superAdmin if (JeproshopTools::isLoadedObject($employee, 'employee_id') && $employee->profile_id != _PS_ADMIN_PROFILE_) { $from .= " LEFT JOIN " . $db->quoteName('#__jeproshop_employee_shop') . " AS employee_shop ON employee_shop.shop_id = shop.shop_id"; $where .= " AND employee_shop.employee_id = " . (int) $employee->employee_id; } $query = "SELECT shop_group.*, shop.*, shop_group.name AS group_name, shop.shop_name AS shop_name, "; $query .= " shop.published, shop_url.domain, shop_url.ssl_domain, shop_url.physical_uri, shop_url."; $query .= "virtual_uri FROM " . $db->quoteName('#__jeproshop_shop_group') . " AS shop_group LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_shop') . " AS shop ON shop.shop_group_id = shop_group.shop_group_id "; $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_shop_url') . " AS shop_url ON shop.shop_id ="; $query .= " shop_url.shop_id AND shop_url.main = 1 " . $from . " WHERE shop.deleted = 0 AND shop_group."; $query .= "deleted = 0 " . $where . " ORDER BY shop_group.name, shop.shop_name"; $db->setQuery($query); $results = $db->loadObjectList(); if ($results) { foreach ($results as $row) { if (!isset(self::$shops[$row->shop_group_id])) { self::$shops[$row->shop_group_id] = array('shop_group_id' => $row->shop_group_id, 'name' => $row->group_name, 'share_customer' => $row->share_customer, 'share_order' => $row->share_order, 'share_stock' => $row->share_stock, 'shops' => array()); self::$shops[$row->shop_group_id]['shops'][$row->shop_id] = $row; /*array( 'shop_id' => $row->shop_id, 'shop_group_id' => $row->shop_group_id, 'name' => $row->shop_name, 'theme_id' => $row->theme_id, 'category_id' => $row->category_id, 'domain' => $row->domain, 'ssl_domain' => $row->ssl_domain, 'uri' => $row->physical_uri . $row->virtual_uri, 'published' => $row->published );*/ } } } }
/** * 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 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; }
public function isMultiShop() { return JeproshopShopModelShop::isTableAssociated('group') || !empty($this->multiLangShop); }
protected function loadObject($option = false) { $app = JFactory::getApplication(); $product_id = $app->input->get('product_id'); $isLoaded = false; $context = JeproshopContext::getContext(); if ($product_id && JeproshopTools::isUnsignedInt($product_id)) { if (!$this->product) { $this->product = new JeproshopProductModelProduct($product_id, false, $context->language->lang_id); } if (!JeproshopTools::isLoadedObject($this->product, 'product_id')) { JError::raiseError(500, JText::_('COM_JEPROSHOP_PRODUCT_NOT_FOUND_MESSAGE')); $isLoaded = false; } else { $isLoaded = true; } } elseif ($option) { if (!$this->product) { $this->product = new JeproshopProductModelProduct(); } } else { JError::raiseError(500, JText::_('COM_JEPROSHOP_PRODUCT_DOES_NOT_EXIST_MESSAGE')); $isLoaded = false; } //specified if ($isLoaded && JeproshopTools::isLoadedObject($this->product, 'product_id')) { if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP && JeproshopShopModelShop::isFeaturePublished() && !$this->product->isAssociatedToShop()) { $this->product = new JeproshopProductModelProduct((int) $this->product->product_id, false, $context->language->lang_id, (int) $this->product->default_shop_id); } $this->product->loadStockData(); } return $isLoaded; }
* but WITHOUT ANY WARRANTY; without even the implied warranty of, * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ // no direct access defined('_JEXEC') or die('Restricted access'); if (!file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'load.php')) { JError::raiseError(500, JText::_('')); } require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'load.php'; $context = JeproshopContext::getContext(); /** initialize the shop **/ $context->shop = JeproshopShopModelShop::initialize(); /** load configuration */ JeproshopSettingModelSetting::loadSettings(); /** load languages */ JeproshopLanguageModelLanguage::loadLanguages(); /** set context cookie */ $life_time = time() + max(JeproshopSettingModelSetting::getValue('bo_life_time'), 1) * 3600; $context->cookie = new JeproshopCookie('jeproshop_site', '', $life_time); /** @var employee */ $context->employee = new JeproshopEmployeeModelEmployee(JFactory::getUser()->id); $context->cookie->employee_id = $context->employee->employee_id; /** Loading default country */ $context->country = new JeproshopCountryModelCountry(JeproshopSettingModelSetting::getValue('default_country'), JeproshopSettingModelSetting::getValue('default_lang')); /** if the cookie stored language is not an available language, use default language */ if (isset($context->cookie->lang_id) && $context->cookie->lang_id) { $language = new JeproshopLanguageModelLanguage($context->cookie->lang_id);
public static function getAttachedProduct($lang_id, $list) { $attachment_ids = array(); if (is_array($list)) { foreach ($list as $attachment) { $attachment_ids[] = $attachment->attachment_id; } $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_product_attachment') . " AS product_attachment LEFT JOIN "; $query .= $db->quoteName('#__jeproshop_product_lang') . " AS product_lang ON (product_attachment." . $db->quoteName('product_id'); $query .= " = product_lang." . $db->quoteName('product_id') . JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang'); $query .= ") WHERE " . $db->quoteName('attachment_id') . " IN (" . implode(',', array_map('intval', $attachment_ids)); $query .= ") AND product_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id; $db->setQuery($query); $tmp = $db->loadObjectList(); $productAttachments = array(); foreach ($tmp as $t) { $productAttachments[$t->attachment_id][] = $t->name; } return $productAttachments; } else { return false; } }
public static function getDeliveredCountries($lang_id, $active_countries = false, $active_carriers = false, $contain_states = null) { if (!JeproshopTools::isBool($active_countries) || !JeproshopTools::isBool($active_carriers)) { die(Tools::displayError()); } $db = JFactory::getDBO(); $query = "SELECT state.* FROM " . $db->quoteName('#__jeproshop_state') . " AS state ORDER BY state." . $db->quoteName('name') . " ASC"; $db->setQuery($query); $states = $db->loadObjectList(); $query = "SELECT country_lang.*, country.*, country_lang." . $db->quoteName('name') . " AS country_name, zone." . $db->quoteName('name') . " AS zone_name FROM " . $db->quoteName('#__jeproshop_country') . " AS country "; $query .= JeproshopShopModelShop::addSqlAssociation('country') . " LEFT JOIN " . $db->quoteName('#__jeproshop_country_lang') . " AS country_lang ON (country." . $db->quoteName('country_id') . " = country_lang." . $db->quoteName('country_id'); $query .= " AND country_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") INNER JOIN (" . $db->quoteName('#__jeproshop_carrier_zone') . " AS carrier_zone INNER JOIN " . $db->quoteName('#__jeproshop_carrier'); $query .= " AS carrier ON ( carrier.carrier_id = carrier_zone.carrier_id AND carrier.deleted = 0 " . ($active_carriers ? " AND carrier.published = 1) " : ") ") . " LEFT JOIN " . $db->quoteName('#__jeproshop_zone') . " AS zone ON(carrier_zone."; $query .= $db->quoteName('zone_id') . " = zone." . $db->quoteName('zone_id') . " AND zone." . $db->quoteName('zone_id') . " = country." . $db->quoteName('zone_id') . ") WHERE 1 " . ($active_countries ? " AND country." . $db->quoteName('published') . " = 1" : ""); $query .= (!is_null($contain_states) ? " AND country." . $db->quoteName('contains_states') . " = " . (int) $contain_states : "") . " ORDER BY country_lang.name ASC"; $db->setQuery($query); $result = $db->loadObjectList(); $countries = array(); foreach ($result as &$country) { $countries[$country->country_id] = $country; } foreach ($states as &$state) { if (isset($countries[$state->country_id])) { /* Does not keep the state if its country has been disabled and not selected */ if ($state->published == 1) { $countries[$state->country_id]['states'][] = $state; } } } return $countries; }
/** * Removes a given product from the stock available * * @param int $product_id * @param int $product_attribute_id Optional * @param mixed $shop shop id or shop object Optional */ public static function removeProductFromStockAvailable($product_id, $product_attribute_id = null, $shop = null) { if (!JeproshopTools::isUnsignedInt($product_id)) { return false; } $db = JFactory::getDBO(); if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) { if (JeproshopShopModelShop::getContextShopGroup()->share_stock == 1) { $product_attribute_sql = ''; if ($product_attribute_id !== null) { $product_attribute_sql = '_attribute'; $product_attribute_id_sql = $product_attribute_id; } else { $product_attribute_id_sql = $product_id; } $query = "SELECT COUNT(*) FROM " . $db->quoteName('#__jeproshop_product' . $product_attribute_sql . '_shop') . " WHERE " . $db->quoteName('product' . $product_attribute_sql . '_id') . " = "; $query .= (int) $product_attribute_id_sql . " AND " . $db->quoteName('shop_id') . " IN (" . implode(',', array_map('intval', JeproshopShopModelShop::getContextListShopIds(JeproshopShopModelShop::SHARE_STOCK))) . ")"; $db->setQuery($query); $result = (int) $db->loadResult(); if ($result) { return true; } } } $query = "DELETE FROM " . $db->quoteName('#__jeproshop_stock_available') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id; $query .= ($product_attribute_id ? " AND " . $db->quoteName('product_attribute_id') . " = " . (int) $product_attribute_id : "") . JeproshopStockAvailableModelStockAvailable::addShopRestriction(null, $shop); $db->setQuery($query); $res = $db->query(); if ($product_attribute_id) { if ($shop === null || !JeproshopTools::isLoadedObject($shop, 'shop_id')) { $shop_datas = new Object(); JeproshopStockAvailableModelStockAvailable::addSqlShopParams($shop_datas); $shop_id = (int) $shop_datas->shop_id; } else { $shop_id = (int) $shop->shop_id; } $stock_available = new JeproshopStockAvailableModelStockAvailable(); $stock_available->product_id = (int) $product_id; $stock_available->product_attribute_id = (int) $product_id; $stock_available->shop_id = (int) $shop_id; $stock_available->postSave(); } JeproshopCache::clean('jeproshop_stock_available_get-quantity_Available_by_product_' . (int) $product_id . '_*'); return $res; }
</div> <div class="control-group" > <div class="control-label" ><label for="jform_" title="<?php echo JText::_('COM_JEPROSHOP_PUBLISHED_TITLE_DESC'); ?> " ><?php echo JText::_('COM_JEPROSHOP_PUBLISHED_LABEL'); ?> </label> </div> <div class="controls" ><?php echo $this->helper->radioButton('published'); ?> </div> </div> <?php if (JeproshopShopModelShop::isFeaturePublished()) { ?> <div class="control-group" > <div class="control-label" ><label for="jform_" title="<?php echo JText::_('COM_JEPROSHOP_ASSOCIATED_SHOP_TITLE_DESC'); ?> " ><?php echo JText::_('COM_JEPROSHOP_ASSOCIATED_SHOP_LABEL'); ?> </label> </div> <div class="controls" ><?php echo $this->shop_tree; ?> </div> </div> <?php
/** * @static * @param $lang_id * @param $customer_id * @param bool $published * @param bool $includeGeneric * @param bool $inStock * @param JeproshopCartModelCart|null $cart * @return array */ public static function getCustomerCartRules($lang_id, $customer_id, $published = false, $includeGeneric = true, $inStock = false, JeproshopCartModelCart $cart = null) { if (!JeproshopCartRuleModelCartRule::isFeaturePublished()) { return array(); } $db = JFactory::getDBO(); $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_cart_rule') . " AS cart_rule LEFT JOIN " . $db->quoteName('#__jeproshop_cart_rule_lang'); $query .= " AS cart_rule_lang ON (cart_rule." . $db->quoteName('cart_rule_id') . " = cart_rule_lang." . $db->quoteName('cart_rule_id') . " AND "; $query .= "cart_rule_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") WHERE ( cart_rule." . $db->quoteName('customer_id') . " = "; $query .= (int) $customer_id . " OR cart_rule.group_restriction = 1 " . ($includeGeneric ? "OR cart_rule." . $db->quoteName('customer_id') . " = 0" : ""); $query .= ") AND cart_rule.date_from < \"" . date('Y-m-d H:i:s') . "\" AND cart_rule.date_to > \"" . date('Y-m-d H:i:s') . "\""; $query .= ($published ? " AND cart_rule" . $db->quoteName('published') . " = 1" : "") . ($inStock ? " AND cart_rule." . $db->quoteName('quantity') . " > 0" : ""); $db->setQuery($query); $result = $db->loadObjectList(); // Remove cart rule that does not match the customer groups $customerGroups = JeproshopCustomerModelCustomer::getGroupsStatic($customer_id); foreach ($result as $key => $cart_rule) { if ($cart_rule->group_restriction) { $query = "SELECT " . $db->quoteName('group_id') . " FROM " . $db->quoteName('#__jeproshop_cart_rule_group') . " WHERE " . $db->quoteName('cart_rule_id') . " = " . (int) $cart_rule->cart_rule_id; $db->setQuery($query); $cartRuleGroups = $db->loadObjectList(); foreach ($cartRuleGroups as $cartRuleGroup) { if (in_array($cartRuleGroup->group_id, $customerGroups)) { continue 2; } } unset($result[$key]); } } foreach ($result as &$cart_rule) { if ($cart_rule->quantity_per_user) { $quantity_used = JeproshopOrderModelOrder::getCustomerDiscounts((int) $customer_id, (int) $cart_rule->cart_rule_id); if (isset($cart) && isset($cart->cart_id)) { $quantity_used += $cart->getDiscountsCustomer((int) $cart_rule->cart_rule_id); } $cart_rule->quantity_for_user = $cart_rule->quantity_per_user - $quantity_used; } else { $cart_rule->quantity_for_user = 0; } } unset($cart_rule); foreach ($result as $cart_rule) { if ($cart_rule->shop_restriction) { $query = "SELECT shop_id FROM " . $db->quoteName('#__jeproshop_cart_rule_shop') . " WHERE cart_rule_id = " . (int) $cart_rule->cart_rule_id; $db->setQuery($query); $cartRuleShops = $db->loadObjectList(); foreach ($cartRuleShops as $cartRuleShop) { if (JeproshopShopModelShop::isFeatureActive() && $cartRuleShop->shop_id == JeproshopContext::getShopContext()->shop->shop_id) { continue 2; } } unset($result[$key]); } } // RetroCompatibility with 1.4 discounts foreach ($result as &$cart_rule) { $cart_rule->value = 0; $cart_rule->minimal = JeproshopTools::convertPriceFull($cart_rule->minimum_amount, new JeproshopCurrencyModelCurrency($cart_rule->minimum_amount_currency), JeproshopContext::getContext()->currency); $cart_rule->cumulable = !$cart_rule->cart_rule_restriction; $cart_rule->discount_type_id = false; if ($cart_rule->free_shipping) { $cart_rule->discount_type_id = Discount::FREE_SHIPPING; } elseif ($cart_rule->reduction_percent > 0) { $cart_rule->discount_type_id = Discount::PERCENT; $cart_rule->value = $cart_rule->reduction_percent; } elseif ($cart_rule->reduction_amount > 0) { $cart_rule->discount_type_id = Discount::AMOUNT; $cart_rule->value = $cart_rule->reduction_amount; } } return $result; }