Exemplo n.º 1
0
 public function display($tpl = null)
 {
     if (!isset($this->context) && $this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     /*if($this->context->controller->isInitialized()){*/
     $this->init();
     //}
     if (!$this->customer_access) {
         return;
     }
     if (isset($this->context->cookie->compare_id)) {
         $this->assignRef('compare_products', JeproshopCompareProductModelCompareProduct::getCompareProducts((int) $this->context->cookie->compare_id));
     }
     $this->assignScenes();
     $this->sortProducts();
     $subCategories = $this->category->getSubCategories($this->context->language->lang_id);
     if (count($subCategories)) {
         $this->assignRef('sub_categories', $subCategories);
         $this->assignRef('sub_categories_total', count($subCategories));
         $this->assignRef('sub_categories_half', ceil(count($subCategories) / 2));
     }
     $this->assignProducts();
     $catalog_mode = (bool) (JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices);
     $this->assignRef('catalog_mode', $catalog_mode);
     $this->assignRef('allow_out_of_stock_ordering', JeproshopSettingModelSetting::getValue('allow_out_of_stock_ordering'));
     $comparator_max_item = (int) JeproshopSettingModelSetting::getValue('comparator_max_item');
     $this->assignRef('comparator_max_item', $comparator_max_item);
     $compared_products = array();
     if (JeproshopSettingModelSetting::getValue('comparator_max_item') && isset($this->context->cookie->compare_id)) {
         $compared_products = JeproshopProductCompareModelProductCompare::getCompareProducts($this->context->cookie->compare_id);
     }
     $this->assignRef('compared_products', is_array($compared_products) ? $compared_products : array());
     $this->assignRef('display_price', JeproshopSettingModelSetting::getValue('display_price'));
     parent::display($tpl);
 }
Exemplo n.º 2
0
 public function __construct($cart_id = null)
 {
     $db = JFactory::getDBO();
     /*$this->def = ObjectModel::getDefinition($this);
     		$this->setDefinitionRetroCompatibility();
     
     		if ($id_lang !== null)
     			$this->id_lang = (Language::getLanguage($id_lang) !== false) ? $id_lang : Configuration::get('PS_LANG_DEFAULT');
     
     		if ($id_shop && $this->isMultishop())
     		{
     			$this->id_shop = (int)$id_shop;
     			$this->get_shop_from_context = false;
     		} */
     if ($this->isMultishop() && !$this->shop_id) {
         $this->shop_id = JeproshopContext::getContext()->shop->shop_id;
     }
     if ($cart_id) {
         // Load object from database if object id is present
         $cache_id = 'jeproshop_model_cart_' . (int) $cart_id . '_' . (int) $this->shop_id;
         if (!JeproshopCache::isStored($cache_id)) {
             $query = "SELECT * FROM " . $db->quoteName('#__jeproshop_cart') . " AS cart WHERE cart.cart_id = " . (int) $cart_id;
             // Get lang informations
             /*if ($id_lang)
             		{
             			$sql->leftJoin($this->def['table'].'_lang', 'b', 'a.'.$this->def['primary'].' = b.'.$this->def['primary'].' AND b.id_lang = '.(int)$id_lang);
             			if ($this->id_shop && !empty($this->def['multilang_shop']))
             				$sql->where('b.id_shop = '.$this->id_shop);
             		} */
             // Get shop informations
             if (JeproshopShopModelShop::isTableAssociated('cart')) {
                 $query .= " LEFT JOIN " . $db->quoteName('#__jeproshop_cart_shop') . " AS cart_shop ON(cart.cart_id =";
                 $query .= " = cart_shop.cart_id AND cart_shop.shop_id = " . (int) $this->shop_id . ")";
             }
             $db->setQuery($query);
             $cart_data = $db->loadObject();
             if ($cart_data) {
                 /*if (!$id_lang && isset($this->def['multilang']) && $this->def['multilang'])
                 		{
                 			$sql = 'SELECT * FROM `'.pSQL(_DB_PREFIX_.$this->def['table']).'_lang`
                 					WHERE `'.bqSQL($this->def['primary']).'` = '.(int)$id
                 					.(($this->id_shop && $this->isLangMultishop()) ? ' AND `id_shop` = '.$this->id_shop : '');
                 			if ($object_datas_lang = ObjectModel::$db->executeS($sql))
                 				foreach ($object_datas_lang as $row)
                 					foreach ($row as $key => $value)
                 					{
                 						if (array_key_exists($key, $this) && $key != $this->def['primary'])
                 						{
                 							if (!isset($object_datas[$key]) || !is_array($object_datas[$key]))
                 								$object_datas[$key] = array();
                 							$object_datas[$key][$row['id_lang']] = $value;
                 						}
                 					}
                 		} */
                 JeproshopCache::store($cache_id, $cart_data);
             }
         } else {
             $cart_data = JeproshopCache::retrieve($cache_id);
         }
         if ($cart_data) {
             $this->cart_id = (int) $cart_id;
             foreach ($cart_data as $key => $value) {
                 if (array_key_exists($key, $this)) {
                     $this->{$key} = $value;
                 }
             }
         }
     }
     /*
     if (!is_null($id_lang))
     	$this->id_lang = (int)(Language::getLanguage($id_lang) !== false) ? $id_lang : Configuration::get('PS_LANG_DEFAULT');
     */
     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);
 }
