示例#1
0
 /**
  * Add an sql join in query between a table and its associated table in multi-shop
  *
  * @param string $table Table name (E.g. product, module, etc.
  * @param bool $inner_join
  * @param null $on
  * @param null $force_not_default
  * @return string
  */
 public static function addSqlAssociation($table, $inner_join = true, $on = null, $force_not_default = null)
 {
     $db = JFactory::getDBO();
     $table_alias = $table . '_shop';
     if (strpos($table, '.') !== false) {
         list($table_alias, $table) = explode('.', $table);
     }
     if ($table == 'group') {
         $output_alias = 'grp';
     } else {
         $output_alias = $table;
     }
     $associated_table = JeproshopShopModelShop::getAssociatedTable($table);
     if ($associated_table === false || $associated_table['type'] != 'shop') {
         return;
     }
     $query = ($inner_join ? " INNER " : " LEFT ") . "JOIN " . $db->quoteName('#__jeproshop_' . $table . '_shop') . " AS ";
     $query .= $table_alias . " ON( " . $table_alias . "." . $table . "_id = " . $output_alias . "." . $table . "_id";
     if ((int) self::$context_shop_id) {
         $query .= " AND " . $table_alias . ".shop_id = " . (int) self::$context_shop_id;
     } elseif (JeproshopShopModelShop::checkDefaultShopId($table) && !$force_not_default) {
         $query .= " AND " . $table_alias . ".shop_id = " . $output_alias . ".default_shop_id";
     } else {
         $query .= " AND " . $table_alias . ".shop_id IN (" . implode(', ', JeproshopShopModelShop::getContextListShopIds()) . ")";
     }
     $query .= ($on ? " AND " . $on : "") . ")";
     return $query;
 }
