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) ));*/ }
/** * Get order products * * @param bool $products * @param bool $selectedProducts * @param bool $selectedQty * @return array Products with price, quantity (with tax and without) */ public function getProducts($products = false, $selectedProducts = false, $selectedQty = false) { if (!$products) { $products = $this->getProductsDetail(); } $customized_datas = JeproshopProductModelProduct::getAllCustomizedDatas($this->cart_id); $resultArray = array(); foreach ($products as $row) { // Change qty if selected if ($selectedQty) { $row->product_quantity = 0; foreach ($selectedProducts as $key => $product_id) { if ($row->order_detail_id == $product_id) { $row->product_quantity = (int) $selectedQty[$key]; } } if (!$row->product_quantity) { continue; } } $this->setProductImageInformations($row); $this->setProductCurrentStock($row); // Backward compatibility 1.4 -> 1.5 $this->setProductPrices($row); $this->setProductCustomizedDatas($row, $customized_datas); // Add information for virtual product if ($row->download_hash && !empty($row->download_hash)) { $row->filename = JeproshopProductDownloadModelProductDownload::getFilenameFromProductId((int) $row->product_id); // Get the display filename $row->display_filename = JeproshopProductDownloadModelProductDownload::getFilenameFromFilename($row->filename); } $row->address_delivery_id = $this->address_delivery_id; /* Stock product */ $resultArray[(int) $row->order_detail_id] = $row; } if ($customized_datas) { JeproshopProductModelProduct::addCustomizationPrice($resultArray, $customized_datas); } return $resultArray; }
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); }