Exemplo n.º 3
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;
 }
Exemplo n.º 4
0
 private function initContent()
 {
     $order_process_type = (bool) JeproshopSettingModelSetting::getValue('order_process_type');
     $this->assignRef('order_process_type', $order_process_type);
     $isGuest = false;
     $this->assignRef('is_guest', $isGuest);
     $catalog_mode = (bool) (JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices);
     $this->assignRef('catalog_mode', $catalog_mode);
 }
Exemplo n.º 5
0
 /**
  * Get product price
  *
  * @param integer $product_id Product id
  * @param boolean $use_tax With taxes or not (optional)
  * @param integer $product_attribute_id Product attribute id (optional).
  *    If set to false, do not apply the combination price impact. NULL does apply the default combination price impact.
  * @param integer $decimals Number of decimals (optional)
  * @param boolean $only_reduction Returns only the reduction amount
  * @param boolean $use_reduction Set if the returned amount will include reduction
  * @param integer $quantity Required for quantity discount application (default value: 1)
  * @param integer $customer_id Customer ID (for customer group reduction)
  * @param integer $cart_id Cart ID. Required when the cookie is not accessible (e.g., inside a payment module, a cron task...)
  * @param integer $address_id Customer address ID. Required for price (tax included) calculation regarding the guest localization
  * @param null $specific_price_output
  * @param boolean $with_ecotax insert ecotax in price output.
  * @param bool $use_group_reduction
  * @param JeproshopContext $context
  * @param bool $use_customer_price
  * @internal param int $divisor Useful when paying many time without fees (optional)
  * @internal param \variable_reference $specificPriceOutput .
  *    If a specific price applies regarding the previous parameters, this variable is filled with the corresponding SpecificPrice object
  * @return float Product price
  */
 public static function getStaticPrice($product_id, $use_tax = true, $product_attribute_id = null, $decimals = 6, $only_reduction = false, $use_reduction = true, $quantity = 1, $customer_id = null, $cart_id = null, $address_id = null, $specific_price_output = null, $with_ecotax = true, $use_group_reduction = true, JeproshopContext $context = null, $use_customer_price = true)
 {
     if (!$context) {
         $context = JeproshopContext::getContext();
     }
     $cur_cart = $context->cart;
     if (!JeproshopTools::isBool($use_tax) || !JeproshopTools::isUnsignedInt($product_id)) {
         //die(Tools::displayError());
     }
     // Initializations
     $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id;
     // If there is cart in context or if the specified id_cart is different from the context cart id
     if (!is_object($cur_cart) || JeproshopTools::isUnsignedInt($cart_id) && $cart_id && $cur_cart->cart_id != $cart_id) {
         /*
          * When a user (e.g., guest, customer, Google...) is on Jeproshop, he has already its cart as the global (see /init.php)
          * When a non-user calls directly this method (e.g., payment module...) is on JeproShop, he does not have already it BUT knows the cart ID
          * When called from the back office, cart ID can be inexistant
          */
         if (!$cart_id && !isset($context->employee)) {
             JError::raiseError(500, __FILE__ . ' ' . __LINE__);
         }
         $cur_cart = new JeproshopCartModelCart($cart_id);
         // Store cart in context to avoid multiple instantiations in BO
         if (!JeproshopTools::isLoadedObject($context->cart, 'cart_id')) {
             $context->cart = $cur_cart;
         }
     }
     $db = JFactory::getDBO();
     $cart_quantity = 0;
     if ((int) $cart_id) {
         $cache_id = 'jeproshop_product_model_get_price_static_' . (int) $product_id . '_' . (int) $cart_id;
         $cart_qty = JeproshopCache::retrieve($cache_id);
         if (!JeproshopCache::isStored($cache_id) || $cart_qty != (int) $quantity) {
             $query = "SELECT SUM(" . $db->quoteName('quantity') . ") FROM " . $db->quoteName('#__jeproshop_cart_product');
             $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id . " AND " . $db->quoteName('cart_id');
             $query .= " = " . (int) $cart_id;
             $db->setQuery($query);
             $cart_quantity = (int) $db->loadResult();
             JeproshopCache::store($cache_id, $cart_quantity);
         }
         $cart_quantity = JeproshopCache::retrieve($cache_id);
     }
     $currency_id = (int) JeproshopTools::isLoadedObject($context->currency, 'currency_id') ? $context->currency->currency_id : JeproshopSettingModelSetting::getValue('default_currency');
     // retrieve address information
     $country_id = (int) $context->country->country_id;
     $state_id = 0;
     $zipcode = 0;
     if (!$address_id && JeproshopTools::isLoadedObject($cur_cart, 'cart_id')) {
         $address_id = $cur_cart->{JeproshopSettingModelSetting::getValue('tax_address_type')};
     }
     if ($address_id) {
         $address_info = JeproshopAddressModelAddress::getCountryAndState($address_id);
         if ($address_info->country_id) {
             $country_id = (int) $address_info->country_id;
             $state_id = (int) $address_info->state_id;
             $zipcode = $address_info->postcode;
         }
     } else {
         if (isset($context->customer->geoloc_country_id)) {
             $country_id = (int) $context->customer->geoloc_country_id;
             $state_id = (int) $context->customer->state_id;
             $zipcode = (int) $context->customer->postcode;
         }
     }
     if (JeproshopTaxModelTax::taxExcludedOption()) {
         $use_tax = false;
     }
     if ($use_tax != false && !empty($address_info->vat_number) && $address_info->country_id != JeproshopSettingModelSetting::getValue('vat_number_country') && JeproshopSettingModelSetting::getValue('vat_number_management')) {
         $use_tax = false;
     }
     if (is_null($customer_id) && JeproshopTools::isLoadedObject($context->customer, 'customer_id')) {
         $customer_id = $context->customer->customer_id;
     }
     return JeproshopProductModelProduct::priceCalculation($context->shop->shop_id, $product_id, $product_attribute_id, $country_id, $state_id, $zipcode, $currency_id, $group_id, $quantity, $use_tax, $decimals, $only_reduction, $use_reduction, $with_ecotax, $specific_price_output, $use_group_reduction, $customer_id, $use_customer_price, $cart_id, $cart_quantity);
 }
