Ejemplo n.º 1
0
 public function assignSummaryInformations()
 {
     $context = JeproshopContext::getContext();
     $summary = $context->cart->getSummaryDetails();
     $customizedDatas = JeproshopProductModelProduct::getAllCustomizedDatas($context->cart->cart_id);
     // override customization tax rate with real tax (tax rules)
     if ($customizedDatas) {
         foreach ($summary['products'] as &$productUpdate) {
             $productId = (int) (isset($productUpdate->product_id) ? $productUpdate->product_id : $productUpdate->product_id);
             $productAttributeId = (int) (isset($productUpdate->product_attribute_id) ? $productUpdate->product_attribute_id : $productUpdate->product_attribute_id);
             if (isset($customizedDatas[$productId][$productAttributeId])) {
                 $productUpdate->tax_rate = JeproshopTaxModelTax::getProductTaxRate($productId, $context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
             }
         }
         JeproshopProductModelProduct::addCustomizationPrice($summary->products, $customizedDatas);
     }
     $cart_product_context = JeproshopContext::getContext()->cloneContext();
     foreach ($summary['products'] as $key => $product) {
         $product->quantity = $product->cart_quantity;
         // for compatibility with 1.2 themes
         if ($cart_product_context->shop->shop_id != $product->shop_id) {
             $cart_product_context->shop = new JeproshopModelShop((int) $product->shop_id);
         }
         $null = null;
         $product->price_without_specific_price = JeproshopProductModelProduct::getStaticPrice($product->product_id, !JeproshopProductModelProduct::getTaxCalculationMethod(), $product->product_attribute_id, 2, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context);
         if (JeproshopProductModelProduct::getTaxCalculationMethod()) {
             $product->is_discounted = $product->price_without_specific_price != $product->price;
         } else {
             $product->is_discounted = $product->price_without_specific_price != $product->price_wt;
         }
     }
     // Get available cart rules and unset the cart rules already in the cart
     $available_cart_rules = JeproshopCartRuleModelCartRule::getCustomerCartRules($this->context->language->lang_id, isset($this->context->customer->customer_id) ? $this->context->customer->customer_id : 0, true, true, true, $this->context->cart);
     $cart_cart_rules = $context->cart->getCartRules();
     foreach ($available_cart_rules as $key => $available_cart_rule) {
         if (!$available_cart_rule->high_light || strpos($available_cart_rule->code, 'BO_ORDER_') === 0) {
             unset($available_cart_rules[$key]);
             continue;
         }
         foreach ($cart_cart_rules as $cart_cart_rule) {
             if ($available_cart_rule->cart_rule_id == $cart_cart_rule->cart_rule_id) {
                 unset($available_cart_rules[$key]);
                 continue 2;
             }
         }
     }
     $show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && JeproshopSettingModelSetting::getValue('ship_when_available');
     $this->assign($summary);
     //$this->assign('token_cart', Tools::getToken(false));
     $this->assign('is_logged', $this->context->controller->isLogged);
     $this->assign('is_virtual_cart', $this->context->cart->isVirtualCart());
     $this->assign('product_number', $this->context->cart->numberOfProducts());
     $this->assign('voucher_allowed', JeproshopCartRuleModelCartRule::isFeaturePublished());
     $this->assign('shipping_cost', $this->context->cart->getOrderTotal(true, JeproshopCartModelCart::ONLY_SHIPPING));
     $this->assign('shipping_cost_tax_excluded', $this->context->cart->getOrderTotal(false, JeproshopCartModelCart::ONLY_SHIPPING));
     $this->assign('customizedDatas', $customizedDatas);
     $this->assign('CUSTOMIZE_FILE', JeproshopProductModelProduct::CUSTOMIZE_FILE);
     $this->assign('CUSTOMIZE_TEXT_FIELD', JeproshopProductModelProduct::CUSTOMIZE_TEXT_FIELD);
     $this->assign('last_product_added', $this->context->cart->getLastProduct());
     $this->assign('display_vouchers', $available_cart_rules);
     $this->assign('currency_sign', $this->context->currency->sign);
     $this->assign('currency_rate', $this->context->currency->conversion_rate);
     $this->assign('currency_format', $this->context->currency->format);
     $this->assign('currency_blank', $this->context->currency->blank);
     $this->assign('show_option_allow_separate_package', $show_option_allow_separate_package);
     $this->assign('small_size', JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('small')));
     /*
             $this->context->smarty->assign(array(
                 'HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary),
                 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary)
             ));*/
 }
Ejemplo n.º 2
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); */
 }