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 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; }
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; } }
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'); } }
/** * 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 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 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; }
/** * Add an sql restriction for shops fields * * @param boolean $share If false, dont check share datas from group. Else can take a Shop::SHARE_* constant value * @param string $alias * @return string */ public static function addSqlRestriction($share = false, $alias = null) { if ($alias) { $alias .= '.'; } $group = JeproshopShopModelShop::getShopGroupFromShop(JeproshopShopModelShop::getContextShopID(), false); if ($share == JeproshopShopModelShop::SHARE_CUSTOMER && JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP && $group['share_customer']) { $restriction = " AND " . $alias . "shop_group_id = " . (int) JeproshopShopModelShop::getContextShopGroupId(); } else { $restriction = " AND " . $alias . "shop_id IN (" . implode(', ', JeproshopShopModelShop::getContextListShopIds($share)) . ") "; } return $restriction; }
public static function getContextListShopIds($share = false) { if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) { $list = $share ? JeproshopShopModelShop::getSharedShops(JeproshopShopModelShop::getContextShopId(), $share) : array(JeproshopShopModelShop::getContextShopId()); } elseif (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_GROUP) { $list = JeproshopShopModelShop::getShops(true, JeproshopShopModelShop::getContextShopGroupId(), true); } else { $list = JeproshopShopModelShop::getShops(TRUE, null, true); } return $list; }
/** * 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; }
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; }
public function updateCategory() { $db = JFactory::getDBO(); $app = JFactory::getApplication(); $input = JRequest::get('post'); $category_data = $input['jform']; $languages = JeproshopLanguageModelLanguage::getLanguages(); $context = JeproshopContext::getContext(); if (!$context->controller->has_errors) { $category_id = (int) $app->input->get('category_id'); /** update category */ if (isset($category_id) && !empty($category_id)) { //$category = new JeproshopCategoryModelCategory($category_id); if (JeproshopTools::isLoadedObject($this, 'category_id')) { if ($this->category_id == $this->parent_id) { $context->controller->has_errors = true; JError::_(500, JText::_('COM_JEPROSHOP_A_CATEGORY_CANNOT_BE_ITS_OWN_PARENT_LABEL')); } if ($this->is_root_category) { $this->parent_id = JeproshopSettingModelSetting::getValue('root_category'); } // Update group selection $this->updateGroup($this->groupBox); $this->depth_level = $this->calculateDepthLevel(); // If the parent category was changed, we don't want to have 2 categories with the same position if ($this->getDuplicatedPosition()) { if ($category_data['check_box_shop_associated_category']) { foreach ($category_data['check_box_shop_associated_category'] as $associated_category_id => $row) { foreach ($row as $shop_id => $value) { $this->addPosition(JeproshopCategoryModelCategory::getLastPosition((int) $this->parent_id, (int) $shop_id), (int) $shop_id); } } } else { foreach (JeproshopShopModelShop::getShops(true) as $shop) { $this->addPosition(max(1, JeproshopCategoryModelCategory::getLastPosition((int) $this->parent_id, $shop->shop_id)), $shop->shop_id); } } } $this->cleanPositions((int) $this->parent_id); $this->clearCache(); $this->date_upd = date('Y-m-d H:i:s'); $shop_list_ids = JeproshopShopModelShop::getContextListShopIds(); if (count($this->shop_list_ids) > 0) { $shop_list_ids = $this->shop_list_ids; } if (JeproshopShopModelShop::checkDefaultShopId('category') && !$this->default_shop_id) { $this->default_shop_id = min($shop_list_ids); } $result = true; $query = "UPDATE " . $db->quoteName('#__jeproshop_category') . " SET " . $db->quoteName('n_left') . " = " . (int) $this->n_left . ", "; $query .= $db->quoteName('n_right') . " = " . (int) $this->n_right . ", " . $db->quoteName('depth_level') . " = " . (int) $this->depth_level; $query .= ", " . $db->quoteName('published') . " = " . (int) $category_data['published'] . ", " . $db->quoteName('default_shop_id') . " = " . (int) $this->default_shop_id; $query .= ", " . $db->quoteName('is_root_category') . " = " . (int) $category_data['is_root_category'] . ", " . $db->quoteName('position') . " = "; $query .= (int) $this->position . ", " . $db->quoteName('date_upd') . " = " . $db->quote($this->date_upd) . " WHERE " . $db->quoteName('category_id'); $query .= " = " . (int) $this->category_id; $db->setQuery($query); $result &= $db->query(); foreach ($shop_list_ids as $shop_id) { $where = " WHERE " . $db->quoteName('category_id') . " = " . (int) $this->category_id . " AND " . $db->quoteName('shop_id') . " = " . (int) $shop_id; $select = "SELECT " . $db->quoteName('category_id') . " FROM " . $db->quoteName('#__jeproshop_category_shop') . $where; $db->setQuery($select); $shop_exist = $db->loadObject()->category_id > 0; if ($shop_exist) { $query = "UPDATE " . $db->quoteName('#__jeproshop_category_shop') . " SET " . $db->quoteName('position') . " = " . (int) $this->position . $where; $db->setQuery($query); $result &= $db->query(); } elseif (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) { $query = "INSERT INTO " . $db->quoteName('#__jeproshop_category_shop') . "(" . $db->quoteName('category_id') . ", " . $db->quoteName('shop_id') . ", " . $db->quoteName('position'); $query .= ") VALUES (" . (int) $this->category_id . ", " . (int) $shop_id . ", " . (int) $this->position . ")"; $db->setQuery($query); $result &= $db->query(); } foreach ($languages as $language) { $where = " WHERE " . $db->quoteName('category_id') . " = " . (int) $this->category_id . " AND " . $db->quoteName('shop_id'); $where .= " = " . (int) $shop_id . " AND " . $db->quoteName('lang_id') . " = " . (int) $language->lang_id; $select = "SELECT COUNT(*) FROM " . $db->quoteNAme('#__jeproshop_category_lang') . $where; $db->setQuery($select); $lang_exist = $db->loadResult(); if ($lang_exist) { $query = "UPDATE " . $db->quoteName('#__jeproshop_category_lang') . " SET " . $db->quoteName('name') . " = " . $db->quote($category_data['name_' . $language->lang_id]) . ", "; $query .= $db->quoteName('description') . " = " . $db->quote($category_data['description_' . $language->lang_id]) . ", " . $db->quoteName('link_rewrite') . " = "; $query .= $db->quote($category_data['link_rewrite_' . $language->lang_id]) . ", " . $db->quoteName('meta_title') . " = " . $db->quote($category_data['meta_title_' . $language->lang_id]); $query .= ", " . $db->quoteName('meta_keywords') . " = " . $db->quote($category_data['meta_keywords_' . $language->lang_id]) . ", " . $db->quoteName('meta_description'); $query .= " = " . $db->quote($category_data['meta_description_' . $language->lang_id]) . $where; } else { $query = "INSERT INTO " . $db->quoteName('#__jeproshop_category_lang') . " (" . $db->quoteName('name') . ", " . $db->quoteName('description') . ", " . $db->quoteName('link_rewrite'); $query .= ", " . $db->quoteName('meta_title') . ", " . $db->quoteName('meta_keywords') . ", " . $db->quoteName('meta_description') . ") VALUES (" . $db->quote($category_data['name_' . $language->lang_id]); $query .= ", " . $db->quote($category_data['description_' . $language->lang_id]) . ", " . $db->quote($category_data['link_rewrite_' . $language->lang_id]) . ", "; $query .= $db->quote($category_data['meta_title_' . $language->lang_id]) . ", " . $db->quote($category_data['meta_keywords_' . $language->lang_id]) . ", "; $query .= $db->quote($category_data['meta_description_' . $language->lang_id]) . ") " . $where; } $db->setQuery($query); $result &= $db->query(); } } if (!isset($this->doNotRegenerateNTree) || !$this->doNotRegenerateNTree) { JeproshopCategoryModelCategory::regenerateEntireNestedtree(); $this->recalculateLevelDepth($this->category_id); } } $message = ''; $link = 'index.php?option=com_jeproshop&view=category&category_id=' . (int) $this->category_id . '&task=edit' . JeproshopTools::getCategoryToken(); } else { $message = ''; $link = 'index.php?option=com_jeproshop&view=category&category_id=' . (int) $this->category_id . '&task=edit' . JeproshopTools::getCategoryToken(); } $app->redirect($link, $message); } }
public function updateProduct() { $db = JFactory::getDBO(); $app = JFactory::getApplication(); $languages = JeproshopLanguageModelLanguage::getLanguages(false); if (!isset($this->context)) { $this->context = JeproshopContext::getContext(); } $this->clearCache(); $this->date_upd = date('Y-m-d H:i:s'); if (JeproshopTools::isLoadedObject($this, 'product_id')) { $this->removeTaxFromEcotax(); $product_type_before = $this->getType(); $this->indexed = 0; $input = JRequest::get('post'); $product_data = isset($input['information']) ? $input['information'] : $input['jform']; $existingProduct = $this; if (JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getShopContext() != JeproshopShopModelShop::CONTEXT_SHOP) { $this->setFieldsToUpdate((array) $input['multishop_check']); } if ($this->context->shop->getShopContext() == JeproshopShopModelShop::CONTEXT_ALL && !$this->isAssociatedToShop()) { $isAssociatedToShop = false; $combinations = JeproshopProductModelProduct::getProductAttributesIds($this->product_id); if ($combinations) { foreach ($combinations as $combination_id) { $combination = new JeproshopCombinationModelCombination($combination_id); $default_combination = new JeproshopCombinationModelCombination($combination_id, null, $this->default_shop_id); $combination->product_id = (int) $default_combination->product_id; $combination->location = $db->quote($default_combination->location); $combination->ean13 = $db->quote($default_combination->ean13); $combination->upc = $db->quote($default_combination->upc); $combination->quantity = (int) $default_combination->quantity; $combination->reference = $db->quote($default_combination->reference); $combination->supplier_reference = $db->quote($default_combination->supplier_reference); $combination->wholesale_price = (double) $default_combination->wholesale_price; $combination->price = (double) $default_combination->price; $combination->ecotax = (double) $default_combination->ecotax; $combination->weight = $default_combination->weight; $combination->unit_price_impact = (double) $default_combination->unit_price_impact; $combination->default_on = (int) $default_combination->default_on; $combination->available_date = $default_combination->available_date ? $db->quote($default_combination->available_date) : '0000-00-00'; $combination->save(); } } } else { $isAssociatedToShop = true; } $shop_list_ids = JeproshopShopModelShop::getCompleteListOfShopsId(); if (count($this->shop_list_id) > 0) { $shop_list_ids = $this->shop_list_id; } if (JeproshopShopModelShop::checkDefaultShopId('product') && !$this->default_shop_id) { $this->default_shop_id = min($shop_list_ids); } /*$manufacturer_id = $product_data['manufacturer_id']; $default_category_id = 1; $default_shop_id = JeproshopSettingModelSetting::getValue('default_shop'); */ //$tax_rules_group_id = $product_data['tax_rules_group_id']; $show_price = isset($input_data['show_price']) ? 1 : 0; $on_sale = isset($product_data['on_sale']) ? 1 : 0; $online_only = isset($product_data['online_only']) ? 1 : 0; $available_for_order = isset($product_data['available_for_order']) ? 1 : 0; $ean_13 = JeproshopTools::isEan13($product_data['ean13']) ? $product_data['ean13'] : ''; $upc = JeproshopTools::isUpc($product_data['upc']) ? $product_data['upc'] : ''; $reference = JeproshopTools::isReference($product_data['reference']) ? $product_data['reference'] : ''; //$product_type = $product_data['product_type']; $published = $product_data['published']; $redirect_type = $product_data['redirect_type']; /*$ecotax = $product_data['ecotax']; $unity = $product_data['unity']; $unit_price = (float)$product_data['unit_price']; $wholesale_price = (float)$product_data['wholesale_price']; */ $visibility = $product_data['visibility']; $condition = $product_data['condition']; $result = true; /** data base updating **/ $query = "UPDATE " . $db->quoteName('#__jeproshop_product') . " SET " . $db->quoteName('reference') . " = " . $db->quote($reference) . ", " . $db->quoteName('on_sale') . " = " . (int) $on_sale . ", "; $query .= $db->quoteName('online_only') . " = " . (int) $online_only . ", " . $db->quoteName('ean13') . " = " . $db->quote($ean_13) . ", " . $db->quoteName('upc') . " = " . $db->quote($upc) . ", "; $query .= $db->quoteName('published') . " = " . (int) $published . ", " . $db->quoteName('redirect_type') . "= " . $db->quote($redirect_type) . ", " . $db->quoteName('visibility') . " = " . $db->quote($visibility) . ", "; $query .= $db->quoteName('product_redirected_id') . " = " . $db->quote($product_data['product_redirected_id']) . ", " . $db->quoteName('available_for_order') . " = " . (int) $available_for_order . ", "; $query .= $db->quoteName('show_price') . " = " . (int) $show_price . ", " . $db->quoteName('condition') . " = " . $db->quote($condition) . ", " . $db->quoteName('date_upd') . " = " . $db->quote($this->date_upd); $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $this->product_id; $db->setQuery($query); $result &= $db->query(); if ($result) { // Database insertion for multishop fields related to the object if (JeproshopShopModelShop::isTableAssociated('product')) { $default_category_id = 1; /* Shop fields */ foreach ($shop_list_ids as $shop_id) { $query = "UPDATE " . $db->quoteName('#__jeproshop_product_shop') . " SET " . $db->quoteName('default_category_id') . " = " . (int) $default_category_id; $query .= ", " . $db->quoteName('online_only') . " = " . (int) $online_only; $query .= ", " . $db->quoteName('redirect_type') . " = " . $db->quote($redirect_type) . ", " . $db->quoteName('product_redirected_id') . " = " . (int) $product_data['product_redirected_id']; $query .= ", " . $db->quoteName('available_for_order') . " = " . (int) $available_for_order . ", " . $db->quoteName('condition') . " = " . $db->quote($product_data['condition']); $query .= ", " . $db->quoteName('published') . " = " . (int) $product_data['published'] . ", " . $db->quoteName('show_price') . " = " . (int) $show_price; //$query .= ", " . $db->quoteName('additional_shipping_cost') . " = " . (float)$product_data['additional_shipping_cost']; $query .= ", " . $db->quoteName('visibility') . " = " . $db->quote($product_data['visibility']) . ", " . $db->quoteName('date_upd') . " = " . $db->quote($this->date_upd); $query .= " WHERE " . $db->quoteName('product_id') . " = " . $this->product_id . " AND " . $db->quoteName('shop_id') . " = " . $shop_id; $db->setQuery($query); $result &= $db->query(); if ($result) { /* Multilingual fields */ foreach ($languages as $language) { $query = "UPDATE " . $db->quoteName('#__jeproshop_product_lang') . " SET " . $db->quoteName('description') . " = "; $query .= $db->quote($product_data['description_' . $language->lang_id]) . ", " . $db->quoteName('short_description'); $query .= " = " . $db->quote($product_data['short_description_' . $language->lang_id]) . ", " . $db->quoteName('name'); $query .= " = " . $db->quote($product_data['name_' . $language->lang_id]) . " WHERE " . $db->quoteName('product_id') . " = "; $query .= (int) $this->product_id . " AND " . $db->quoteName('shop_id'); $query .= " = " . (int) $shop_id . " AND " . $db->quoteName('lang_id') . " = " . (int) $language->lang_id; $db->setQuery($query); $result &= $db->query(); } } } } } if ($result) { // If the product doesn't exist in the current shop but exists in another shop if (JeproshopShopModelShop::getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP && $existingProduct->isAssociatedToShop($this->context->shop->shop_id)) { $outOfStock = JeproshopStockAvailableModelStockAvailable::outOfStock($existingProduct->product_id, $existingProduct->default_shop_id); $dependsOnStock = JeproshopStockAvailableModelStockAvailable::dependsOnStock($existingProduct->product_id, $existingProduct->default_shop_id); JeproshopStockAvailableModelStockAvailable::setProductOutOfStock((int) $this->product_id, $outOfStock, $this->context->shop->shop_id); JeproshopStockAvailableModelStockAvailable::setProductDependsOnStock((int) $this->product_id, $dependsOnStock, $this->context->shop->shop_id); } if (in_array($this->context->shop->getShopContext(), array(JeproshopShopModelShop::CONTEXT_SHOP, JeproshopShopModelShop::CONTEXT_ALL))) { $this->addCarriers(); $this->updateAccessories(); $this->processSuppliers(); $this->processFeatures(); $this->processProductAttribute(); $this->processProductAttribute(); $this->processPriceAddition(); $this->processSpecificPricePriorities(); $this->processCustomizationConfiguration(); $this->processAttachments(); $this->updatePackItems(); // Disallow advanced stock management if the product become a pack if ($product_type_before == JeproshopProductModelProduct::SIMPLE_PRODUCT && $this->getType() == JeproshopProductModelProduct::PACKAGE_PRODUCT) { JeproshopStockAvailableModelStockAvailable::setProductDependsOnStock($this->product_id, false); } $this->updateDownloadProduct(1); $this->updateTags(JeproshopLanguageModelLanguage::getLanguages(false)); if ($this->isProductFieldUpdated('category_box') && !$this->updateCategories($product_data['category_box'])) { JError::raiseError(500, JText::_('COM_JEPROSHOP_AN_ERROR_OCCURRED_WHILE_LINKING_THE_PRODUCT_TO_CATEGORIES_MESSAGE')); $this->context->controller->has_errors = true; } //TODO correct category update and check php $_POST limit to handle the form } $this->processWarehouses(); $category_link = $app->input->get('category_id') ? '&category_id=' . $app->input->get('category_id') : ''; if (!$this->context->controller->has_errors) { if (in_array($this->visibility, array('both', 'search')) && JeproshopSettingModelSetting::getValue('search_indexation')) { JeproshopSearch::indexation(false, $this->product_id); } //save and preview $message = JText::_('COM_JEPROSHOP_UPDATE_SUCCESSFULLY_MESSAGE'); if ($app->input->get('task') == 'save_preview') { $link = $this->getPreviewUrl(); } else { if ($app->input->get('task') == 'edit') { $link = JRoute::_('index.php?option=com_jeproshop&view=product&task=edit&product_id=' . $this->product_id . $category_link . JeproshopTools::getProductToken()); } else { $link = JRoute::_('index.php?option=com_jeproshop&view=product&' . $category_link); $message = JText::_('COM_JEPROSHOP_UPDATE_SUCCESSFULLY_MESSAGE'); } } $app->redirect($link, $message); } else { $app->input->set('task', 'edit'); $app->redirect('index.php?option=com_jeproshop&view=product&task=edit&product_id=' . $this->product_id . $category_link . JeproshopTools::getProductToken()); } } else { if (!$isAssociatedToShop && $combinations) { foreach ($combinations as $combination_id) { $combination = new JeproshopCombinationModelCombination((int) $combination_id); $combination->delete(); } JError::raiseError(500, JText::_('COM_JEPROSHOP_AN_ERROR_OCCURRED_WHILE_UPDATING_A_PRODUCT_MESSAGE')); } } $this->setGroupReduction(); if ($this->getType() == JeproshopProductModelProduct::VIRTUAL_PRODUCT && $this->published && !JeproshopSettingModelSetting::getValue('virtual_product_feature_active')) { JeproshopSettingModelSetting::updateValue('virtual_product_feature_active', '1'); } return true; } }