Exemplo n.º 6
0
 /**
  * Assign price and tax to the template
  */
 protected function assignPriceAndTax()
 {
     $customer_id = isset($this->context->customer) ? (int) $this->context->customer->customer_id : 0;
     $group_id = (int) JeproshopGroupModelGroup::getCurrent()->group_id;
     $country_id = (int) $customer_id ? JeproshopCustomerModelCustomer::getCurrentCountry($customer_id) : JeproshopSettingModelSetting::getValue('default_country');
     $group_reduction = JeproshopGroupReductionModelGroupReduction::getValueForProduct($this->product->product_id, $group_id);
     if ($group_reduction === false) {
         $group_reduction = JeproshopGroupModelGroup::getReduction((int) $this->context->cookie->customer_id) / 100;
     }
     // Tax
     $tax = (double) $this->product->getTaxesRate(new JeproshopAddressModelAddress((int) $this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')}));
     $this->assignRef('tax_rate', $tax);
     $product_price_with_tax = JeproshopProductModelProduct::getStaticPrice($this->product->product_id, true, null, 6);
     if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED) {
         $product_price_with_tax = JeproshopTools::roundPrice($product_price_with_tax, 2);
     }
     $product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax;
     $ecotax_rate = (double) JeproshopTaxModelTax::getProductEcotaxRate($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
     $ecotax_tax_amount = JeproshopTools::roundPrice($this->product->ecotax, 2);
     if (JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED && (int) JeproshopSettingModelSetting::getValue('use_tax')) {
         $ecotax_tax_amount = JeproshopTools::roundPrice($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2);
     }
     $currency_id = (int) $this->context->cookie->currency_id;
     $product_id = (int) $this->product->product_id;
     $shop_id = $this->context->shop->shop_id;
     $quantity_discounts = JeproshopSpecificPriceModelSpecificPrice::getQuantityDiscounts($product_id, $shop_id, $currency_id, $country_id, $group_id, null, true, (int) $this->context->customer->customer_id);
     foreach ($quantity_discounts as &$quantity_discount) {
         if ($quantity_discount->product_attribute_id) {
             $combination = new JeproshopCombinationModelCombination((int) $quantity_discount->product_attribute_id);
             $attributes = $combination->getAttributesName((int) $this->context->language->lang_id);
             foreach ($attributes as $attribute) {
                 $quantity_discount->attributes = $attribute->name . ' - ';
             }
             $quantity_discount->attributes = rtrim($quantity_discount->attributes, ' - ');
         }
         if ((int) $quantity_discount->currency_id == 0 && $quantity_discount->reduction_type == 'amount') {
             $quantity_discount->reduction = JeproshopTools::convertPriceFull($quantity_discount->reduction, null, JeproshopContext::getContext()->currency);
         }
     }
     $product_price = $this->product->getPrice(JeproshopProductModelProduct::$_taxCalculationMethod == COM_JEPROSHOP_TAX_INCLUDED, false);
     $address = new JeproshopAddressModelAddress($this->context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
     $quantity_discounts = $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount);
     $this->assignRef('quantity_discounts', $quantity_discounts);
     $this->assignRef('ecotax_tax_included', $ecotax_tax_amount);
     $ecotax_tax_excluded = JeproshopTools::roundPrice($this->product->ecotax, 2);
     $this->assignRef('ecotax_tax_excluded', $ecotax_tax_excluded);
     $this->assignRef('ecotaxTax_rate', $ecotax_rate);
     $display_price = JeproshopSettingModelSetting::getValue('display_price');
     $this->assignRef('display_price', $display_price);
     $product_price_without_eco_tax = (double) $product_price_without_eco_tax;
     $this->assignRef('product_price_without_ecotax', $product_price_without_eco_tax);
     $this->assignRef('group_reduction', $group_reduction);
     $no_tax = JeproshopTaxModelTax::taxExcludedOption() || !$this->product->getTaxesRate($address);
     $this->assignRef('no_tax', $no_tax);
     $ecotax = !count($this->errors) && $this->product->ecotax > 0 ? JeproshopTools::convertPrice((double) $this->product->ecotax) : 0;
     $this->assignRef('ecotax', $ecotax);
     $tax_enabled = JeproshopSettingModelSetting::getValue('use_tax');
     $this->assignRef('tax_enabled', $tax_enabled);
     $customer_group_without_tax = JeproshopGroupModelGroup::getPriceDisplayMethod($this->context->customer->default_group_id);
     $this->assignRef('customer_group_without_tax', $customer_group_without_tax);
 }
Exemplo n.º 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);
 }
