Пример #1
0
 public function display($tpl = null)
 {
     if (!isset($this->context) || $this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     if (!$this->context->controller->isInitialized()) {
         $this->context->controller->initialize();
     }
     $app = JFactory::getApplication();
     $useSSL = isset($this->context->controller->ssl_enabled) && $this->context->conteoller->ssl_enabled && $app->input->get('enable_ssl') || JeproshopTools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     /*$contextParams = $this->context->controller->getContextParams();
       foreach ($contextParams as $assign_key => $assign_value){
           if (!is_array($assign_value) && mb_substr($assign_value, 0, 1, 'utf-8') == '/' || $protocol_content == 'https://'){
               $this->assignRef($assign_key, $protocol_content.JeproshopTools::getMediaServer($assign_value).$assign_value);
           }else{
               $this->assignRef($assign_key, $assign_value);
           }
       }*/
     if (!isset(self::$cache_products)) {
         $category = new JeproshopCategoryModelCategory(JeproshopContext::getContext()->shop->getCategoryId(), (int) JeproshopContext::getContext()->language->lang_id);
         $nb = (int) JeproshopSettingModelSetting::getValue('number_of_products_on_page');
         self::$cache_products = JeproshopDefaultModelDefault::getProducts((int) JeproshopContext::getContext()->language->lang_id, 0, $nb ? $nb : 8, 'position');
     }
     if (self::$cache_products === false || empty(self::$cache_products)) {
         self::$cache_products = false;
     }
     $this->assignRef('products', self::$cache_products);
     $display_add_product = JeproshopSettingModelSetting::getValue('display_category_attribute');
     $this->assignRef('display_add_product', $display_add_product);
     $homeSize = JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('home'));
     $this->assignRef('homeSize', $homeSize);
     $this->assignRef('pagination', JeproshopDefaultModelDefault::$_pagination);
     parent::display($tpl);
 }
Пример #2
0
 public static function getMediaServer($filename)
 {
     if (self::$_cache_nb_media_servers === null && defined('COM_JEPROSHOP_MEDIA_SERVER_1') && defined('COM_JEPROSHOP_MEDIA_SERVER_2') && defined('COM_JEPROSHOP_MEDIA_SERVER_3')) {
         if (COM_JEPROSHOP_MEDIA_SERVER_1 == '') {
             self::$_cache_nb_media_servers = 4;
         } elseif (COM_JEPROSHOP_MEDIA_SERVER_2 == '') {
             self::$_cache_nb_media_servers = 1;
         } elseif (COM_JEPROSHOP_MEDIA_SERVER_3 == '') {
             self::$_cache_nb_media_servers = 2;
         } else {
             self::$_cache_nb_media_servers = 3;
         }
     }
     $media_server_id = abs(crc32($filename)) % self::$_cache_nb_media_servers + 1;
     if (self::$_cache_nb_media_servers && $media_server_id) {
         return constant('COM_JEPROSHOP_MEDIA_SERVER_' . $media_server_id);
     }
     return JeproshopTools::usingSecureMode() ? JeproshopTools::getShopSslDomain() : JeproshopTools::getShopDomain();
 }
