Example #1
0
 public function initialize()
 {
     if (self::$initialized) {
         return;
     }
     self::$initialized = true;
     $app = JFactory::getApplication();
     $context = JeproshopContext::getContext();
     $view = $app->input->get('view', 'default');
     $viewClass = $this->getView($view, JFactory::getDocument()->getType());
     if (JeproshopTools::usingSecureMode()) {
         $this->ssl_enabled = true;
     }
     if (isset($context->cookie->account_created)) {
         $accountCreated = true;
         $viewClass->assignRef('account_created', $accountCreated);
         $context->cookie->account_created = 0;
     }
     JeproshopTools::setCookieLanguage($context->cookie);
     $cart_id = (int) $this->recoverCart();
     if ($cart_id) {
         $context->cookie->cart_id = $cart_id;
     }
     if ($this->authenticated && !$context->customer->isLogged($this->guest_allowed)) {
         $app->redirect('index.php?option=com_jeproshop&view=authentication');
         // todo add retun option
     }
     if (JeproshopSettingModelSetting::getValue('enable_geolocation')) {
         $defaultCountry = $this->geolocationManagement($context->country);
         if ($defaultCountry && JeproshopTools::isLoadedObject($defaultCountry, 'country_id')) {
             $context->country = $defaultCountry;
         }
     }
     $currency = JeproshopTools::setCurrency($context->cookie);
     $logout = $app->input->get('logout');
     $myLogout = $app->input->get('mylogout');
     if (isset($logout) || $context->customer->logged && JeproshopCustomerModelCustomer::isBanned($context->cutomer->customer_id)) {
         $context->customer->logout();
         //$app->input->get('')
     } elseif (isset($myLogout)) {
         $context->customer->mylogout();
     }
     if ((int) $context->cookie->cart_id) {
         $cart = new JeproshopCartModelCart($context->cookie->cart_id);
         if ($cart->orderExists()) {
             $context->cookie->cart_id = null;
             $context->cookie->check_selling_condition = false;
         } elseif ((int) JeproshopSettingModelSetting::getValue('enable_geolocation') && !in_array(strtoupper($context->cookie->iso_code_country), explode(';', JeproshopSettingModelSetting::getValue('allowed_countries'))) && $cart->numberOfProducts() && (int) JeproshopSettingModelSetting::getValue('geolocation_behavior') != -1 && !self::isInWhiteListForGeolocation() && !in_array($_SERVER['SERVER_NAME'], array('localhost', '127.0.0.1'))) {
             $context->cookie->cart_id = null;
             $cart = null;
         } elseif ($context->cookie->customer_id != $cart->customer_id || $context->cookie->lang_id != $cart->lang_id || $currency->currency_id != $cart->currency_id) {
             if ($context->cookie->customer_id) {
                 $cart->customer_id = (int) $context->cookie->customer_id;
             }
             $cart->lang_id = (int) $context->cookie->lang_id;
             $cart->currency_id = (int) $currency->currency_id;
             $cart->update();
         }
         if (isset($cart) && (!isset($cart->address_delivery_id) || $cart->address_delivery_id == 0 || !isset($cart->address_invoice_id) || $cart->address_invoice_id) && $context->cookie->customer_id) {
             $toUpdate = false;
             if (!isset($cart->address_delivery_id) || $cart->address_delivery_id == 0) {
                 $toUpdate = true;
                 $cart->address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id);
             }
             if (!isset($cart->address_invoice_id) || $cart->address_invoice_id == 0) {
                 $toUpdate = true;
                 $cart->address_invoice_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id);
             }
             if ($toUpdate) {
                 $cart->update();
             }
         }
     }
     if (!isset($cart) || $cart->cart_id) {
         $cart = new JeproshopCartModelCart();
         $cart->lang_id = (int) $context->cookie->lang_id;
         $cart->currency_id = (int) $context->cookie->currency_id;
         $cart->guest_id = (int) $context->cookie->guest_id;
         $cart->shop_group_id = (int) $context->shop->shop_group_id;
         $cart->shop_id = $context->shop->shop_id;
         if ($context->cookie->customer_id) {
             $cart->customer_id = (int) $context->cookie->id_customer;
             $cart->address_delivery_id = (int) JeproshopAddressModelAddress::getCustomerFirstAddressId($cart->customer_id);
             $cart->address_invoice_id = $cart->address_delivery_id;
         } else {
             $cart->address_delivery_id = 0;
             $cart->address_invoice_id = 0;
         }
         // Needed if the merchant want to give a free product to every visitors
         $context->cart = $cart;
         JeproshopCartRuleModelCartRule::autoAddToCart($context);
     } else {
         $context->cart = $cart;
     }
     JeproshopProductModelProduct::initPricesComputation();
     $display_tax_label = $context->country->display_tax_label;
     if (isset($cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) && $cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}) {
         $info = JeproshopAddressModelAddress::getCountryAndState($cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
         $country = new JeproshopCountryModelCountry((int) $info->country_id);
         $context->country = $country;
         if (JeproshopTools::isLoadedObject($country, 'country_id')) {
             $display_tax_label = $country->display_tax_label;
         }
     }
     $languages = JeproshopLanguageModelLanguage::getLanguages(true);
     $meta_language = array();
     foreach ($languages as $lang) {
         $meta_language[] = $lang->iso_code;
     }
     $compared_products = array();
     $comparatorMaxItem = JeproshopSettingModelSetting::getValue('comparator_max_item');
     if ($comparatorMaxItem && isset($context->cookie->compare_id)) {
         $compared_products = JeproshopProductComparedModelProductCompared::getComparedProducts($context->cookie->compare_id);
     }
     $mobileDevice = $context->getMobileDevice();
     $viewClass->assignRef('mobile_device', $mobileDevice);
     $viewClass->assignRef('cart', $cart);
     $viewClass->assignRef('currency', $currency);
     $viewClass->assignRef('display_tax_label', $display_tax_label);
     $isLogged = (bool) $context->customer->isLogged();
     $viewClass->assignRef('is_logged', $isLogged);
     $isGuest = (bool) $context->customer->isGuest();
     $viewClass->assignRef('is_guest', $isGuest);
     $priceRoundMode = JeproshopSettingModelSetting::getValue('price_round_mode');
     $viewClass->assignRef('price_round_mode', $priceRoundMode);
     $useTax = JeproshopSettingModelSetting::getValue('use_tax');
     $viewClass->assignRef('use_taxes', $useTax);
     $showTax = (int) JeproshopSettingModelSetting::getValue('display_tax') == 1 && JeproshopSettingModelSetting::getValue('use_tax');
     $viewClass->assignRef('show_tax', $showTax);
     $catalogMode = (bool) JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices;
     $viewClass->assignRef('catalog_mode', $catalogMode);
     $enableB2bMode = (bool) JeproshopSettingModelSetting::getValue('enable_b2b_mode');
     $viewClass->assignRef('enable_b2b_mode', $enableB2bMode);
     $stockManagement = JeproshopSettingModelSetting::getValue('stock_management');
     $viewClass->assignRef('stock_management', $stockManagement);
     $metaLanguages = implode(',', $meta_language);
     $viewClass->assignRef('meta_languages', $metaLanguages);
     $viewClass->assignRef('languages', $languages);
     $numberOfProducts = $cart->numberOfProducts();
     $viewClass->assignRef('cart_quantities', $numberOfProducts);
     $currencies = JeproshopCurrencyModelCurrency::getCurrencies();
     $viewClass->assignRef('currencies', $currencies);
     $comparatorMaxItem = JeproshopSettingModelSetting::getValue('comparator_max_item');
     $viewClass->assignRef('comparator_max_item', $comparatorMaxItem);
     $quickView = (bool) JeproshopSettingModelSetting::getValue('quick_view');
     $viewClass->assignRef('quick_view', $quickView);
     $restrictedCountryMode = false;
     $viewClass->assignRef('restricted_country_mode', $restrictedCountryMode);
     $displayPrice = JeproshopProductModelProduct::getTaxCalculationMethod((int) $context->cookie->customer_id);
     $viewClass->assignRef('display_price', $displayPrice);
     /*$viewClass->assignRef('');
       $viewClass->assignRef('');
       $viewClass->assignRef('');*/
     $viewClass->assignRef('compared_products', $compared_products);
     /*$viewClass->assignRef('comparator_max_item', $comparatorMaxItem); */
 }