示例#2
0
 /**
  * @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;
 }
示例#3
0
 /**
  * @todo Remove existing module condition
  * @param int $product_id
  * @return array
  */
 public static function getAttributesInformationsByProduct($product_id)
 {
     $db = JFactory::getDBO();
     $context = JeproshopContext::getContext();
     //todo if block_layered module is installed we check if user has set custom attribute name
     if ($context->controller->isModuleInstalled('mod_block_layered') && $context->controller->isModuleEnabled('mod_block_layered')) {
         $query = " SELECT DISTINCT layered_attribute." . $db->quoteName('attribute_id') . ", layered_attribute." . $db->quoteName('url_name') . " AS attribute_url FROM ";
         $query .= $db->quoteName('#__jeproshop_attribute') . " AS attribute LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination') . " AS product_attribute_combination ";
         $query .= " ON (attribute." . $db->quoteName('attribute_id') . " = product_attribute_combination." . $db->quoteName('attribute_id') . " ) LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute');
         $query .= " AS product_attribute ON (product_attribute_combination." . $db->quoteName('product_attribute_id') . " = product_attribute." . $db->quoteName('product_attribute_id') . ") ";
         $query .= JeproshopShopModelShop::addSqlAssociation('product_attribute') . " LEFT JOIN " . $db->quoteName('#__jeproshop_layered_indexable_attribute_lang_value') . " AS layered_attribute ON (layered_attribute.";
         $query .= $db->quoteName('attribute_id') . " = attribute." . $db->quoteName('attribute_id') . " AND layered_attribute." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id;
         $query .= ") WHERE layered_attribute." . $db->quoteName('url_name') . " IS NOT NULL AND layered_attribute." . $db->quoteName('url_name') . " != '' AND product_attribute." . $db->quoteName('product_id') . " = " . (int) $product_id;
         $db->setQuery($query);
         $nb_custom_values = $db->loadObjectList();
         if (!empty($nb_custom_values)) {
             $tab_attribute_id = array();
             foreach ($nb_custom_values as $attribute) {
                 $tab_attribute_id[] = $attribute->attribute_id;
                 $query = "SELECT layered_attribute_group." . $db->quoteName('attribute_group_id') . ", layered_attribute_group." . $db->quoteName('url_name') . " AS ";
                 $query .= " layered_attribute_url FROM " . $db->quoteName('#__jeproshop_layered_indexable_attribute_group_lang_value') . " AS layered_attribute_group ";
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_attribute') . " AS attribute ON (attribute." . $db->quoteName('attribute_group_id') . " = layered_attribute_group.";
                 $query .= $db->quoteName('attribute_group_id') . ") WHERE attribute." . $db->quoteName('attribute_id') . " = " . (int) $attribute->attribute_id . " AND ";
                 $query .= "layered_attribute_group." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id . " AND layered_attribute_group.";
                 $query .= $db->quoteName('url_name') . " IS NOT NULL AND layered_attribute_group." . $db->quoteName('url_name') . " != '' ";
                 $db->setQuery($query);
                 $group = $db->loadObjectList();
                 if (empty($group)) {
                     $query = "SELECT attribute_group_lang." . $db->quoteName('attribute_group_id') . ", attribute_group_lang." . $db->quoteName('name') . " AS group_name";
                     $query .= "\tFROM " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang LEFT JOIN " . $db->quoteName('#__jeproshop_attribute');
                     $query .= " AS attribute ON (attribute." . $db->quoteteName('attribute_group_id') . " = attribute_group_lang." . $db->quoteName('attribute_group_id');
                     $query .= ") WHERE attribute." . $db->quoteName('attribute_id') . " = " . (int) $attribute->attribute_id . " AND attribute_group_lang." . $db->quoteName('lang_id');
                     $query .= " = " . (int) JeproshopContext::getContext()->language->lang_id . " AND attribute_group_lang." . $db->quoteName('name') . " IS NOT NULL";
                     $db->setQuery($query);
                     $group = $db->loadObjectList();
                 }
                 $result[] = array_merge($attribute, $group[0]);
             }
             $query = "SELECT DISTINCT attribute." . $db->quoteName('attribute_id') . ", attribute." . $db->quoteName('attribute_group_id') . ", attribute_lang.";
             $query .= $db->quoteName('name') . " AS attribute, attribute_group_lang." . $db->quoteName('name') . " AS group_name FROM " . $db->quoteName('#__jeproshop_attribute');
             $query .= " AS attribute LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_lang') . " AS attribute_lang ON (attribute." . $db->quoteName('attribute_id');
             $query .= " = attribute_lang." . $db->quoteName('attribute_id') . " AND attribute_lang." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id;
             $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON (attribute." . $db->quoteName('attribute_group_id');
             $query .= " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND attribute_group_lang." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id;
             $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination') . " AS product_attribute_combination ON (attribute." . $db->quoteName('attribute_id') . " = ";
             $query .= "product_attribute_combination." . $db->quoteName('attribute_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON (";
             $query .= "product_attribute_combination." . $db->quoteName('product_attribute_id') . " = product_attribute." . $db->quoteName('product_attribute_id') . ") ";
             $query .= JeproshopShopModelShop::addSqlAssociation('product_attribute') . JeproshopShopModelShop::addSqlAssociation('attribute', 'pac') . "\n\t\t\t\tWHERE product_attribute" . $db->quoteName('product_id') . " = " . (int) $product_id . "\tAND attribute." . $db->quoteName('attribute_id') . " NOT IN(" . implode(', ', $tab_attribute_id) . ")";
             $db->setQuery($query);
             $values_not_custom = $db->loadObjectList();
             $result = array_merge($values_not_custom, $result);
         } else {
             $query = "SELECT DISTINCT attribute." . $db->quoteName('attribute_id') . ", attribute." . $db->quoteName('attribute_group_id') . ", attribute_lang." . $db->quoteName('name') . " AS attribute_name,";
             $query .= " attribute_group_lang." . $db->quoteName('name') . " AS group_name FROM " . $db->quoteName('#__jeproshop_attribute') . " AS attribute LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_lang');
             $query .= " AS attribute_lang ON (attribute." . $db->quoteName('attribute_id') . " = attribute_lang." . $db->quoteName('attribute_id') . " AND attribute_lang." . $db->quoteName('lang_id') . " = ";
             $query .= (int) JeproshopContext::getContext()->language->lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON (attribute." . $db->quoteName('attribute_group_id');
             $query .= " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND attribute_group_lang." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id;
             $query .= ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination') . " AS product_attribute_combination ON (attribute." . $db->quoteName('attribute_id') . " = product_attribute_combination.";
             $query .= $db->quoteName('attribute_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON (product_attribute_combination." . $db->quoteName('product_attribute_id');
             $query .= " = product_attribute." . $db->quoteName('product_attribute_id') . ") " . JeproshopShopModelShop::addSqlAssociation('product_attribute') . " " . JeproshopShopModelShop::addSqlAssociation('attribute', 'product_attribute_combination') . " WHERE product_attribute." . $db->quoteName('product_id') . " = " . (int) $product_id;
             $db->setQuery($query);
             $result = $db->loadObjectList();
         }
     } else {
         $query = "SELECT DISTINCT attribute." . $db->quoteName('attribute_id') . ", attribute." . $db->quoteName('attribute_group_id') . ", attribute_lang." . $db->quoteName('name');
         $query .= " AS attribute_name, attribute_group_lang." . $db->quoteName('name') . " AS group_name FROM" . $db->quoteName('#__jeproshop_attribute') . " AS attribute LEFT JOIN ";
         $query .= $db->quoteName('#__jeproshop_attribute_lang') . " AS attribute_lang ON (attribute." . $db->quoteName('attribute_id') . " = attribute_lang." . $db->quoteName('attribute_id');
         $query .= " AND attribute_lang." . $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang');
         $query .= " AS attribute_group_lang ON (attribute." . $db->quoteName('attribute_group_id') . " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND attribute_group_lang.";
         $query .= $db->quoteName('lang_id') . " = " . (int) JeproshopContext::getContext()->language->lang_id . ") LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute_combination');
         $query .= " AS  product_attribute_combination ON (attribute." . $db->quoteName('attribute_id') . " = product_attribute_combination." . $db->quoteName('attribute_id') . ") LEFT JOIN ";
         $query .= $db->quoteName('#__jeproshop_product_attribute') . " AS product_attribute ON (product_attribute_combination." . $db->quoteName('product_attribute_id') . " = product_attribute.";
         $query .= $db->quoteName('product_attribute_id') . ") " . JeproshopShopModelShop::addSqlAssociation('product_attribute') . " LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_shop');
         $query .= " AS product_attribute_combination_shop ON(product_attribute_combination_shop." . $db->quoteName('attribute_id') . " = product_attribute_combination." . $db->quoteName('attribute_id');
         if (JeproshopShopModelShop::$context_shop_id) {
             $query .= " AND product_attribute_combination_shop." . $db->quoteName('shop_id') . " = " . JeproshopShopModelShop::$context_shop_id;
         } elseif (JeproshopShopModelShop::checkDefaultShopId()) {
             $query .= " AND product_attribute_combination_shop." . $db->quoteName('shop_id') . " IN( " . implode(', ', JeproshopShopModelShop::getContextShopListId()) . ") ";
         }
         $query .= ") WHERE product_attribute." . $db->quoteName('product_id') . " = " . (int) $product_id;
         $db->setQuery($query);
         $result = $db->loadObjectList();
     }
     return $result;
 }
示例#4
0
 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);
     }
 }
示例#5
0
 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;
     }
 }
