Ejemplo n.º 1
0
 /**
  * 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();
 }
Ejemplo n.º 2
0
 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');
     }
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 protected static function getProductsToIndex($total_languages, $product_id = false, $limit = 50, $weight_array = array())
 {
     // Adjust the limit to get only "whole" products, in every languages (and at least one)
     $max_possibilities = $total_languages * count(JeproshopShopModelShop::getShops(true));
     $limit = max($max_possibilities, floor($limit / $max_possibilities) * $max_possibilities);
     $db = JFactory::getDBO();
     $query = "SELECT product.product_id, product_lang.lang_id, product_lang.shop_id, language.sef";
     if (is_array($weight_array)) {
         foreach ($weight_array as $key => $weight) {
             if ((int) $weight) {
                 switch ($key) {
                     case 'product_name':
                         $query .= ", product_lang.name product_name";
                         break;
                     case 'reference':
                         $query .= ", product.reference, product_attribute.reference AS product_attribute_reference";
                         break;
                     case 'ean13':
                         $query .= ", product.ean13";
                         break;
                     case 'upc':
                         $query .= ", product.upc";
                         break;
                     case 'short_description':
                         $query .= ", product_lang.short_description";
                         break;
                     case 'description':
                         $query .= ", product_lang.description";
                         break;
                     case 'category_name':
                         $query .= ", category_lang.name AS category_name";
                         break;
                     case 'manufacturer_name':
                         $query .= ", manufacturer.name AS manufacturer_name";
                         break;
                 }
             }
         }
     }
     $query .= " FROM " . $db->quoteName('#__jeproshop_product') . " AS product LEFT JOIN " . $db->quoteName('#__jeproshop_product_attribute');
     $query .= " AS product_attribute ON product_attribute.product_id = product.product_id LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_product_lang') . " AS product_lang ON product.product_id = product_lang.product_id ";
     $query .= JeproshopShopModelShop::addSqlAssociation('product') . "\tLEFT JOIN " . $db->quoteName('#__jeproshop_category_lang') . " AS ";
     $query .= " category_lang ON (category_lang.category_id = product_shop.default_category_id AND product_lang.lang_id = category_lang.";
     $query .= "lang_id AND category_lang.shop_id = product_shop.shop_id ) LEFT JOIN " . $db->quoteName('#__jeproshop_manufacturer');
     $query .= " AS manufacturer ON manufacturer.manufacturer_id = product.manufacturer_id LEFT JOIN " . $db->quoteName('#__languages');
     $query .= " AS language ON language.lang_id = product_lang.lang_id WHERE product_shop.indexed = 0 AND product_shop.visibility IN";
     $query .= " (\"both\", \"search\") " . ($product_id ? "AND product.product_id = " . (int) $product_id : "") . " AND product_shop.";
     $query .= $db->quoteName('published') . " = 1 LIMIT " . (int) $limit;
     $db->setQuery($query);
     return $db->loadObjectList();
 }
Ejemplo n.º 5
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);
     }
 }
Ejemplo n.º 6
0
 public static function addModuleRestrictions(array $shops = array(), array $countries = array(), array $modules = array())
 {
     if (!count($shops)) {
         $shops = JeproshopShopModelShop::getShops(true, null, true);
     }
     if (!count($countries)) {
         $countries = JeproshopCountryModelCountry::getCountries((int) JeproshopContext::getContext()->cookie->lang_id);
     }
     if (!count($modules)) {
         $modules = Module::getPaymentModules();
     }
     $sql = false;
     foreach ($shops as $id_shop) {
         foreach ($countries as $country) {
             foreach ($modules as $module) {
                 $sql .= '(' . (int) $module['id_module'] . ', ' . (int) $id_shop . ', ' . (int) $country['id_country'] . '),';
             }
         }
     }
     if ($sql) {
         $sql = 'INSERT IGNORE INTO `' . _DB_PREFIX_ . 'module_country` (`id_module`, `id_shop`, `id_country`) VALUES ' . rtrim($sql, ',');
         return Db::getInstance()->execute($sql);
     } else {
         return true;
     }
 }
Ejemplo n.º 7
0
 private function initPriceForm()
 {
     if ($this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     if ($this->product->product_id) {
         $shops = JeproshopShopModelShop::getShops();
         $countries = JeproshopCountryModelCountry::getStaticCountries($this->context->language->lang_id);
         $groups = JeproshopGroupModelGroup::getStaticGroups($this->context->language->lang_id);
         $currencies = JeproshopCurrencyModelCurrency::getStaticCurrencies();
         $attributes = $this->product->getAttributesGroups((int) $this->context->language->lang_id);
         $combinations = array();
         if (count($attributes)) {
             foreach ($attributes as $attribute) {
                 $combinations[$attribute->product_attribute_id] = new JObject();
                 $combinations[$attribute->product_attribute_id]->product_attribute_id = $attribute->product_attribute_id;
                 if (!isset($combinations[$attribute->product_attribute_id]->attributes)) {
                     $combinations[$attribute->product_attribute_id]->attributes = '';
                 }
                 if (isset($combinations[$attribute->product_attribute_id])) {
                     $combinations[$attribute->product_attribute_id]->attributes .= $attribute->attribute_name . ' - ';
                     $combinations[$attribute->product_attribute_id]->price = JeproshopTools::displayPrice(JeproshopTools::convertPrice(JeproshopProductModelProduct::getStaticPrice((int) $this->product->product_id, false, $attribute->product_attribute_id), $this->context->currency), $this->context->currency);
                 }
             }
             foreach ($combinations as $combination) {
                 if (isset($combination->attributes)) {
                     $combination->attributes = rtrim($combination->attributes, ' - ');
                 }
             }
         }
         $specificPriceModificationForm = $this->displaySpecificPriceModificationForm($this->context->currency, $shops, $currencies, $countries, $groups);
         $this->assignRef('specific_price_modification_form', $specificPriceModificationForm);
         $this->assignRef('ecotax_tax_excluded', $this->product->ecotax);
         //$this->applyTaxToEcotax();
         $this->assignRef('shops', $shops);
         /*$admin_one_shop = count($this->context->employee->getAssociatedShops()) == 1;
           $this->assignRef('admin_one_shop', $admin_one_shop); */
         $this->assignRef('currencies', $currencies);
         $this->assignRef('currency', $this->context->currency);
         $this->assignRef('countries', $countries);
         $this->assignRef('groups', $groups);
         $this->assignRef('combinations', $combinations);
         $multiShop = JeproshopShopModelShop::isFeaturePublished();
         $this->assignRef('multi_shop', $multiShop);
     } else {
         JError::raiseWarnig(JText::_('COM_JEPROSHOP_YOU_MUST_SAVE_THIS_PRODUCT_BEFORE_ADDING_SPECIFIC_PRICING_MESSAGE'));
         $this->product->tax_rules_group_id = JeproshopProductModelProduct::getTaxRulesMostUsedGroupId();
         $this->assignRef('ecotax_tax_excluded', 0);
     }
     $use_tax = JeproshopSettingModelSetting::getValue('use_tax');
     $this->assignRef('use_tax', $use_tax);
     $use_ecotax = JeproshopSettingModelSetting::getValue('use_eco_tax');
     $this->assignRef('use_ecotax', $use_ecotax);
     $tax_rules_groups = JeproshopTaxRulesGroupModelTaxRulesGroup::getTaxRulesGroups(true);
     $this->assignRef('tax_rules_groups', $tax_rules_groups);
     $taxesRatesByGroup = JeproshopTaxRulesGroupModelTaxRulesGroup::getAssociatedTaxRatesByCountryId($this->context->country->country_id);
     $this->assignRef('taxesRatesByGroup', $taxesRatesByGroup);
     $ecotaxTaxRate = JeproshopTaxModelTax::getProductEcotaxRate();
     $this->assignRef('ecotaxTaxRate', $ecotaxTaxRate);
     $tax_exclude_tax_option = JeproshopTaxModelTax::taxExcludedOption();
     $this->assignRef('tax_exclude_tax_option', $tax_exclude_tax_option);
     $this->product->price = JeproshopTools::convertPrice($this->product->price, $this->context->currency, true, $this->context);
     if ($this->product->unit_price_ratio != 0) {
         $unit_price = JeproshopTools::roundPrice($this->product->price / $this->product->unit_price_ratio, 2);
     } else {
         $unit_price = 0;
     }
     $this->assignRef('unit_price', $unit_price);
 }