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) ));*/ }
public function getDeliveryOptionList(JeproshopCountryModelCountry $default_country = null, $flush = false) { static $cache = null; if ($cache !== null && !$flush) { return $cache; } $delivery_option_list = array(); $carriers_price = array(); $carrier_collection = array(); $package_list = $this->getPackageList(); // Foreach addresses foreach ($package_list as $address_id => $packages) { // Initialize vars $delivery_option_list[$address_id] = array(); $carriers_price[$address_id] = array(); $common_carriers = null; $best_price_carriers = array(); $best_grade_carriers = array(); $carriers_instance = array(); // Get country if ($address_id) { $address = new JeproshopAddressModelAddress($address_id); $country = new JeproshopCountryModelCountry($address->country_id); } else { $country = $default_country; } // Foreach packages, get the carriers with best price, best position and best grade foreach ($packages as $package_id => $package) { // No carriers available if (count($package['carrier_list']) == 1 && current($package['carrier_list']) == 0) { $cache = array(); return $cache; } $carriers_price[$address_id][$package_id] = array(); // Get all common carriers for each packages to the same address if (is_null($common_carriers)) { $common_carriers = $package['carrier_list']; } else { $common_carriers = array_intersect($common_carriers, $package['carrier_list']); } $best_price = null; $best_price_carrier = null; $best_grade = null; $best_grade_carrier = null; // Foreach carriers of the package, calculate his price, check if it the best price, position and grade foreach ($package['carrier_list'] as $carrier_id) { if (!isset($carriers_instance[$carrier_id])) { $carriers_instance[$carrier_id] = new JeproshopCarrierModelCarrier($carrier_id); } $price_with_tax = $this->getPackageShippingCost($carrier_id, true, $country, $package['product_list']); $price_without_tax = $this->getPackageShippingCost($carrier_id, false, $country, $package['product_list']); if (is_null($best_price) || $price_with_tax < $best_price) { $best_price = $price_with_tax; $best_price_carrier = $carrier_id; } $carriers_price[$address_id][$package_id][$carrier_id] = array('without_tax' => $price_without_tax, 'with_tax' => $price_with_tax); $grade = $carriers_instance[$carrier_id]->grade; if (is_null($best_grade) || $grade > $best_grade) { $best_grade = $grade; $best_grade_carrier = $carrier_id; } } $best_price_carriers[$package_id] = $best_price_carrier; $best_grade_carriers[$package_id] = $best_grade_carrier; } // Reset $best_price_carrier, it's now an array $best_price_carrier = array(); $key = ''; // Get the delivery option with the lower price foreach ($best_price_carriers as $package_id => $carrier_id) { $key .= $carrier_id . ','; if (!isset($best_price_carrier[$carrier_id])) { $best_price_carrier[$carrier_id] = array('price_with_tax' => 0, 'price_without_tax' => 0, 'package_list' => array(), 'product_list' => array()); } $best_price_carrier[$carrier_id]['price_with_tax'] += $carriers_price[$address_id][$package_id][$carrier_id]['with_tax']; $best_price_carrier[$carrier_id]['price_without_tax'] += $carriers_price[$address_id][$package_id][$carrier_id]['without_tax']; $best_price_carrier[$carrier_id]['package_list'][] = $package_id; $best_price_carrier[$carrier_id]['product_list'] = array_merge($best_price_carrier[$carrier_id]['product_list'], $packages[$package_id]['product_list']); $best_price_carrier[$carrier_id]['instance'] = $carriers_instance[$carrier_id]; } // Add the delivery option with best price as best price $delivery_option_list[$address_id][$key] = array('carrier_list' => $best_price_carrier, 'is_best_price' => true, 'is_best_grade' => false, 'unique_carrier' => count($best_price_carrier) <= 1); // Reset $best_grade_carrier, it's now an array $best_grade_carrier = array(); $key = ''; // Get the delivery option with the best grade foreach ($best_grade_carriers as $package_id => $carrier_id) { $key .= $carrier_id . ','; if (!isset($best_grade_carrier[$carrier_id])) { $best_grade_carrier[$carrier_id] = array('price_with_tax' => 0, 'price_without_tax' => 0, 'package_list' => array(), 'product_list' => array()); } $best_grade_carrier[$carrier_id]['price_with_tax'] += $carriers_price[$address_id][$package_id][$carrier_id]['with_tax']; $best_grade_carrier[$carrier_id]['price_without_tax'] += $carriers_price[$address_id][$package_id][$carrier_id]['without_tax']; $best_grade_carrier[$carrier_id]['package_list'][] = $package_id; $best_grade_carrier[$carrier_id]['product_list'] = array_merge($best_grade_carrier[$carrier_id]['product_list'], $packages[$package_id]['product_list']); $best_grade_carrier[$carrier_id]['instance'] = $carriers_instance[$carrier_id]; } // Add the delivery option with best grade as best grade if (!isset($delivery_option_list[$address_id][$key])) { $delivery_option_list[$address_id][$key] = array('carrier_list' => $best_grade_carrier, 'is_best_price' => false, 'unique_carrier' => count($best_grade_carrier) <= 1); } $delivery_option_list[$address_id][$key]['is_best_grade'] = true; // Get all delivery options with a unique carrier foreach ($common_carriers as $carrier_id) { $key = ''; $package_list = array(); $product_list = array(); $price_with_tax = 0; $price_without_tax = 0; foreach ($packages as $package_id => $package) { $key .= $carrier_id . ','; $price_with_tax += $carriers_price[$address_id][$package_id][$carrier_id]['with_tax']; $price_without_tax += $carriers_price[$address_id][$package_id][$carrier_id]['without_tax']; $package_list[] = $package_id; $product_list = array_merge($product_list, $package['product_list']); } if (!isset($delivery_option_list[$address_id][$key])) { $delivery_option_list[$address_id][$key] = array('is_best_price' => false, 'is_best_grade' => false, 'unique_carrier' => true, 'carrier_list' => array($carrier_id => array('price_with_tax' => $price_with_tax, 'price_without_tax' => $price_without_tax, 'instance' => $carriers_instance[$carrier_id], 'package_list' => $package_list, 'product_list' => $product_list))); } else { $delivery_option_list[$address_id][$key]['unique_carrier'] = count($delivery_option_list[$address_id][$key]['carrier_list']) <= 1; } } } $cart_rules = JeproshopCartRuleModelCartRule::getCustomerCartRules(JeproshopContext::getContext()->cookie->lang_id, JeproshopContext::getContext()->cookie->customer_id, true, true, false, $this); $free_carriers_rules = array(); foreach ($cart_rules as $cart_rule) { if ($cart_rule->free_shipping && $cart_rule->carrier_restriction) { $cartRule = new JeproshopCartRuleModelCartRule((int) $cart_rule->cart_rule_id); if (JeproshopValidator::isLoadedObject($cartRule, 'cart_rule_id')) { $carriers = $cart_rule->getAssociatedRestrictions('carrier', true, false); if (is_array($carriers) && count($carriers) && isset($carriers['selected'])) { foreach ($carriers['selected'] as $carrier) { if (isset($carrier->carrier_id) && $carrier->carrier_id) { $free_carriers_rules[] = (int) $carrier->carrier_id; } } } } } } // For each delivery options : // - Set the carrier list // - Calculate the price // - Calculate the average position foreach ($delivery_option_list as $address_id => $delivery_option) { foreach ($delivery_option as $key => $value) { $total_price_with_tax = 0; $total_price_without_tax = 0; $position = 0; foreach ($value['carrier_list'] as $carrier_id => $data) { $total_price_with_tax += $data['price_with_tax']; $total_price_without_tax += $data['price_without_tax']; $total_price_without_tax_with_rules = in_array($carrier_id, $free_carriers_rules) ? 0 : $total_price_without_tax; if (!isset($carrier_collection[$carrier_id])) { $carrier_collection[$carrier_id] = new Carrier($carrier_id); } $delivery_option_list[$address_id][$key]['carrier_list'][$carrier_id]['instance'] = $carrier_collection[$carrier_id]; if (file_exists(_PS_SHIP_IMG_DIR_ . $carrier_id . '.jpg')) { $delivery_option_list[$address_id][$key]['carrier_list'][$carrier_id]['logo'] = _THEME_SHIP_DIR_ . $carrier_id . '.jpg'; } else { $delivery_option_list[$address_id][$key]['carrier_list'][$carrier_id]['logo'] = false; } $position += $carrier_collection[$carrier_id]->position; } $delivery_option_list[$address_id][$key]['total_price_with_tax'] = $total_price_with_tax; $delivery_option_list[$address_id][$key]['total_price_without_tax'] = $total_price_without_tax; $delivery_option_list[$address_id][$key]['is_free'] = !$total_price_without_tax_with_rules ? true : false; $delivery_option_list[$address_id][$key]['position'] = $position / count($value['carrier_list']); } } // Sort delivery option list foreach ($delivery_option_list as &$array) { uasort($array, array('Cart', 'sortDeliveryOptionList')); } $cache = $delivery_option_list; return $delivery_option_list; }
public function renderView($tpl = null) { if ($this->getLayout() !== 'modal') { } if ($this->context == null) { $this->context = JeproshopContext::getContext(); } $db = JFactory::getDBO(); $this->setLayout('view'); $this->loadObject(); if (!JeproshopTools::isLoadedObject($this->customer, 'customer_id')) { return; } $this->context->customer = $this->customer; $customer_stats = $this->customer->getStats(); $query = "SELECT SUM(total_paid_real) FROM " . $db->quoteName('#__jeproshop_orders'); $query .= " WHERE customer_id = " . (int) $this->customer->customer_id . " AND valid = 1"; $db->setQuery($query); $total_customer = $db->loadResult(); if ($total_customer) { $query = "SELECT SQL_CALC_FOUND_ROWS COUNT(*) FROM " . $db->quoteName('#__jeproshop_orders'); $query .= " WHERE valid = 1 AND customer_id != " . (int) $this->customer->customer_id . " GROUP BY "; $query .= "customer_id HAVING SUM(total_paid_real) > " . (int) $total_customer; $db->setQuery($query); $db->loadResult(); $count_better_customers = (int) $db->loadResult('SELECT FOUND_ROWS()') + 1; } else { $count_better_customers = '-'; } $orders = JeproshopOrderModelOrder::getCustomerOrders($this->customer->customer_id, true); $total_orders = count($orders); for ($i = 0; $i < $total_orders; $i++) { $orders[$i]->total_paid_real_not_formated = $orders[$i]->total_paid_real; $orders[$i]->total_paid_real = JeproshopTools::displayPrice($orders[$i]->total_paid_real, new JeproshopCurrencyModelCurrency((int) $orders[$i]->currency_id)); } $messages = JeproshopCustomerThreadModelCustomerThread::getCustomerMessages((int) $this->customer->customer_id); $total_messages = count($messages); for ($i = 0; $i < $total_messages; $i++) { $messages[$i]->message = substr(strip_tags(html_entity_decode($messages[$i]->message, ENT_NOQUOTES, 'UTF-8')), 0, 75); $messages[$i]->date_add = Tools::displayDate($messages[$i]->date_add, null, true); } $groups = $this->customer->getGroups(); $total_groups = count($groups); for ($i = 0; $i < $total_groups; $i++) { $group = new JeproshopGroupModelGroup($groups[$i]); $groups[$i] = array(); $groups[$i]['group_id'] = $group->group_id; $groups[$i]['name'] = $group->name[$this->context->controller->default_form_language]; } $total_ok = 0; $orders_ok = array(); $orders_ko = array(); foreach ($orders as $order) { if (!isset($order->order_state)) { $order->order_state = JText::_('COM_JEPROSHOP_THERE_IS_NO_STATUS_DEFINED_FOR_THIS_ORDER_MESSAGE'); } if ($order->valid) { $orders_ok[] = $order; $total_ok += $order->total_paid_real_not_formated; } else { $orders_ko[] = $order; } } $products = $this->customer->getBoughtProducts(); $carts = JeproshopCartModelCart::getCustomerCarts($this->customer->customer_id); $total_carts = count($carts); for ($i = 0; $i < $total_carts; $i++) { $cart = new JeproshopCartModelCart((int) $carts[$i]->cart_id); $this->context->cart = $cart; $summary = $cart->getSummaryDetails(); $currency = new JeproshopCurrencyModelCurrency((int) $carts[$i]->currency_id); $carrier = new JeproshopCarrierModelCarrier((int) $carts[$i]->carrier_id); $carts[$i]['id_cart'] = sprintf('%06d', $carts[$i]['id_cart']); $carts[$i]['date_add'] = JeproshopValidator::displayDate($carts[$i]->date_add, null, true); $carts[$i]['total_price'] = Tools::displayPrice($summary->total_price, $currency); $carts[$i]->name = $carrier->name; } $query = "SELECT DISTINCT cart_product.product_id, cart.cart_id, cart.shop_id, cart_product.shop_id "; $query .= " AS cart_product_shop_id FROM " . $db->quoteName('#__jeproshop_cart_product') . " AS cart_product"; $query .= " JOIN " . $db->quoteName('#__jeproshop_cart') . " AS cart ON (cart.cart_id = cart_product.cart_id) "; $query .= "JOIN " . $db->quoteName('#__jeproshop_product') . " AS product ON (cart_product.product_id = product."; $query .= "product_id) WHERE cart.customer_id = " . (int) $this->customer->customer_id . " AND cart_product.product_id"; $query .= " NOT IN ( SELECT product_id FROM " . $db->quoteName('#__jeproshop_orders') . " AS ord JOIN "; $query .= $db->quoteName('#__jeproshop_order_detail') . " AS ord_detail ON (ord.order_id = ord_detail.order_id ) WHERE "; $query .= "ord.valid = 1 AND ord.customer_id = " . (int) $this->customer->customer_id . ")"; $db->setQuery($query); $interested = $db->loadObjectList(); $total_interested = count($interested); for ($i = 0; $i < $total_interested; $i++) { $product = new JeproshopProductModelProduct($interested[$i]->product_id, false, $this->context->controller->default_form_language, $interested[$i]->shop_id); if (!Validate::isLoadedObject($product, 'product_id')) { continue; } $interested[$i]->url = $this->context->controller->getProductLink($product->product_id, $product->link_rewrite, JeproshopCategoryModelCategory::getLinkRewrite($product->default_category_id, $this->context->controller->default_form_language), null, null, $interested[$i]->cp_shop_id); $interested[$i]->product_id = (int) $product->product_id; $interested[$i]->name = htmlentities($product->name); } $connections = $this->customer->getLastConnections(); if (!is_array($connections)) { $connections = array(); } $total_connections = count($connections); for ($i = 0; $i < $total_connections; $i++) { $connections[$i]->http_referer = $connections[$i]->http_referer ? preg_replace('/^www./', '', parse_url($connections[$i]->http_referer, PHP_URL_HOST)) : JText::_('COM_JEPROSHOP_DIRECT_LINK_LABEL'); } $referrers = JeproshopReferrerModelReferrer::getReferrers($this->customer->customer_id); $total_referrers = count($referrers); for ($i = 0; $i < $total_referrers; $i++) { $referrers[$i]->date_add = JeproshopTools::displayDate($referrers[$i]->date_add, null, true); } $customerLanguage = new JeproshopLanguageModelLanguage($this->customer->lang_id); $shop = new JeproshopShopModelShop($this->customer->shop_id); //$this->assignRef('customer', $customer); /*'gender' => $gender, /* 'gender_image' => $gender_image, // General information of the customer */ $registration = JeproshopTools::displayDate($this->customer->date_add, null, true); $this->assignRef('registration_date', $registration); $this->assignRef('customer_stats', $customer_stats); $last_visit = JeproshopTools::displayDate($customer_stats->last_visit, null, true); $this->assignRef('last_visit', $last_visit); $this->assignRef('count_better_customers', $count_better_customers); $shop_feature_active = JeproshopShopModelShop::isFeaturePublished(); $this->assignRef('shop_is_feature_active', $shop_feature_active); $this->assignRef('shop_name', $shop->shop_name); $customerBirthday = JeproshopTools::displayDate($this->customer->birthday); $this->assignRef('customer_birthday', $customerBirthday); $last_update = JeproshopTools::displayDate($this->customer->date_upd, null, true); $this->assignRef('last_update', $last_update); $customerExists = JeproshopCustomerModelCustomer::customerExists($this->customer->email); $this->assignRef('customer_exists', $customerExists); $this->assignRef('lang_id', $this->customer->lang_id); $this->assignRef('customerLanguage', $customerLanguage); // Add a Private note $customerNote = JeproshopTools::htmlentitiesUTF8($this->customer->note); $this->assignRef('customer_note', $customerNote); // Messages $this->assignRef('messages', $messages); // Groups $this->assignRef('groups', $groups); // Orders $this->assignRef('orders', $orders); $this->assignRef('orders_ok', $orders_ok); $this->assignRef('orders_ko', $orders_ko); $total_ok = JeproshopTools::displayPrice($total_ok, $this->context->currency->currency_id); $this->assignRef('total_ok', $total_ok); // Products $this->assignRef('products', $products); // Addresses $addresses = $this->customer->getAddresses($this->context->controller->default_form_language); $this->assignRef('addresses', $addresses); // Discounts $discounts = JeproshopCartRuleModelCartRule::getCustomerCartRules($this->context->controller->default_form_language, $this->customer->customer_id, false, false); $this->assignRef('discounts', $discounts); // Carts $this->assignRef('carts', $carts); // Interested $this->assignRef('interested_products', $interested); // Connections $this->assignRef('connections', $connections); // Referrers $this->assignRef('referrers', $referrers); if ($this->getLayout() != 'modal') { $this->addToolBar(); $this->sideBar = JHtmlSidebar::render(); } parent::display($tpl); }