示例#6
0
 public function save()
 {
     $db = JFactory::getDBO();
     $input = JRequest::get('post');
     $inputData = $input['jform'];
     $query = "INSERT INTO " . $db->quoteName('#__jeproshop_tax_rules_group') . " ( " . $db->quoteName('name') . ", " . $db->quoteName('published') . ") VALUES(" . $db->quote($inputData['name']) . ", " . (int) $inputData['published'] . ")";
     $db->setQuery($query);
     if ($db->query()) {
         $result = true;
         $taxRuleGroupId = $db->insertid();
         $shopListIds = JeproshopShopModelShop::getContextListShopIds();
         if (count($this->shop_list_ids) > 0) {
             $shopListIds = $this->shop_list_ids;
         }
         if (JeproshopShopModelShop::checkDefaultShopId('tax_rules_group')) {
             $this->default_shop_id = min($shopListIds);
         }
         foreach ($shopListIds as $shop_id) {
             $query = "INSERT INTO " . $db->quoteName('#__jeproshop_tax_rules_group_shop') . " ( " . $db->quoteName('tax_rules_group_id') . ", " . $db->quoteName('shop_id') . ") VALUES ( " . (int) $taxRuleGroupId . ", " . (int) $shop_id . ")";
             $db->setQuery($query);
             $result &= $db->query();
         }
         $link = 'index.php?option=com_jeproshop&view=tax&task=groups';
         if (!$result) {
             $message = JText::_('COM_JEPROSHOP_');
         } else {
         }
     }
 }