Exemplo n.º 8
0
 public function renderView($tpl = null)
 {
     if (!$this->loadObject(true)) {
         return;
     }
     if (!isset($this->context)) {
         $this->context = JeproshopContext::getContext();
     }
     $customer = new JeproshopCustomerModelCustomer($this->cart->customer_id);
     $currency = new JeproshopCurrencyModelCurrency($this->cart->currency_id);
     $this->context->cart = $this->cart;
     $this->context->currency = $currency;
     $this->context->customer = $customer;
     //$this->toolbar_title = sprintf($this->l('Cart #%06d'), $this->context->cart->cart_id);
     $products = $this->cart->getProducts();
     $customized_datas = JeproshopProductModelProduct::getAllCustomizedDatas((int) $this->cart->cart_id);
     JeproshopProductModelProduct::addCustomizationPrice($products, $customized_datas);
     $summary = $this->cart->getSummaryDetails();
     /* Display order information */
     $order_id = (int) JeproshopOrderModelOrder::getOrderIdByCartId($this->cart->cart_id);
     $order = new JeproshopOrderModelOrder($order_id);
     if (JeproshopTools::isLoadedObject($order, 'order_id')) {
         $tax_calculation_method = $order->getTaxCalculationMethod();
         $shop_id = (int) $order->shop_id;
     } else {
         $shop_id = (int) $this->cart->shop_id;
         $tax_calculation_method = JeproshopGroupModelGroup::getPriceDisplayMethod(JeproshopGroupModelGroup::getCurrent()->group_id);
     }
     if ($tax_calculation_method == COM_JEPROSHOP_TAX_EXCLUDED) {
         $total_products = $summary->total_products;
         $total_discounts = $summary->total_discounts_tax_exc;
         $total_wrapping = $summary->total_wrapping_tax_exc;
         $total_price = $summary->total_price_without_tax;
         $total_shipping = $summary->total_shipping_tax_exc;
     } else {
         $total_products = $summary->total_products_wt;
         $total_discounts = $summary->total_discounts;
         $total_wrapping = $summary->total_wrapping;
         $total_price = $summary->total_price;
         $total_shipping = $summary->total_shipping;
     }
     foreach ($products as $k => &$product) {
         if ($tax_calculation_method == COM_JEPROSHOP_TAX_EXCLUDED) {
             $product->product_price = $product->price;
             $product->product_total = $product->total;
         } else {
             $product->product_price = $product->price_wt;
             $product->product_total = $product->total_wt;
         }
         $image = array();
         $db = JFactory::getDBO();
         if (isset($product->product_attribute_id) && (int) $product->product_attribute_id) {
             $query = "SELECT " . $db->quoteName('image_id') . " FROM " . $db->quoteName('#__jeproshop_product_attribute_image') . " WHERE product_attribute_id = " . (int) $product->product_attribute_id;
             $db->setQuery($query);
             $image = $db->loadObject();
         }
         if (!isset($image->image_id)) {
             $query = "SELECT " . $db->quoteName('image_id') . " FROM " . $db->quoteName('#__jeproshop_image') . " WHERE " . $db->quoteName('product_id') . " = " . (int) $product->product_id . " AND cover = 1 ";
             $db->setQuery($query);
             $image = $db->loadObject();
         }
         $product_obj = new JeproshopProductModelProduct($product->product_id);
         $product->qty_in_stock = JeproshopStockAvailableModelStockAvailable::getQuantityAvailableByProduct($product->product_id, isset($product->product_attribute_id) ? $product->product_attribute_id : null, (int) $shop_id);
         $image_product = new JeproshopImageModelImage($image->image_id);
         $product->image = isset($image->image_id) ? JeproshopImageManager::thumbnail(COM_JEPROSHOP_IMAGE_DIR . 'products/' . $image_product->getExistingImagePath() . '.jpg', 'product_mini_' . (int) $product->product_id . (isset($product->product_attribute_id) ? '_' . (int) $product->product_attribute_id : '') . '.jpg', 45, 'jpg') : '--';
     }
     /*$helper = new HelperKpi();
       $helper->id = 'box-kpi-cart';
       $helper->icon = 'icon-shopping-cart';
       $helper->color = 'color1';
       $helper->title = $this->l('Total Cart', null, null, false);
       $helper->subtitle = sprintf($this->l('Cart #%06d', null, null, false), $cart->id);
       $helper->value = Tools::displayPrice($total_price, $currency);
       $kpi = $helper->generate(); */
     //$this->assignRef('kpi', $kpi);
     $this->assignRef('products', $products);
     $discounts = $this->cart->getCartRules();
     $this->assignRef('discounts', $discounts);
     $this->assignRef('order', $order);
     $this->assignRef('currency', $currency);
     $this->assignRef('customer', $customer);
     $customerStats = $customer->getStats();
     $this->assignRef('customer_stats', $customerStats);
     $this->assignRef('total_products', $total_products);
     $this->assignRef('total_discounts', $total_discounts);
     $this->assignRef('total_wrapping', $total_wrapping);
     $this->assignRef('total_price', $total_price);
     $this->assignRef('total_shipping', $total_shipping);
     $this->assignRef('customized_datas', $customized_datas);
     if ($this->getLayout() != 'modal') {
         $this->addToolBar();
         $this->sideBar = JHtmlSidebar::render();
     }
     parent::display($tpl);
 }
Exemplo n.º 9
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); */
 }