Example #1
0
 public function __construct($address_id = NULL, $lang_id = NULL)
 {
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== FALSE ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($address_id) {
         //Load address from database if address id is provided
         $cache_id = 'jeproshop_address_model_' . $address_id . '_' . $lang_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $db = JFactory::getDBO();
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_address') . " AS address ";
             $query .= " WHERE address.address_id = " . (int) $address_id;
             $db->setQuery($query);
             $address_data = $db->loadObject();
             if ($address_data) {
                 JeproshopCache::store($cache_id, $address_data);
             }
         } else {
             $address_data = JeproshopCache::retrieve($cache_id);
         }
         if ($address_data) {
             $address_data->address_id = $address_id;
             foreach ($address_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     if ($this->address_id) {
         $this->country = JeproshopCountryModelCountry::getNameById($lang_id, $this->country_id);
     }
 }
Example #2
0
 public function renderEditForm($tpl = NULL)
 {
     $app = JFactory::getApplication();
     if (!isset($this->context)) {
         $this->context = JeproshopContext::getContext();
     }
     $this->helper = new JeproshopHelper();
     $languages = JeproshopLanguageModelLanguage::getLanguages();
     $this->assignRef('languages', $languages);
     $currencies = JeproshopCurrencyModelCurrency::getStaticCurrencies();
     $this->assignRef('currencies', $currencies);
     $zones = JeproshopZoneModelZone::getZones();
     $this->assignRef('zones', $zones);
     $addressLayout = JeproshopAddressFormatModelAddressFormat::getAddressCountryFormat($this->country->country_id);
     if ($value = $app->input->get('address_layout')) {
         $addressLayout = $value;
     }
     $default_layout = '';
     $default_layout_tab = array(array('firstname', 'lastname'), array('company'), array('vat_number'), array('address1'), array('address2'), array('postcode', 'city'), array('Country:name'), array('phone'), array('phone_mobile'));
     foreach ($default_layout_tab as $line) {
         $default_layout .= implode(' ', $line) . "\r\n";
     }
     $this->assignRef('address_layout', $addressLayout);
     $encodingAddressLayout = urlencode($addressLayout);
     $this->assignRef('encoding_address_layout', $encodingAddressLayout);
     $encodingDefaultLayout = urlencode($default_layout);
     $this->assignRef('encoding_default_layout', $encodingDefaultLayout);
     $displayValidFields = $this->displayValidFields();
     $this->assignRef('display_valid_fields', $displayValidFields);
     $this->addToolBar();
     $this->sideBar = JHtmlSidebar::render();
     parent::display($tpl);
 }
Example #3
0
 public function add()
 {
     $db = JFactory::getDBO();
     $view = JFactory::getApplication()->input->get('view');
     $languages = JeproshopLanguageModelLanguage::getLanguages();
     $data = JRequest::get('post');
     $input_data = $data['jform'];
     $result = true;
     foreach ($languages as $language) {
         if ($view == 'tag') {
             $name = $input_data['name_' . $language->lang_id];
         } else {
             $name = $input_data['tag_' . $language->lang_id];
         }
         $query = "INSERT INTO " . $db->quoteName('#__jeproshop_tag') . "(" . $db->quoteName('lang_id') . ", " . $db->quoteName('name') . ") VALUES (";
         $query .= (int) $language->lang_id . ", " . $db->quote($name) . ")";
         $db->setQuery($query);
         $result &= $db->query();
     }
     if (!$result) {
         return false;
     } else {
         if (isset($input_data['products'])) {
             return $this->setProducts($input_data['products']);
         }
     }
     return true;
 }
Example #4
0
 public function __construct($country_id = null, $lang_id = null, $shop_id = NULL)
 {
     $db = JFactory::getDBO();
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($shop_id && $this->isMultiShop()) {
         $this->shop_id = (int) $shop_id;
         $this->get_shop_from_context = FALSE;
     }
     if ($this->isMultiShop() && !$this->shop_id) {
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     if ($country_id) {
         $cache_id = 'jeproshop_country_model_' . (int) $country_id . '_' . (int) $lang_id . '_' . (int) $shop_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_country') . " AS country ";
             //Get language data
             if ($lang_id) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_country_lang') . " AS country_lang ON (country_lang." . $db->quoteName('country_id') . " = country." . $db->quoteName('country_id') . " AND country_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")";
             }
             if (JeproshopShopModelShop::isTableAssociated('country')) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_country_shop') . " AS country_shop ON (country_shop." . $db->quoteName('country_id') . " = country." . $db->quoteName('country_id') . " AND country_shop." . $db->quoteName('shop_id') . " = " . (int) $shop_id . ") ";
             }
             $db->setQuery($query);
             $country_data = $db->loadObject();
             if ($country_data) {
                 if (!$lang_id) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_country_lang') . " WHERE " . $db->quoteName('country_id') . " = " . (int) $country_id;
                     $db->setQuery($query);
                     $country_lang_data = $db->loadObjectList();
                     if ($country_lang_data) {
                         foreach ($country_lang_data as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'country_id') {
                                     if (!isset($country_data->{$key}) || !is_array($country_data->{$key})) {
                                         $country_data->{$key} = array();
                                     }
                                     $country_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $country_data);
             }
         } else {
             $country_data = JeproshopCache::retrieve($cache_id);
         }
         if ($country_data) {
             $country_data->country_id = (int) $country_id;
             foreach ($country_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
 }
Example #5
0
 public function __construct($manufacturer_id = null, $lang_id = null)
 {
     $db = JFactory::getDBO();
     if ($lang_id !== null) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== false ? $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($manufacturer_id) {
         // Load object from database if object id is present
         $cache_id = 'jeproshop_manufacturer_model_' . (int) $manufacturer_id . '_' . (int) $lang_id;
         $db = JFactory::getDBO();
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_manufacturer') . " AS manufacturer ";
             // Get lang informations
             if ($lang_id) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_manufacturer_lang') . " AS manufacturer_lang ON (manufacturer." . $db->quoteName('manufacturer_id');
                 $query .= " = manufacturer_lang." . $db->quoteName('manufacturer_id') . " AND manufacturer_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")";
             }
             $query .= " WHERE manufacturer." . $db->quoteName('manufacturer_id') . " = " . (int) $manufacturer_id;
             // Get shop informations
             /*if (Shop::isTableAssociated($this->def['table']))
               $sql->leftJoin($this->def['table'].'_shop', 'c', 'a.'.$this->def['primary'].' = c.'.$this->def['primary'].' AND c.id_shop = '.(int)$this->id_shop); */
             $db->setQuery($query);
             $manufacturer_data = $db->loadObject();
             if ($manufacturer_data) {
                 if (!$lang_id) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_manufacturer_lang') . " WHERE " . $db->quoteName('manufacturer_id') . " = " . (int) $manufacturer_id;
                     $db->setQuery($query);
                     $manufacturer_data_lang = $db->loadObjectList();
                     if ($manufacturer_data_lang) {
                         foreach ($manufacturer_data_lang as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'manufacturer_id') {
                                     if (!isset($manufacturer_data->{$key}) || !is_array($manufacturer_data->{$key})) {
                                         $manufacturer_data->{$key} = array();
                                     }
                                     $manufacturer_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $manufacturer_data);
             }
         } else {
             $manufacturer_data = JeproshopCache::retrieve($cache_id);
         }
         if ($manufacturer_data) {
             //$this->id = (int)$id;
             foreach ($manufacturer_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     $this->link_rewrite = JeproshopTools::str2url($this->name);
 }
Example #6
0
 public function __construct($order_id = null, $lang_id = null)
 {
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== FALSE ? (int) $lang_id : (int) JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($order_id) {
         $cache_id = 'jeproshop_order_model_' . $order_id . '_' . $lang_id . ($this->shop_id ? '_' . $this->shop_id : '');
         if (!JeproshopCache::isStored($cache_id)) {
             $db = JFactory::getDBO();
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_orders') . " AS ord ";
             $where = "";
             /** get language information **/
             if ($lang_id) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_order_lang') . " AS order_lang ";
                 $query .= " ON (ord.order_id = order_lang.order_id AND order_lang.lang_id = " . (int) $lang_id . ") ";
                 if ($this->shop_id && !empty($this->multiLangShop)) {
                     $where = " AND order_lang.shop_id = " . $this->shop_id;
                 }
             }
             /** Get shop informations **/
             if (JeproshopShopModelShop::isTableAssociated('order')) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_order_shop') . " AS order_shop ON (";
                 $query .= "ord.order_id = order_shop.order_id AND order_shop.shop_id = " . (int) $this->shop_id . ")";
             }
             $query .= " WHERE ord.order_id = " . (int) $order_id . $where;
             $db->setQuery($query);
             $order_data = $db->loadObject();
             if ($order_data) {
                 JeproshopCache::store($cache_id, $order_data);
             }
         } else {
             $order_data = JeproshopCache::retrieve($cache_id);
         }
         if ($order_data) {
             $order_data->order_id = $order_id;
             foreach ($order_data as $key => $value) {
                 if (property_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     $this->_taxCalculationMethod = JeproshopGroupModelGroup::getDefaultPriceDisplayMethod();
 }
Example #7
0
 public function __construct($cart_id = null, $lang_id = null)
 {
     $db = JFactory::getDBO();
     if (!is_null($lang_id)) {
         $this->lang_id = (int) (JeproshopLanguageModelLanguage::getLanguage($lang_id) !== false) ? $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($cart_id) {
         //Load object from database if object
         $cache_id = 'jeproshop_cart_model_cart_' . $cart_id . '_' . $lang_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_cart') . " AS cart WHERE " . $db->quoteName('cart_id') . " = " . (int) $lang_id;
             $db->setQuery($query);
             $cartData = $db->loadObject();
             if ($cartData) {
                 JeproshopCache::store($cache_id, $cartData);
             }
         } else {
             $cartData = JeproshopCache::retrieve($cache_id);
         }
         if ($cartData) {
             $this->cart_id = (int) $cart_id;
             foreach ($cartData as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
         print_r($cartData);
     }
     if ($this->customer_id) {
         if (isset(JeproshopContext::getContext()->customer) && JeproshopContext::getContext()->customer->customer_id == $this->customer_id) {
             $customer = JeproshopContext::getContext()->customer;
         } else {
             $customer = new JeproshopCustomerModelCustomer((int) $this->customer_id);
         }
         if ((!$this->secure_key || $this->secure_key == '-1') && $customer->secure_key) {
             $this->secure_key = $customer->secure_key;
             $this->save();
         }
     }
     $this->_taxCalculationMethod = JeproshopGroupModelGroup::getPriceDisplayMethod(JeproshopGroupModelGroup::getCurrent()->group_id);
 }
Example #8
0
 /**
  * Change language in cookie while clicking on a flag
  *
  * @param null $cookie
  * @return string iso code
  */
 public static function setCookieLanguage($cookie = null)
 {
     if (!$cookie) {
         $cookie = JeproshopContext::getContext()->cookie;
     }
     /* If language does not exist or is disabled, erase it */
     if ($cookie->lang_id) {
         $lang = new JeproshopLanguageModelLanguage((int) $cookie->lang_id);
         if (!JeproshopTools::isLoadedObject($lang, 'lang_id') || !$lang->published || !$lang->isAssociatedToShop()) {
             $cookie->lang_id = null;
         }
     }
     /* Automatically detect language if not already defined, detect_language is set in Cookie::update **/
     if ((!$cookie->lang_id || isset($cookie->detect_language)) && isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         $array = explode(',', strtolower($_SERVER['HTTP_ACCEPT_LANGUAGE']));
         $string = $array[0];
         if (JeproshopTools::isLanguageCode($string)) {
             $lang = JeproshopLanguageModelLanguage::getLanguageByIETFCode($string);
             if (JeproshopTools::isLoadedObject($lang, 'lang_id') && $lang->published && $lang->isAssociatedToShop()) {
                 JeproshopContext::getContext()->language = $lang;
                 $cookie->lang_id = (int) $lang->lang_id;
             }
         }
     }
     if (isset($cookie->detect_language)) {
         unset($cookie->detect_language);
     }
     /* If language file not present, you must use default language file **/
     if (!$cookie->lang_id || !JeproshopTools::isUnsignedInt($cookie->lang_id)) {
         $cookie->lang_id = (int) JeproshopSettingModelSetting::getValue('default_lang');
     }
     $iso = JeproshopLanguageModelLanguage::getIsoById((int) $cookie->lang_id);
     //@include_once(_PS_THEME_DIR_.'lang/'.$iso.'.php');
     return $iso;
 }
Example #9
0
 public function __construct($manufacturer_id = null, $lang_id = null)
 {
     parent::__construct();
     $db = JFactory::getDBO();
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($manufacturer_id) {
         $cache_id = 'jeproshop_manufacturer_model_' . $manufacturer_id . '_' . $lang_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_manufacturer') . " AS j_manufacturer ";
             $where = "";
             /** get language information **/
             if ($lang_id) {
                 $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_manufacturer_lang') . " AS manufacturer_lang ";
                 $query .= "ON (j_manufacturer.manufacturer_id = manufacturer_lang.manufacturer_id AND manufacturer_lang.lang_id = " . (int) $lang_id . ") ";
                 /* if($this->shop_id && !(empty($this->multiLangShop))){
                        $where = " AND manufacturer_lang.shop_id = " . $this->shop_id;
                    }*/
             }
             /** Get shop informations ** /
                 if(JeproshopShopModelShop::isTableAssociated('manufacturer')){
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_manufacturer_shop') . " AS manufacturer_shop ON (";
                 $query .= "j_manufacturer.manufacturer_id = manufacturer_shop.manufacturer_id AND manufacturer_shop.shop_id = " . (int)  $this->shop_id . ")";
                 }*/
             $query .= " WHERE j_manufacturer.manufacturer_id = " . (int) $manufacturer_id . $where;
             $db->setQuery($query);
             $manufacturer_data = $db->loadObject();
             if ($manufacturer_data) {
                 if (!$lang_id && isset($this->multiLang) && $this->multiLang) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_manufacturer_lang');
                     $query .= " WHERE manufacturer_id = " . (int) $manufacturer_id;
                     $db->setQuery($query);
                     $manufacturer_lang_data = $db->loadObjectList();
                     if ($manufacturer_lang_data) {
                         foreach ($manufacturer_lang_data as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'manufacturer_id') {
                                     if (!isset($manufacturer_data->{$key}) || !is_array($manufacturer_data->{$key})) {
                                         $manufacturer_data->{$key} = array();
                                     }
                                     $manufacturer_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $manufacturer_data);
             }
         } else {
             $manufacturer_data = JeproshopCache::retrieve($cache_id);
         }
         if ($manufacturer_data) {
             $manufacturer_data->manufacturer_id = $manufacturer_id;
             foreach ($manufacturer_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     $this->link_rewrite = $this->getLink();
     $this->image_dir = COM_JEPROSHOP_MANUFACTURER_IMAGE_DIRECTORY;
 }
Example #10
0
 public function __construct($carrier_id = null, $lang_id = null)
 {
     $db = JFactory::getDBO();
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($carrier_id) {
         $cache_id = 'jeproshop_carrier_model_' . $carrier_id . '_' . $lang_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_carrier') . " AS carrier ";
             $where = "";
             /** get language information **/
             if ($lang_id) {
                 $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_carrier_lang') . " AS carrier_lang ON (carrier.";
                 $query .= "carrier_id = carrier_lang.carrier_id AND carrier_lang.lang_id = " . (int) $lang_id . ") ";
                 /*if($this->shop_id && !(empty($this->multiLangShop))){
                 			$where = " AND carrier_lang.shop_id = " . $this->shop_id;
                 		}*/
             }
             /** Get shop informations **/
             if (JeproshopShopModelShop::isTableAssociated('carrier')) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_carrier_shop') . " AS carrier_shop ON (carrier.";
                 $query .= "carrier_id = carrier_shop.carrier_id AND carrier_shop.shop_id = " . (int) $this->shop_id . ")";
             }
             $query .= " WHERE carrier.carrier_id = " . (int) $carrier_id . $where;
             $db->setQuery($query);
             $carrier_data = $db->loadObject();
             if ($carrier_data) {
                 if (!$lang_id && isset($this->multiLang) && $this->multiLang) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_carrier_lang');
                     $query .= " WHERE carrier_id = " . (int) $carrier_id;
                     $db->setQuery($query);
                     $carrier_lang_data = $db->loadObjectList();
                     if ($carrier_lang_data) {
                         foreach ($carrier_lang_data as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'carrier_id') {
                                     if (!isset($carrier_data->{$key}) || !is_array($carrier_data->{$key})) {
                                         $carrier_data->{$key} = array();
                                     }
                                     $carrier_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $carrier_data);
             }
         } else {
             $carrier_data = JeproshopCache::retrieve($cache_id);
         }
         if ($carrier_data) {
             $carrier_data->carrier_id = $carrier_id;
             foreach ($carrier_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     /**
      * keep retro-compatibility SHIPPING_METHOD_DEFAULT
      * @deprecated 1.5.5
      */
     if ($this->shipping_method == JeproshopCarrierModelCarrier::DEFAULT_SHIPPING_METHOD) {
         $this->shipping_method = (int) JeproshopSettingModelSetting::getValue('shipping_method') ? JeproshopCarrierModelCarrier::WEIGHT_SHIPPING_METHOD : JeproshopCarrierModelCarrier::PRICE_SHIPPING_METHOD;
     }
     /**
      * keep retro-compatibility id_tax_rules_group
      * @deprecated 1.5.0
      */
     if ($this->carrier_id) {
         $this->tax_rules_group_id = $this->getTaxRulesGroupId(JeproshopContext::getContext());
     }
     if ($this->name == '0') {
         $this->name = JeproshopSettingModelSetting::getValue('shop_name');
     }
     $this->image_dir = COM_JEPROSHOP_CARRIER_IMAGE_DIR;
 }
Example #11
0
 public function renderAddForm($tpl = null)
 {
     //print_r(JeproshopCustomerModelCustomer::searchByName('je'));
     $context = JeproshopContext::getContext();
     if ($context->shop->getShopContext() != JeproshopShopModelShop::CONTEXT_SHOP && JeproshopShopModelShop::isFeaturePublished()) {
         $context->controller->has_errors = true;
         $this->l('You have to select a shop before creating new orders.');
     }
     $app = JFactory::getApplication();
     $cart_id = (int) $app->input->get('cart_id');
     $cart = new JeproshopCartModelCart((int) $cart_id);
     if ($cart_id && !JeproshopTools::isLoadedObject($cart, 'cart_id')) {
         $context->controller->has_errors = true;
         $this->l('This cart does not exists');
     }
     if ($cart_id && JeproshopTools::isLoadedObject($cart, 'cart_id') && !$cart->customer_id) {
         $context->controller->has_errors = true;
         $this->l('The cart must have a customer');
     }
     if ($context->controller->has_errors) {
         return false;
     }
     /*parent::renderForm();
             unset($this->toolbar_btn['save']);
             $this->addJqueryPlugin(array('autocomplete', 'fancybox', 'typewatch'));
     */
     $defaults_order_statues = array('cheque' => (int) JeproshopSettingModelSetting::getValue('order_status_cheque'), 'bank_wire' => (int) JeproshopSettingModelSetting::getValue('order_status_bank_wire'), 'cash_on_delivery' => (int) JeproshopSettingModelSetting::getValue('order_status_preparation'), 'other' => (int) JeproshopSettingModelSetting::getValue('order_status_payment'));
     $payment_modules = array();
     /*  foreach (PaymentModule::getInstalledPaymentModules() as $p_module)
                 $payment_modules[] = Module::getInstanceById((int)$p_module['id_module']);
     */
     $recyclable_pack = (int) JeproshopSettingModelSetting::getValue('offer_recycled_wrapping');
     $this->assignRef('recyclable_pack', $recyclable_pack);
     $gift_wrapping = (int) JeproshopSettingModelSetting::getValue('offer_gift_wrapping');
     $this->assignRef('gift_wrapping', $gift_wrapping);
     $this->assignRef('cart', $cart);
     $this->assignRef('cart_id', $cart_id);
     $currencies = JeproshopCurrencyModelCurrency::getCurrenciesByShopId(JeproshopContext::getContext()->shop->shop_id);
     $this->assignRef('currencies', $currencies);
     $languages = JeproshopLanguageModelLanguage::getLanguages(true, JeproshopContext::getContext()->shop->shop_id);
     $this->assignRef('languages', $languages);
     $this->assignRef('payment_modules', $payment_modules);
     $order_statues = JeproshopOrderStatusModelOrderStatus::getOrderStatus((int) JeproshopContext::getContext()->language->lang_id);
     $this->assignRef('order_statues', $order_statues);
     $this->assignRef('defaults_order_statues', $defaults_order_statues);
     /*    'show_toolbar' => $this->show_toolbar,
               'toolbar_btn' => $this->toolbar_btn,
               'toolbar_scroll' => $this->toolbar_scroll,
               'title' => array($this->l('Orders'), $this->l('Create order'))
           ));* /
           $this->content .= $this->createTemplate('form.tpl')->fetch(); */
     $this->addToolBar();
     $this->sideBar = JHtmlSideBar::render();
     parent::display($tpl);
 }
Example #12
0
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// no direct access
defined('_JEXEC') or die('Restricted access');
if (!file_exists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'load.php')) {
    JError::raiseError(500, JText::_(''));
}
require_once dirname(__FILE__) . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'load.php';
$context = JeproshopContext::getContext();
/** initialize the shop **/
$context->shop = JeproshopShopModelShop::initialize();
/** load configuration  */
JeproshopSettingModelSetting::loadSettings();
/** load languages  */
JeproshopLanguageModelLanguage::loadLanguages();
/** set context cookie */
$life_time = time() + max(JeproshopSettingModelSetting::getValue('bo_life_time'), 1) * 3600;
$context->cookie = new JeproshopCookie('jeproshop_site', '', $life_time);
/** @var  employee */
$context->employee = new JeproshopEmployeeModelEmployee(JFactory::getUser()->id);
$context->cookie->employee_id = $context->employee->employee_id;
/** Loading default country */
$context->country = new JeproshopCountryModelCountry(JeproshopSettingModelSetting::getValue('default_country'), JeproshopSettingModelSetting::getValue('default_lang'));
/** if the cookie stored language is not an available language, use default language */
if (isset($context->cookie->lang_id) && $context->cookie->lang_id) {
    $language = new JeproshopLanguageModelLanguage($context->cookie->lang_id);
}
if (!isset($language) || !JeproshopTools::isLoadedObject($language, 'lang_id')) {
    $language = new JeproshopLanguageModelLanguage(JeproshopSettingModelSetting::getValue('default_lang'));
}
Example #13
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;
     }
 }
Example #14
0
 public function __construct($attribute_group_id = null, $lang_id = null, $shop_id = null)
 {
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== FALSE ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($shop_id && $this->isMultiShop()) {
         $this->shop_id = (int) $shop_id;
         $this->get_shop_from_context = false;
     }
     if ($this->isMultiShop() && !$this->shop_id) {
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     if ($attribute_group_id) {
         $cache_id = 'jeproshop_attribute_group_model_' . (int) $attribute_group_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $db = JFactory::getDBO();
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_attribute_group') . " AS attribute_group ";
             $where = " WHERE attribute_group." . $db->quoteName('attribute_group_id') . " = " . (int) $attribute_group_id;
             //Get Language information
             if ($lang_id) {
                 $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_lang') . " AS attribute_group_lang ON (attribute_group.";
                 $query .= $db->quoteName('attribute_group_id') . " = attribute_group_lang." . $db->quoteName('attribute_group_id') . " AND ";
                 $query .= "attribute_group_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")";
                 if ($this->shop_id && !empty($this->multiLangShop)) {
                     $where .= " AND attribute_group_lang." . $db->quoteName('shop_id') . " = " . (int) $shop_id;
                 }
             }
             // Get Shop Information
             if (JeproshopShopModelShop::isTableAssociated('attribute_group')) {
                 $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_attribute_group_shop') . " AS attribute_group_shop ON (attribute_group.";
                 $query .= $db->quoteName('attribute_group_id') . " = attribute_group_shop." . $db->quoteName('attribute_group_id') . " AND attribute_group_shop.";
                 $query .= $db->quoteName('shop_id') . " = " . (int) $this->shop_id . ")";
             }
             $db->setQuery($query . $where);
             $attributeGroupData = $db->loadObject();
             if ($attributeGroupData) {
                 if (!$lang_id && isset($this->multiLang) && $this->multiLang) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_attribute_group_lang') . " WHERE " . $db->quoteName('attribute_group_id') . " = ";
                     $query .= (int) $attribute_group_id;
                     // . (($this->shop_id && $this->isMultiLangShop()) ? " AND " . $db->quoteName('shop_id') . " = " . (int)$this->shop_id : "");
                     $db->setQuery($query);
                     $attributeGroupDataLang = $db->loadObjectList();
                     if ($attributeGroupDataLang) {
                         foreach ($attributeGroupDataLang as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'attribute_group_id') {
                                     if (!isset($attributeGroupData->{$key}) || !is_array($attributeGroupData->{$key})) {
                                         $attributeGroupData->{$key} = array();
                                     }
                                     $attributeGroupData->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $attributeGroupData);
             }
         } else {
             $attributeGroupData = JeproshopCache::retrieve($cache_id);
         }
         if ($attributeGroupData) {
             $this->attribute_group_id = (int) $attribute_group_id;
             foreach ($attributeGroupData as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
 }
Example #15
0
 /**
  * Return available languages
  *
  * @param bool $published
  * @param bool $shop_id
  * @return array Languages
  */
 public static function getLanguages($published = true, $shop_id = false)
 {
     if (!self::$_LANGUAGES) {
         JeproshopLanguageModelLanguage::loadLanguages();
     }
     $default_language = JFactory::getLanguage();
     $languages = array();
     foreach (self::$_LANGUAGES as $language) {
         if ($published && !$language->published || $shop_id && !isset($language->shops[(int) $shop_id])) {
             continue;
         }
         if ($default_language->getTag() == $language->language_code) {
             $language->is_default = 1;
         }
         $languages[] = $language;
     }
     return $languages;
 }
Example #16
0
 public function __construct($employee_id = NULL, $lang_id = NULL, $shop_id = null)
 {
     parent::__construct();
     $db = JFactory::getDBO();
     if ($lang_id !== null) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== false ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($shop_id && $this->isMultiShop()) {
         $this->shop_id = (int) $shop_id;
         $this->getShopFromContext = false;
     }
     /*
     if($this->isMultiShop() && !$this->shop_id){
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     
     if($employee_id){
         /** load employee from database if employee * /
         $cache_id = 'jeproshop_employee_model_' . (int)$employee_id . (($lang_id) ? '_lang_' . (int)$lang_id : '') .(($shop_id) ? '_shop_' .(int)$shop_id : '');
         if(!JeproshopCache::isStored($cache_id)){
             $query = "SELECT * FROM " . $db->quoteName('#__users') . " AS employee LEFT JOIN " . $db->quoteName('#__jeproshop_employee');
             $query .= " AS alias ON(employee.id = alias.employee_id) ";
             //add language filter
             $where = "";
             if($lang_id){
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_employee_lang') . " employee_lang ON(alias.";
                 $query .= $db->quoteName('employee_id') . " = employee_lang." . $db->quoteName('employee_id') ;
                 $query .= " AND employee_lang." . $db->quoteName('lang_id') . " = " . (int)$lang_id . ")";
                 if($this->shop_id && !empty($this->multiLangShop)){
                     $where = " AND employee_lang." . $db->quoteName('shop_id') . " = " . $this->shop_id;
                 }
             }
     
             /** get shop information * /
             if(JeproshopShopModelShop::isTableAssociated('employee')){
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_employee_shop') . " AS shop ON(alias.employee_id";
                 $query .= " = shop.employee_id AND shop.shop_id = " .  (int)$this->shop_id . ")";
             }
     
             $query .= " WHERE employee." . $db->quoteName('id') . " = " . (int)$employee_id . $where;
             $db->setQuery($query);
     
             $employee_data = $db->loadObject();
             if($employee_data){
                 if(!$lang_id && isset($this->multiLang) && $this->multiLang){
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_employee_lang') . " WHERE " . $db->quoteName('employee_id');
                     $query .= " = " . (int)$employee_id . (($this->shop_id && $this->isLangMultiShop()) ? " AND " . $db->quoteName('shop_id') . " = " . $this->shop_id : "");
     
                     $db->setQuery($query);
                     $employee_lang_data = $db->loadObjectList();
                     if($employee_lang_data){
                         foreach($employee_lang_data as $row){
                             foreach($row as $key => $value){
                                 if(array_key_exists($key, $this) && $key != 'employee_id'){
                                     if(!isset($employee_data->{$key}) || !is_array($employee_data->{$key})){
                                         $employee_data->{$key} = array();
                                     }
                                     $employee_data->{$key}[$row->lang_id] =$value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $employee_data);
             }
         } else{
             $employee_data = JeproshopCache::retrieve($cache_id);
         }
     
         if($employee_data){
             $employee_data->employee_id = (int)$employee_id;
             foreach($employee_data as $key => $value){
                 if(array_key_exists($key, $this)){
                     $this->{$key} = $value;
                 }
             }
         }
     }
     
     if($this->employee_id){
         $this->associated_shops = $this->getAssociatedShops();
     }
     */
     $this->image_dir = COM_JEPROSHOP_EMPLOYEE_IMAGE_DIRECTORY;
 }
Example #17
0
 public function getLanguages()
 {
     $cookie = JeproshopContext::getContext()->cookie;
     $this->allow_employee_form_language = (int) JeproshopSettingModelSetting::getValue('allow_employee_form_lang');
     if ($this->allow_employee_form_language && !$cookie->employee_form_lang) {
         $cookie->employee_form_lang = (int) JeproshopSettingModelSetting::getValue('default_lang');
     }
     $lang_exists = false;
     $languages = JeproshopLanguageModelLanguage::getLanguages(false);
     foreach ($languages as $language) {
         if (isset($cookie->employee_form_language) && $cookie->employee_form_language == $language->lang_id) {
             $lang_exists = true;
         }
     }
     $this->default_form_language = $lang_exists ? (int) $cookie->employee_form_language : (int) JeproshopSettingModelSetting::getValue('default_lang');
     return $languages;
 }
Example #18
0
 public static function defineProductImage($row, $lang_id)
 {
     if (isset($row->image_id) && $row->image_id) {
         return $row->product_id . '_' . $row->image_id;
     }
     return JeproshopLanguageModelLanguage::getIsoById((int) $lang_id) . '_default';
 }
Example #19
0
 public function __construct($feature_id = null, $lang_id = null, $shop_id = null)
 {
     if ($lang_id !== null) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) !== false ? $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($shop_id && $this->isMultiShop()) {
         $this->shop_id = (int) $shop_id;
         $this->get_shop_from_context = false;
     }
     if ($this->isMultiShop() && !$this->shop_id) {
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     if ($feature_id) {
         // Load object from database if object id is present
         $cache_id = 'jeproshop_feature_model_' . (int) $feature_id . '_' . (int) $this->shop_id . '_' . (int) $lang_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $db = JFactory::getDBO();
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_feature') . " AS feature ";
             $where = " WHERE feature." . $db->quoteName('feature_id') . " = " . (int) $feature_id;
             // Get lang informations
             if ($lang_id) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_feature_lang') . " AS feature_lang ON (feature." . $db->quoteName('feature_id') . " = ";
                 $query .= $db->quoteName('feature_id') . " AND feature_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ") ";
                 if ($this->shop_id && !empty($this->multiLangShop)) {
                     $where .= " AND feature_lang." . $db->quoteName('shop_id') . " = " . $this->shop_id;
                 }
             }
             // Get shop informations
             if (JeproshopShopModelShop::isTableAssociated('feature')) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_feature_shop') . " AS feature_shop ON (feature." . $db->quoteName('feature_id') . " = feature_shop.";
                 $query .= $db->quoteName('feature_id') . " AND feature_shop." . $db->quoteName('shop_id') . " = " . (int) $this->shop_id . ") ";
             }
             $db->setQuery($query . $where);
             $feature_data = $db->loadObject();
             if ($feature_data) {
                 if (!$lang_id && isset($this->multiLang) && $this->multiLang) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_feature_lang') . " WHERE " . $db->quoteName('feature_id') . " = " . (int) $feature_id;
                     $query .= $this->shop_id && $this->isLangMultiShop() ? " AND " . $db->quoteName('shop_id') . " = " . $this->shop_id : "";
                     $db->setQuery($query);
                     $feature_data_lang = $db->loadObjectList();
                     if ($feature_data_lang) {
                         foreach ($feature_data_lang as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'feature_id') {
                                     if (!isset($feature_data->{$key}) || !is_array($feature_data->{$key})) {
                                         $feature_data->{$key} = array();
                                     }
                                     $feature_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $feature_data);
             }
         } else {
             $feature_data = JeproshopCache::retrieve($cache_id);
         }
         if ($feature_data) {
             //$this->id = (int)$id;
             foreach ($feature_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
 }
Example #20
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);
     }
 }
Example #21
0
 private function initImagesForm()
 {
     if ((bool) $this->product->product_id) {
         if ($this->product_exists_in_shop) {
             $shops = false;
             if (JeproshopShopModelShop::isFeaturePublished()) {
                 $shops = JeproshopShopModelShop::getShops();
             }
             if ($shops) {
                 foreach ($shops as $key => $shop) {
                     if (!$this->product->isAssociatedToShop($shop->shop_id)) {
                         unset($shops[$key]);
                     }
                 }
             }
             $this->assignRef('shops', $shops);
             $db = JFactory::getDBO();
             $app = JFactory::getApplication();
             $query = "SELECT COUNT(product_id) FROM " . $db->quoteName('#__jeproshop_image');
             $query .= " WHERE product_id = " . (int) $this->product->product_id;
             $db->setQuery($query);
             $count_images = $db->loadResult();
             $images = JeproshopImageModelImage::getImages($this->context->language->lang_id, $this->product->product_id);
             foreach ($images as $k => $image) {
                 $images[$k] = new JeproshopImageModelImage($image->image_id);
             }
             if ($this->context->shop->getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
                 $current_shop_id = (int) $this->context->shop->shop_id;
             } else {
                 $current_shop_id = 0;
             }
             $languages = JeproshopLanguageModelLanguage::getLanguages(true);
             $image_uploader = new JeproshopImageUploader('file');
             $image_link = JRoute::_('index.php?option=com_jeproshop&view=product&ajax=1&product_id=' . (int) $this->product->product_id . '&task=add_product_image');
             $image_uploader->setMultiple(!(JeproshopTools::getUserBrowser() == 'Apple Safari' && JeproshopTools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl($image_link);
             $this->assignRef('countImages', $count_images);
             /*$this->assignRef(
               'id_product' => (int)Tools::getValue('id_product'),
               'id_category_default' => (int)$this->_category->id, */
             $this->assignRef('images', $images);
             /*'iso_lang' => $languages[0]['iso_code'],
               'token' =>  $this->token,
               'table' => $this->table,*/
             $image_size = (int) JeproshopSettingModelSetting::getValue('product_picture_max_size') / 1024 / 1024;
             $this->assignRef('max_image_size', $image_size);
             $virtualProductFilenameAttribute = (string) $app->input->get('virtual_product_filename_attribute');
             $this->assignRef('up_filename', $virtualProductFilenameAttribute);
             //'currency' => $this->context->currency,
             $this->assignRef('current_shop_id', $current_shop_id);
             //		'languages' => $this->_languages,
             //		'default_language' => (int)Configuration::get('PS_LANG_DEFAULT'),
             $imageUploader = $image_uploader->render();
             $this->assignRef('image_uploader', $imageUploader);
             //));
             $type = JeproshopImageTypeModelImageType::getByNameNType('%', 'products', 'height');
             if (isset($type->name)) {
                 $imageType = $type->name;
             } else {
                 $imageType = 'small_default';
             }
             $this->assignRef('image_type', $imageType);
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before adding images.'));
         }
     }
 }
Example #22
0
 public function updateTax()
 {
     $db = JFactory::getDBO();
     $this->clearCache();
     $result = true;
     $languages = JeproshopLanguageModelLanguage::getLanguages(false);
     $input = JRequest::get('post');
     $input_data = $input['jform'];
     $published = $input_data['published'];
     $deleted = $published ? 0 : 1;
     $query = "UPDATE " . $db->quoteName('#__jeproshop_tax') . " SET " . $db->quoteName('rate') . " = " . (double) $input_data['tax_rate'] . ", " . $db->quoteName('published') . " = " . (int) $published;
     $query .= ", " . $db->quoteName('deleted') . " = " . (int) $deleted . " WHERE " . $db->quoteName('tax_id') . " = " . (int) $this->tax_id;
     $db->setQuery($query);
     $result &= $db->query();
     foreach ($languages as $language) {
         $where = $db->quoteName('tax_id') . " = " . (int) $this->tax_id . " AND " . $db->quoteName('lang_id') . " = " . (int) $language->lang_id;
         $query = "SELECT COUNT(*) FROM " . $db->quoteName('#__jeproshop_tax_lang') . " WHERE " . $where;
         $db->setQuery($query);
         if ($db->loadResult()) {
             $query = "UPDATE " . $db->quoteName('#__jeproshop_tax_lang') . " SET " . $db->quoteName('name') . " = " . $db->quote($input_data['name_' . $language->lang_id]) . " WHERE " . $where;
             $db->setQuery($query);
             $result &= $db->query();
         } else {
             $query = "INSERT INTO " . $db->quoteName('#__jeproshop_tax_lang') . "(" . $db->quoteName('name') . ") VALUE (" . $db->quote($input_data['name_' . $language->lang_id]) . ")";
             $db->setQuery($query);
             $result &= $db->query();
         }
     }
     return $result;
 }
Example #23
0
 public function multiLanguageTextAreaField($fieldName, $wrapper, $content = NULL, $width = '550', $height = '100')
 {
     $wrapper = $wrapper ? $wrapper : 'jform';
     if (!isset($this->languages) || !$this->languages) {
         $this->languages = JeproshopLanguageModelLanguage::getLanguages();
     }
     $script = '<div class="translatable" >';
     foreach ($this->languages as $language) {
         $script .= '<div class="lang_' . $language->lang_id . ' input_lang"' . (!$language->is_default ? 'style="display:none" ' : '') . ' >';
         $script .= '<textarea class="ckeditor" name="' . $wrapper . '[' . $fieldName . '_' . $language->lang_id . ']" id="jform_' . $fieldName . '_' . $language->lang_id . '" >';
         $script .= ($content ? $content[$language->lang_id] : '') . '</textarea>';
         $script .= '</div><div class="btn-group-action lang-select" ><div class="btn-group" >';
         $script .= '<button type="button" class="btn btn-default dropdown_toggle" tabindex="-1" data-toggle="dropdown" > ';
         $script .= $language->iso_code . '&nbsp; <i class="caret" ></i> </button><ul class="dropdown-menu" >';
         foreach ($this->languages as $value) {
             $script .= '<li><a href="jeproLang.hideOtherLanguage(' . $value->lang_id . ');" tabindex="-1" >' . $value->name . '</a></li>';
         }
         $script .= '</ul></div></div>';
         //$script .= '</div></div>';
     }
     $script .= '</div>';
     return $script;
 }
Example #24
0
 /**
  * Return current category childs
  *
  * @param integer $lang_id Language ID
  * @param boolean $published return only active categories
  * @return array Categories
  */
 public function getSubCategories($lang_id, $published = true)
 {
     $sql_groups_where = '';
     $sql_groups_join = '';
     $db = JFactory::getDBO();
     if (JeproshopGroupModelGroup::isFeaturePublished()) {
         $sql_groups_join = " LEFT JOIN " . $db->quoteName('#__jeproshop_category_group') . " AS category_group ON (category_group." . $db->quoteName('category_id') . " = category." . $db->quoteName('category_id') . ")";
         $groups = JeproshopController::getCurrentCustomerGroups();
         $sql_groups_where = " AND category_group." . $db->quoteName('group_id') . " " . (count($groups) ? " IN (" . implode(',', $groups) . ")" : " = " . (int) JeproshopGroupModelGroup::getCurrent()->group_id);
     }
     $query = "SELECT category.*, category_lang.lang_id, category_lang.name, category_lang.description, category_lang.link_rewrite, category_lang.meta_title, category_lang.meta_keywords, ";
     $query .= " category_lang.meta_description FROM " . $db->quoteName('#__jeproshop_category') . " AS category " . JeproshopShopModelShop::addSqlAssociation('category') . " LEFT JOIN ";
     $query .= $db->quoteName('#__jeproshop_category_lang') . " AS category_lang ON (category." . $db->quoteName('category_id') . " = category_lang." . $db->quoteName('category_id');
     $query .= " AND " . $db->quoteName('lang_id') . " = " . (int) $lang_id . " " . JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang') . ") " . $sql_groups_join;
     $query .= " WHERE " . $db->quoteName('parent_id') . " = " . (int) $this->category_id . ($published ? " AND " . $db->quoteName('published') . " = 1 " : "") . $sql_groups_where;
     $query .= "\tGROUP BY category." . $db->quoteName('category_id') . " ORDER BY " . $db->quoteName('depth_level') . " ASC, category_shop." . $db->quoteName('position') . " ASC";
     $db->setQuery($query);
     $result = $db->loadObjectList();
     foreach ($result as &$row) {
         $row->image_id = JeproshopTools::file_exists_cache(COM_JEPROSHOP_CATEGORY_IMAGE_DIRECTORY . $row->category_id . '.jpg') ? (int) $row->category_id : JeproshopLanguageModelLanguage::getIsoById($lang_id) . '_default';
         $row->legend = JText::_('COM_JEPROSHOP_NO_PICTURE_LABEL');
     }
     return $result;
 }
Example #25
0
 public function __construct($shop_id = null, $lang_id = null)
 {
     parent::__construct();
     $db = JFactory::getDBO();
     if ($lang_id != null) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) != false ? $lang_id : JeproshopSettingModelSetting::getSettingValue('default_lang');
     }
     if ($shop_id) {
         /** Load shop from database if  id is supplied */
         $cache_id = 'jeproshop_shop_model_' . (int) $shop_id . ($lang_id > 0 ? '_' . $lang_id : '');
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_shop') . " AS shop ";
             if ($lang_id) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_shop_lang');
                 $query .= " ON(shop." . $db->quoteName('shop_id') . " = shop_lang." . $db->quoteName('shop_id');
                 $query .= " AND shop_lang." . $db->quoteName('lang_id') . " = " . (int) $lang_id . ")";
             }
             $query .= " WHERE shop." . $db->quoteName('shop_id') . " = " . (int) $shop_id;
             $db->setQuery($query);
             $shop_data = $db->loadObject();
             //print_r($shop_data);
             if ($shop_data) {
                 /*if($lang_id && isset($this->multilang) && $this->multilang){
                 			$query = " SELECT * FROM " . $db->quoteName('#__jeproshop_shop_lang') . " WHERE ";
                 			$query .= $db->quoteName('shop_id') . " = " . $shop_id;
                 			$db->setQuery($query);
                 			$shop_lang_data = $db->loadObjectList();
                 			if($shop_lang_data){
                 				foreach($shop_lang_data as $row){
                 					foreach($row as $key => $value){
                 						if(array_key_exists($key, $this) && $key != 'shop_id'){
                 							if(!isset($shop_data->{$key}) || !is_array($shop_data->{$key})){
                 								$shop_data->{$key} = array();
                 							}
                 							$shop_data->{$key}[$row->lang_id]  = $value;
                 						}
                 					}
                 				}
                 			}
                 		}*/
                 JeproshopCache::store($cache_id, $shop_data);
             }
         } else {
             $shop_data = JeproshopCache::retrieve($cache_id);
         }
         if ($shop_data) {
             $this->shop_id = (int) $shop_id;
             foreach ($shop_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     //if($key != 'name'){
                     $this->{$key} = $value;
                     /*}else{
                     			$prop = 'shop_' . $key;
                     			$this->{$prop} = $value;
                     		}*/
                 }
             }
         }
     }
     if ($this->shop_id) {
         $this->setShopUrl();
     }
 }
Example #26
0
 public function __construct($order_id = null, $lang_id = null)
 {
     //parent::__construct();
     $db = JFactory::getDBO();
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($this->isMultiShop() && !$this->shop_id) {
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     if ($order_id) {
         $cache_id = 'jeproshop_order_model_' . $order_id . '_' . $lang_id . '_' . $this->shop_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_orders') . " AS ord ";
             $where = "";
             /** get language information **/
             if ($lang_id) {
                 $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_product_lang') . " AS product_lang ";
                 $query .= "ON (product.product_id = product_lang.product_id AND product_lang.lang_id = " . (int) $lang_id . ") ";
                 if ($this->shop_id && !empty($this->multiLangShop)) {
                     $where = " AND product_lang.shop_id = " . $this->shop_id;
                 }
             }
             /** Get shop information **/
             if (JeproshopShopModelShop::isTableAssociated('order')) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_order_shop') . " AS order_shop ON (";
                 $query .= "ord.order_id = order_shop.order_id AND order_shop.shop_id = " . (int) $this->shop_id . ")";
             }
             $query .= " WHERE ord.order_id = " . (int) $order_id . $where;
             $db->setQuery($query);
             $order_data = $db->loadObject();
             if ($order_data) {
                 if (!$lang_id && isset($this->multiLang) && $this->multiLang) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_product_lang');
                     $query .= " WHERE product_id = " . (int) $order_id;
                     $db->setQuery($query);
                     $order_lang_data = $db->loadObjectList();
                     if ($order_lang_data) {
                         foreach ($order_lang_data as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'order_id') {
                                     if (!isset($order_data->{$key}) || !is_array($order_data->{$key})) {
                                         $order_data->{$key} = array();
                                     }
                                     $order_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $order_data);
             }
         } else {
             $order_data = JeproshopCache::retrieve($cache_id);
         }
         if ($order_data) {
             $order_data->product_id = $order_id;
             foreach ($order_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     if ($this->customer_id) {
         $customer = new JeproshopCustomerModelCustomer((int) $this->customer_id);
         $this->_taxCalculationMethod = JeproshopGroupModelGroup::getPriceDisplayMethod((int) $customer->default_group_id);
     }
 }
Example #27
0
 public function __construct($group_id = NULL, $lang_id = NULL, $shop_id = NULL)
 {
     $db = JFactory::getDBO();
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) ? (int) $lang_id : JeproshopSettingModelSetting::getValue('default_lang');
     }
     if ($shop_id && $this->isMultiShop()) {
         $this->shop_id = (int) $shop_id;
         $this->getShopFromContext = FALSE;
     }
     if ($this->isMultiShop() && !$this->shop_id) {
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     if ($group_id) {
         $cache_id = 'jeproshop_group_model_' . $group_id . '_' . $lang_id . '_' . $shop_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_group') . " AS j_group ";
             $where = "";
             /** get language information **/
             if ($lang_id) {
                 $query .= "LEFT JOIN " . $db->quoteName('#__jeproshop_group_lang') . " AS group_lang ";
                 $query .= "ON (j_group.group_id = group_lang.group_id AND group_lang.lang_id = " . (int) $lang_id . ") ";
                 if ($this->shop_id && !empty($this->multiLangShop)) {
                     $where = " AND group_lang.shop_id = " . $this->shop_id;
                 }
             }
             /** Get shop informations **/
             if (JeproshopShopModelShop::isTableAssociated('group')) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_group_shop') . " AS group_shop ON (";
                 $query .= "j_group.group_id = group_shop.group_id AND group_shop.shop_id = " . (int) $this->shop_id . ")";
             }
             $query .= " WHERE j_group.group_id = " . (int) $group_id . $where;
             $db->setQuery($query);
             $group_data = $db->loadObject();
             if ($group_data) {
                 if (!$lang_id && isset($this->multiLang) && $this->multiLang) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_group_lang');
                     $query .= " WHERE group_id = " . (int) $group_id;
                     $db->setQuery($query);
                     $group_lang_data = $db->loadObjectList();
                     if ($group_lang_data) {
                         foreach ($group_lang_data as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'group_id') {
                                     if (!isset($group_data->{$key}) || !is_array($group_data->{$key})) {
                                         $group_data->{$key} = array();
                                     }
                                     $group_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $group_data);
             }
         } else {
             $group_data = JeproshopCache::retrieve($cache_id);
         }
         if ($group_data) {
             $group_data->group_id = $group_id;
             foreach ($group_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     if ($this->group_id && !isset(JeproshopGroupModelGroup::$group_price_display_method[$this->group_id])) {
         self::$group_price_display_method[$this->group_id] = $this->price_display_method;
     }
 }
Example #28
0
 public function __construct($shop_id = NULL, $lang_id = NULL)
 {
     parent::__construct();
     $db = JFactory::getDBO();
     if ($lang_id !== NULL) {
         $this->lang_id = JeproshopLanguageModelLanguage::getLanguage($lang_id) != FALSE ? $lang_id : JeproshopSettingModelSetting::getSettingValue('default_lang');
     }
     if ($shop_id) {
         $this->shop_id = (int) $shop_id;
         $this->get_shop_from_context = FALSE;
     }
     if (!$this->shop_id) {
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     if ($shop_id) {
         //load object from database if object id is present
         $cache_id = 'jeproshop_shop_model_' . $shop_id . '_' . $lang_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_shop') . " AS shop ";
             $where = "";
             if ($lang_id) {
                 //Get lang informations
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_shop_lang') . " AS shop_lang ";
                 $query .= " ON (shop.shop_id = shop_lang.shop_id AND shop_lang.lang_id = " . (int) $lang_id . ")";
                 if ($this->shop_id && !empty($this->multiLangShop)) {
                     $where = " AND shop_lang.shop_id = " . $this->shop_id;
                 }
             }
             $query .= "WHERE shop.shop_id = " . (int) $shop_id . $where;
             $db->setQuery($query);
             $shop_data = $db->loadObject();
             if ($shop_data) {
                 if (!$lang_id && isset($this->multiLang) && $this->multiLang) {
                     $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_shop_lang') . " WHERE shop_id = " . (int) $shop_id;
                     $db->setQuery($query);
                     $shop_lang_data = $db->loadObjectList();
                     if ($shop_lang_data) {
                         foreach ($shop_lang_data as $row) {
                             foreach ($row as $key => $value) {
                                 if (array_key_exists($key, $this) && $key != 'shop_id') {
                                     if (!isset($shop_data->{$key}) || !is_array($shop_data->{$key})) {
                                         $shop_data->{$key} = array();
                                     }
                                     $shop_data->{$key}[$row->lang_id] = $value;
                                 }
                             }
                         }
                     }
                 }
                 JeproshopCache::store($cache_id, $shop_data);
             }
         } else {
             $shop_data = JeproshopCache::retrieve($cache_id);
         }
         if ($shop_data) {
             $shop_data->shop_id = (int) $shop_id;
             foreach ($shop_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     if ($this->shop_id) {
         $this->setShopUrl();
     }
 }
Example #29
0
 public static function indexation($full = false, $product_id = false)
 {
     $db = JFactory::getDBO();
     if ($product_id) {
         $full = false;
     }
     if ($full) {
         $db->execute('TRUNCATE ' . $db->quoteName('#__jeproshop_search_index'));
         $db->execute('TRUNCATE ' . $db->quoteName('#__jeproshop_search_word'));
         self::updateMultishopTable('Product', array('indexed' => 0));
     } else {
         // Do it even if you already know the product id in order to be sure that it exists and it needs to be indexed
         $query = "SELECT product.product_id FROM " . $db->quoteName('#__jeproshop_product') . " AS product ";
         $query .= JeproshopShopModelShop::addSqlAssociation('product') . " WHERE product_shop.visibility IN (\"both\", \"search\") ";
         $query .= " AND product_shop." . $db->quoteName('published') . " = 1 AND ";
         $query .= $product_id ? "product.product_id = " . (int) $product_id : "product_shop.indexed = 0";
         $db->setQuery($query);
         $products = $db->loadObjectList();
         $ids = array();
         if ($products) {
             foreach ($products as $product) {
                 $ids[] = (int) $product->product_id;
             }
         }
         if (count($ids)) {
             $query = "DELETE FROM " . $db->quoteName('#__jeproshop_search_index') . " WHERE product_id IN (" . implode(',', $ids) . ")";
             $db->setQuery($query);
             $db->query();
             $data = " SET product." . $db->quoteName('indexed') . " = 0";
             $where = ' WHERE product.product_id IN (' . implode(',', $ids) . ')';
             JeproshopProductModelProduct::updateMultishopTable($data, $where, '', true);
         }
     }
     // Every fields are weighted according to the configuration in the backend
     $weight_array = array('product_name' => JeproshopSettingModelSetting::getValue('search_weight_product_name'), 'reference' => JeproshopSettingModelSetting::getValue('search_weight_reference'), 'product_attribute_reference' => JeproshopSettingModelSetting::getValue('search_weight_reference'), 'ean13' => JeproshopSettingModelSetting::getValue('search_weight_reference'), 'upc' => JeproshopSettingModelSetting::getValue('search_weight_reference'), 'short_description' => JeproshopSettingModelSetting::getValue('search_weight_short_description'), 'description' => JeproshopSettingModelSetting::getValue('search_weight_description'), 'category_name' => JeproshopSettingModelSetting::getValue('search_weight_category_name'), 'manufacture_name' => JeproshopSettingModelSetting::getValue('search_weight_manufacturer_name'), 'tag' => JeproshopSettingModelSetting::getValue('search_weight_tag'), 'attributes' => JeproshopSettingModelSetting::getValue('search_weight_attribute'), 'features' => JeproshopSettingModelSetting::getValue('search_weight_feature'));
     // Those are kind of global variables required to save the processed data in the database every X occurrences, in order to avoid overloading MySQL
     $count_words = 0;
     $query_array3 = array();
     // Every indexed words are cached into a PHP array
     $query = "SELECT word_id, word, lang_id, shop_id FROM " . $db->quoteName('#__jeproshop_search_word');
     $db->setQuery($query);
     $word_ids = $db->loadObjectList();
     $word_ids_by_word = array();
     while ($word_id = $db->nextRow($word_ids)) {
         if (!isset($word_ids_by_word[$word_id->shop_id][$word_id->lang_id])) {
             $word_ids_by_word[$word_id['id_shop']][$word_id['id_lang']] = array();
         }
         $word_ids_by_word[$word_id->shop_id][$word_id->lang_id]['_' . $word_id->word] = (int) $word_id->word_id;
     }
     // Retrieve the number of languages
     $total_languages = count(JeproshopLanguageModelLanguage::getLanguages(false));
     // Products are processed 50 by 50 in order to avoid overloading MySQL
     while (($products = JeproshopSearch::getProductsToIndex($total_languages, $product_id, 50, $weight_array)) && count($products) > 0) {
         $products_array = array();
         // Now each non-indexed product is processed one by one, langage by langage
         foreach ($products as $product) {
             if ((int) $weight_array['tag']) {
                 $product->tags = JeproshopSearch::getTags($db, (int) $product->product_id, (int) $product->lang_id);
             }
             if ((int) $weight_array['attributes']) {
                 $product->attributes = JeproshopSearch::getAttributes($db, (int) $product->product_id, (int) $product->lang_id);
             }
             if ((int) $weight_array['features']) {
                 $product->features = JeproshopSearch::getFeatures($db, (int) $product->product_id, (int) $product->lang_id);
             }
             // Data must be cleaned of html, bad characters, spaces and anything, then if the resulting words are long enough, they're added to the array
             $product_array = array();
             foreach ($product as $key => $value) {
                 if (strncmp($key, 'id_', 3) && isset($weight_array[$key])) {
                     $words = explode(' ', JeproshopSearch::sanitize($value, (int) $product->lang_id, true, JeproshopContext::getContext()->language->iso_code));
                     foreach ($words as $word) {
                         if (!empty($word)) {
                             $word = substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH);
                             // Remove accents
                             $word = JeproshopValidator::replaceAccentedChars($word);
                             if (!isset($product_array[$word])) {
                                 $product_array[$word] = 0;
                             }
                             $product_array[$word] += $weight_array[$key];
                         }
                     }
                 }
             }
             // If we find words that need to be indexed, they're added to the word table in the database
             if (count($product_array)) {
                 $query_array = $query_array2 = array();
                 foreach ($product_array as $word => $weight) {
                     if ($weight && !isset($word_ids_by_word['_' . $word])) {
                         $query_array[$word] = '(' . (int) $product->lang_id . ', ' . (int) $product->shop_id . ', ' . $db->quote($word) . ')';
                         $query_array2[] = $db->quote($word);
                         $word_ids_by_word[$product->shop_id][$product->lang_id]['_' . $word] = 0;
                     }
                 }
                 if ($query_array2) {
                     $query = "SELECT DISTINCT word FROM " . $db->quoteName('#__jeproshop_search_word') . " WHERE word IN (";
                     $query .= implode(',', $query_array2) . ") AND lang_id = " . (int) $product->lang_id . " AND shop_id = " . (int) $product->shop_id;
                     $db->setQuery($query);
                     $existing_words = $db->loadObjectList();
                     foreach ($existing_words as $data) {
                         unset($query_array[JeproshopValidator::replaceAccentedChars($data->word)]);
                     }
                 }
                 if (count($query_array)) {
                     // The words are inserted...
                     $query = "INSERT IGNORE INTO " . $db->quoteName('#__jeproshop_search_word') . " (lang_id, shop_id, word) VALUES " . implode(',', $query_array);
                     $db->setQuery($query);
                     $db->query();
                 }
                 if (count($query_array2)) {
                     // ...then their IDs are retrieved and added to the cache
                     $query = "SELECT search_word.word_id, search_word.word FROM " . $db->quoteName('#__jeproshop_search_word') . " AS search_word ";
                     $query .= " WHERE search_word.word IN (" . implode(',', $query_array2) . ") AND search_word.lang_id = " . (int) $product->lang_id;
                     $query .= " AND search_word.shop_id = " . (int) $product->shop_id . " LIMIT " . count($query_array2);
                     $db->setQuery($query);
                     $added_words = $db->loadObjectList();
                     // replace accents from the retrieved words so that words without accents or with differents accents can still be linked
                     foreach ($added_words as $word_id) {
                         $word_ids_by_word[$product->shop_id][$product->lang_id]['_' . JeproshopValidator::replaceAccentedChars($word_id->word)] = (int) $word_id->word_id;
                     }
                 }
             }
             foreach ($product_array as $word => $weight) {
                 if (!$weight) {
                     continue;
                 }
                 if (!isset($word_ids_by_word[$product->shop_id][$product->lang_id]['_' . $word])) {
                     continue;
                 }
                 if (!$word_ids_by_word[$product->shop_id][$product->lang_id]['_' . $word]) {
                     continue;
                 }
                 $query_array3[] = '(' . (int) $product->product_id . ',' . (int) $word_ids_by_word[$product->shop_id][$product->lang_id]['_' . $word] . ',' . (int) $weight . ')';
                 // Force save every 200 words in order to avoid overloading MySQL
                 if (++$count_words % 200 == 0) {
                     JeproshopSearch::saveIndex($query_array3);
                 }
             }
             if (!in_array($product->product_id, $products_array)) {
                 $products_array[] = (int) $product->product_id;
             }
         }
         JeproshopSearch::setProductsAsIndexed($products_array);
         // One last save is done at the end in order to save what's left
         JeproshopSearch::saveIndex($query_array3);
     }
     return true;
 }
Example #30
0
 /** Get cookie content **/
 public function update()
 {
     $cookie = JRequest::get('COOKIE');
     if (isset($cookie[$this->_name])) {
         /** Decrypt cookie content **/
         $content = $this->_cipherTool->decrypt($cookie[$this->_name]);
         /** Get cookie checksum **/
         $checksum = crc32($this->_iv . substr($content, 0, strrpos($content, '�') + 2));
         /** Un-serialize cookie content **/
         $tmpTab = explode('�', $content);
         foreach ($tmpTab as $keyAndValue) {
             $tmpTab2 = explode('|', $keyAndValue);
             if (count($tmpTab2) == 2) {
                 $this->_content[$tmpTab2[0]] = $tmpTab2[1];
             }
         }
         /** Blowfish fix **/
         if (isset($this->_content['checksum'])) {
             $this->_content['checksum'] = (int) $this->_content['checksum'];
         }
         /** Check if cookie has not been modified **/
         if (!isset($this->_content['checksum']) || $this->_content['checksum'] != $checksum) {
             $this->logOut();
         }
         if (!isset($this->_content['date_add'])) {
             $this->_content['date_add'] = date('Y-m-d H:i:s');
         }
     } else {
         $this->_content['date_add'] = date('Y-m-d H:i:s');
     }
     /** checks if the language exists , if not choose  the default  language **/
     if (!JeproshopLanguageModelLanguage::getLanguage((int) $this->lang_id)) {
         $this->lang_id = JeproshopSettingModelSetting::getValue('default_lang');
     }
 }