Пример #3
0
 public function renderView($tpl = null)
 {
     $app = JFactory::getApplication();
     if (!isset($this->context) && null == $this->context) {
         $this->context = JeproshopContext::getContext();
     }
     if (!isset($this->context->cart)) {
         $this->context->cart = new JeproshopCartModelCart();
     }
     if (!$this->context->controller->isInitialized()) {
         $this->initialize();
     }
     $useSSL = isset($this->context->controller->ssl_enabled) && $this->context->controller->ssl_enabled && $app->input->get('enable_ssl') || JeproshopTools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     $this->loadObject();
     if (JeproshopProductPack::isPack((int) $this->product->product_id) && !JeproshopProductPack::isInStock((int) $this->product->product_id)) {
         $this->product->quantity = 0;
     }
     $this->product->description = $this->transformDescriptionWithImg($this->product->description);
     // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
     $virtual = JeproshopProductDownloadModelProductDownload::getIdFromProductId((int) $this->product->product_id);
     $this->assignRef('virtual', $virtual);
     $customization_form_target = JeproshopTools::safeOutput(urldecode($_SERVER['REQUEST_URI']));
     $this->assignRef('customization_form_target', $customization_form_target);
     $delete_picture = $app->input->get('delete_picture');
     if ($app->input->get('submit_customized_datas')) {
         // If cart has not been saved, we need to do it so that customization fields can have an id_cart
         // We check that the cookie exists first to avoid ghost carts
         if (!$this->context->cart->cart_id && isset($_COOKIE[$this->context->cookie->getName()])) {
             $this->context->cart->add();
             $this->context->cookie->cart_id = (int) $this->context->cart->cart_id;
         }
         $this->pictureUpload();
         $this->textRecord();
         $this->formTargetFormat();
     } else {
         if (isset($delete_picture) && !$this->context->cart->deleteCustomizationToProduct($this->product->product_id, $app->input->get('delete_picture'))) {
             $this->errors[] = JText::_('An error occurred while deleting the selected picture.');
         }
     }
     $pictures = array();
     $text_fields = array();
     if ($this->product->customizable) {
         $files = $this->context->cart->getProductCustomization($this->product->product_id, JeproshopProductModelProduct::CUSTOMIZE_FILE, true);
         foreach ($files as $file) {
             $pictures['pictures_' . $this->product->product_id . '_' . $file['index']] = $file['value'];
         }
         $texts = $this->context->cart->getProductCustomization($this->product->product_id, JeproshopProductModelProduct::CUSTOMIZE_TEXT_FIELD, true);
         foreach ($texts as $text_field) {
             $text_fields['textFields_' . $this->product->product_id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
         }
     }
     $this->assignRef('pictures', $pictures);
     $this->assignRef('textFields', $text_fields);
     $this->product->customization_required = false;
     $customizationFields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->lang_id) : false;
     if (is_array($customizationFields)) {
         foreach ($customizationFields as $customizationField) {
             if ($this->product->customization_required = $customizationField['required']) {
                 break;
             }
         }
     }
     // Assign template vars related to the category + execute hooks related to the category
     $this->assignCategory();
     // Assign template vars related to the price and tax
     $this->assignPriceAndTax();
     // Assign template vars related to the images
     $this->assignImages();
     // Assign attribute groups to the template
     $this->assignAttributesGroups();
     // Assign attributes combinations to the template
     $this->assignAttributesCombinations();
     // Pack management
     $pack_items = $this->product->cache_is_pack ? JeproshopProductPack::getItemTable($this->product->product_id, $this->context->language->lang_id, true) : array();
     $this->assignRef('packItems', $pack_items);
     $packs = JeproshopProductPack::getPacksTable($this->product->product_id, $this->context->language->lang_id, true, 1);
     $this->assignRef('packs', $packs);
     if (isset($this->category->category_id) && $this->category->category_id) {
         $return_link = JeproshopTools::safeOutput($this->context->controller->getCategoryLink($this->category));
     } else {
         $return_link = 'javascript: history.back();';
     }
     if (!$this->context->controller->useMobileTheme()) {
     }
     //'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
     //		'customizationFields' => $customizationFields,
     $accessories = $this->product->getAccessories($this->context->language->lang_id);
     $this->assignRef('accessories', $accessories);
     $enable_jqzoom = JeproshopSettingModelSetting::getValue('enable_jqzoom');
     $this->assignRef('jqZoomEnabled', $enable_jqzoom);
     $manufacturer = new JeproshopManufacturerModelManufacturer((int) $this->product->manufacturer_id, $this->context->language->lang_id);
     $this->assignRef('product_manufacturer', $manufacturer);
     $features = $this->product->getFrontFeatures($this->context->language->lang_id);
     $this->assignRef('features', $features);
     $attachments = $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->lang_id) : array();
     $this->assignRef('attachments', $attachments);
     $display_discount_price = JeproshopSettingModelSetting::getValue('display_discount_price');
     $this->assignRef('display_discount_price', $display_discount_price);
     $this->assignRef('return_link', $return_link);
     $content_only = $app->input->get('content_only');
     $this->assignRef('content_only', $content_only);
     $last_quantities = JeproshopSettingModelSetting::getValue('last_quantities');
     $this->assignRef('last_quantities', $last_quantities);
     $display_quantities = JeproshopSettingModelSetting::getValue('display_quantities');
     $this->assignRef('display_quantities', $display_quantities);
     $allow_out_of_stock_ordering = JeproshopSettingModelSetting::getValue('allow_out_of_stock_ordering');
     $this->assignRef('allow_out_of_stock_ordering', $allow_out_of_stock_ordering);
     $catalog_mode = (bool) (JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices);
     $this->assignRef('catalog_mode', $catalog_mode);
     $extra_left = null;
     $this->assignRef('extra_left', $extra_left);
     $extra_right = null;
     $this->assignRef('extra_right', $extra_right);
     parent::display($tpl);
 }
Пример #4
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); */
 }