本文整理汇总了PHP中Customer::getCurrentCountry方法的典型用法代码示例。如果您正苦于以下问题:PHP Customer::getCurrentCountry方法的具体用法?PHP Customer::getCurrentCountry怎么用?PHP Customer::getCurrentCountry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Customer
的用法示例。
在下文中一共展示了Customer::getCurrentCountry方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: assignPriceAndTax
/**
* Assign price and tax to the template
*/
protected function assignPriceAndTax()
{
die('coucou');
$id_customer = isset($this->context->customer) ? (int) $this->context->customer->id : 0;
$id_group = (int) Group::getCurrent()->id;
$id_country = $id_customer ? (int) Customer::getCurrentCountry($id_customer) : (int) Tools::getCountry();
$group_reduction = GroupReduction::getValueForProduct($this->product->id, $id_group);
if ($group_reduction === false) {
$group_reduction = Group::getReduction((int) $this->context->cookie->id_customer) / 100;
}
// Tax
$tax = (double) $this->product->getTaxesRate(new Address((int) $this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$this->context->smarty->assign('tax_rate', $tax);
$product_price_with_tax = Product::getPriceStatic($this->product->id, true, null, 6) * 10;
if (Product::$_taxCalculationMethod == PS_TAX_INC) {
$product_price_with_tax = Tools::ps_round($product_price_with_tax, 2);
}
$product_price_without_eco_tax = (double) $product_price_with_tax - $this->product->ecotax;
$ecotax_rate = (double) Tax::getProductEcotaxRate($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotax_tax_amount = Tools::ps_round($this->product->ecotax, 2);
if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotax_tax_amount = Tools::ps_round($ecotax_tax_amount * (1 + $ecotax_rate / 100), 2);
}
$id_currency = (int) $this->context->cookie->id_currency;
$id_product = (int) $this->product->id;
$id_shop = $this->context->shop->id;
$quantity_discounts = SpecificPrice::getQuantityDiscounts($id_product, $id_shop, $id_currency, $id_country, $id_group, null, true, (int) $this->context->customer->id);
foreach ($quantity_discounts as &$quantity_discount) {
if ($quantity_discount['id_product_attribute']) {
$combination = new Combination((int) $quantity_discount['id_product_attribute']);
$attributes = $combination->getAttributesName((int) $this->context->language->id);
foreach ($attributes as $attribute) {
$quantity_discount['attributes'] = $attribute['name'] . ' - ';
}
$quantity_discount['attributes'] = rtrim($quantity_discount['attributes'], ' - ');
}
if ((int) $quantity_discount['id_currency'] == 0 && $quantity_discount['reduction_type'] == 'amount') {
$quantity_discount['reduction'] = Tools::convertPriceFull($quantity_discount['reduction'], null, Context::getContext()->currency);
}
}
$product_price = $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false) * 10;
$address = new Address($this->context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$this->context->smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts($quantity_discounts, $product_price, (double) $tax, $ecotax_tax_amount), 'ecotax_tax_inc' => $ecotax_tax_amount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'productPriceWithoutEcoTax' => (double) $product_price_without_eco_tax, 'group_reduction' => $group_reduction, 'no_tax' => Tax::excludeTaxeOption() || !$this->product->getTaxesRate($address), 'ecotax' => !count($this->errors) && $this->product->ecotax > 0 ? Tools::convertPrice((double) $this->product->ecotax) : 0, 'tax_enabled' => Configuration::get('PS_TAX') && !Configuration::get('AEUC_LABEL_TAX_INC_EXC'), 'customer_group_without_tax' => Group::getPriceDisplayMethod($this->context->customer->id_default_group)));
}
示例2: process
public function process()
{
global $cart, $currency;
parent::process();
if (!($id_product = (int) Tools::getValue('id_product')) or !Validate::isUnsignedId($id_product)) {
$this->errors[] = Tools::displayError('Product not found');
} else {
if (!Validate::isLoadedObject($this->product) or !$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) {
header('HTTP/1.1 404 page not found');
$this->errors[] = Tools::displayError('Product is no longer available.');
} elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) {
$this->errors[] = Tools::displayError('You do not have access to this product.');
} else {
self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
if (!$this->product->active) {
self::$smarty->assign('adminActionDisplay', true);
}
/* rewrited url set */
$rewrited_url = self::$link->getProductLink($this->product->id, $this->product->link_rewrite);
/* Product pictures management */
require_once 'images.inc.php';
self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
if (Tools::isSubmit('submitCustomizedDatas')) {
$this->pictureUpload($this->product, $cart);
$this->textRecord($this->product, $cart);
$this->formTargetFormat();
} elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) {
$this->errors[] = Tools::displayError('An error occurred while deleting the selected picture');
}
$files = self::$cookie->getFamily('pictures_' . (int) $this->product->id);
$textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id);
foreach ($textFields as $key => $textField) {
$textFields[$key] = str_replace('<br />', "\n", $textField);
}
self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields));
if ((int) Tools::getValue('pp') == 1) {
echo 'here1';
}
$productPriceWithTax = Product::getPriceStatic($id_product, true, NULL, 6);
if (Product::$_taxCalculationMethod == PS_TAX_INC) {
$productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
}
if ((int) Tools::getValue('pp') == 1) {
$time2 = time();
echo 'time2: ' . $time2;
}
$productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax);
$configs = Configuration::getMultiple(array('PS_ORDER_OUT_OF_STOCK', 'PS_LAST_QTIES'));
/* Features / Values */
$features = $this->product->getFrontFeatures((int) self::$cookie->id_lang);
$attachments = $this->product->getAttachments((int) self::$cookie->id_lang);
/* Category */
$category = false;
if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
if (isset($regs[2]) and is_numeric($regs[2])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
$category = new Category((int) $regs[2], (int) self::$cookie->id_lang);
}
} elseif (isset($regs[5]) and is_numeric($regs[5])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
$category = new Category((int) $regs[5], (int) self::$cookie->id_lang);
}
}
}
if (!$category) {
$category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang);
}
if (isset($category) and Validate::isLoadedObject($category)) {
self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name)));
} else {
self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name));
}
self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();');
$lang = Configuration::get('PS_LANG_DEFAULT');
if (Pack::isPack((int) $this->product->id, (int) $lang) and !Pack::isInStock((int) $this->product->id, (int) $lang)) {
$this->product->quantity = 0;
}
$group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100;
$id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0;
$id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));
if ((int) Tools::getValue('pp') == 1) {
$time3 = time();
echo 'time3: ' . $time3;
}
// Tax
$tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
self::$smarty->assign('tax_rate', $tax);
$ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2);
if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2);
}
$manufacturer = new Manufacturer((int) $this->product->id_manufacturer, 1);
$sizechart = new Sizechart((int) $this->product->id_sizechart, 1);
//see if the product is already in the wishlist
if ($id_customer) {
$sql = "select id from ps_wishlist where id_customer = " . $id_customer . " and id_product = " . $this->product->id;
$res = Db::getInstance()->ExecuteS($sql);
if ($res) {
//.........这里部分代码省略.........
示例3: process
public function process()
{
global $cart, $currency;
parent::process();
if (!Validate::isLoadedObject($this->product)) {
$this->errors[] = Tools::displayError('Product not found');
} else {
if (!$this->product->active and Tools::getValue('adtoken') != Tools::encrypt('PreviewProduct' . $this->product->id) || !file_exists(dirname(__FILE__) . '/../' . Tools::getValue('ad') . '/ajax.php')) {
header('HTTP/1.1 404 page not found');
$this->errors[] = Tools::displayError('Product is no longer available.');
} elseif (!$this->product->checkAccess((int) self::$cookie->id_customer)) {
$this->errors[] = Tools::displayError('You do not have access to this product.');
} else {
self::$smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
if (!$this->product->active) {
self::$smarty->assign('adminActionDisplay', true);
}
/* Product pictures management */
require_once 'images.inc.php';
if ($this->product->customizable) {
self::$smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
if (Tools::isSubmit('submitCustomizedDatas')) {
$this->pictureUpload($this->product, $cart);
$this->textRecord($this->product, $cart);
$this->formTargetFormat();
} elseif (isset($_GET['deletePicture']) and !$cart->deletePictureToProduct((int) $this->product->id, (int) Tools::getValue('deletePicture'))) {
$this->errors[] = Tools::displayError('An error occurred while deleting the selected picture');
}
$files = self::$cookie->getFamily('pictures_' . (int) $this->product->id);
$textFields = self::$cookie->getFamily('textFields_' . (int) $this->product->id);
foreach ($textFields as $key => $textField) {
$textFields[$key] = str_replace('<br />', "\n", $textField);
}
self::$smarty->assign(array('pictures' => $files, 'textFields' => $textFields));
}
/* Features / Values */
$features = $this->product->getFrontFeatures((int) self::$cookie->id_lang);
$attachments = $this->product->cache_has_attachments ? $this->product->getAttachments((int) self::$cookie->id_lang) : array();
/* Category */
$category = false;
if (isset($_SERVER['HTTP_REFERER']) and preg_match('!^(.*)\\/([0-9]+)\\-(.*[^\\.])|(.*)id_category=([0-9]+)(.*)$!', $_SERVER['HTTP_REFERER'], $regs) and !strstr($_SERVER['HTTP_REFERER'], '.html')) {
if (isset($regs[2]) and is_numeric($regs[2])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[2])))) {
$category = new Category((int) $regs[2], (int) self::$cookie->id_lang);
}
} elseif (isset($regs[5]) and is_numeric($regs[5])) {
if (Product::idIsOnCategoryId((int) $this->product->id, array('0' => array('id_category' => (int) $regs[5])))) {
$category = new Category((int) $regs[5], (int) self::$cookie->id_lang);
}
}
}
if (!$category) {
$category = new Category($this->product->id_category_default, (int) self::$cookie->id_lang);
}
if (isset($category) and Validate::isLoadedObject($category)) {
self::$smarty->assign(array('path' => Tools::getPath((int) $category->id, $this->product->name, true), 'category' => $category, 'subCategories' => $category->getSubCategories((int) self::$cookie->id_lang, true), 'id_category_current' => (int) $category->id, 'id_category_parent' => (int) $category->id_parent, 'return_category_name' => Tools::safeOutput($category->name)));
} else {
self::$smarty->assign('path', Tools::getPath((int) $this->product->id_category_default, $this->product->name));
}
self::$smarty->assign('return_link', (isset($category->id) and $category->id) ? Tools::safeOutput(self::$link->getCategoryLink($category)) : 'javascript: history.back();');
if (Pack::isPack((int) $this->product->id) and !Pack::isInStock((int) $this->product->id)) {
$this->product->quantity = 0;
}
$group_reduction = (100 - Group::getReduction((int) self::$cookie->id_customer)) / 100;
$id_customer = (isset(self::$cookie->id_customer) and self::$cookie->id_customer) ? (int) self::$cookie->id_customer : 0;
$id_group = $id_customer ? (int) Customer::getDefaultGroupId($id_customer) : _PS_DEFAULT_CUSTOMER_GROUP_;
$id_country = (int) ($id_customer ? Customer::getCurrentCountry($id_customer) : Configuration::get('PS_COUNTRY_DEFAULT'));
// Tax
$tax = (double) Tax::getProductTaxRate((int) $this->product->id, $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
self::$smarty->assign('tax_rate', $tax);
$productPriceWithTax = Product::getPriceStatic($this->product->id, true, NULL, 6);
if (Product::$_taxCalculationMethod == PS_TAX_INC) {
$productPriceWithTax = Tools::ps_round($productPriceWithTax, 2);
}
$productPriceWithoutEcoTax = (double) ($productPriceWithTax - $this->product->ecotax);
$ecotax_rate = (double) Tax::getProductEcotaxRate($cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotaxTaxAmount = Tools::ps_round($this->product->ecotax, 2);
if (Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX')) {
$ecotaxTaxAmount = Tools::ps_round($ecotaxTaxAmount * (1 + $ecotax_rate / 100), 2);
}
self::$smarty->assign(array('quantity_discounts' => $this->formatQuantityDiscounts(SpecificPrice::getQuantityDiscounts((int) $this->product->id, (int) Shop::getCurrentShop(), (int) self::$cookie->id_currency, $id_country, $id_group), $this->product->getPrice(Product::$_taxCalculationMethod == PS_TAX_INC, false), (double) $tax), 'product' => $this->product, 'ecotax_tax_inc' => $ecotaxTaxAmount, 'ecotax_tax_exc' => Tools::ps_round($this->product->ecotax, 2), 'ecotaxTax_rate' => $ecotax_rate, 'homeSize' => Image::getSize('home'), 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, self::$cookie->id_lang), 'token' => Tools::getToken(false), 'productPriceWithoutEcoTax' => (double) $productPriceWithoutEcoTax, 'features' => $features, 'attachments' => $attachments, 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'group_reduction' => $group_reduction, 'col_img_dir' => _PS_COL_IMG_DIR_));
self::$smarty->assign(array('HOOK_EXTRA_LEFT' => Module::hookExec('extraLeft'), 'HOOK_EXTRA_RIGHT' => Module::hookExec('extraRight'), 'HOOK_PRODUCT_OOS' => Hook::productOutOfStock($this->product), 'HOOK_PRODUCT_FOOTER' => Hook::productFooter($this->product, $category), 'HOOK_PRODUCT_ACTIONS' => Module::hookExec('productActions'), 'HOOK_PRODUCT_TAB' => Module::hookExec('productTab'), 'HOOK_PRODUCT_TAB_CONTENT' => Module::hookExec('productTabContent')));
$images = $this->product->getImages((int) self::$cookie->id_lang);
$productImages = array();
foreach ($images as $k => $image) {
if ($image['cover']) {
self::$smarty->assign('mainImage', $images[0]);
$cover = $image;
$cover['id_image'] = Configuration::get('PS_LEGACY_IMAGES') ? $this->product->id . '-' . $image['id_image'] : $image['id_image'];
$cover['id_image_only'] = (int) $image['id_image'];
}
$productImages[(int) $image['id_image']] = $image;
}
if (!isset($cover)) {
$cover = array('id_image' => Language::getIsoById(self::$cookie->id_lang) . '-default', 'legend' => 'No picture', 'title' => 'No picture');
}
$size = Image::getSize('large');
self::$smarty->assign(array('cover' => $cover, 'imgWidth' => (int) $size['width'], 'mediumSize' => Image::getSize('medium'), 'largeSize' => Image::getSize('large'), 'accessories' => $this->product->getAccessories((int) self::$cookie->id_lang)));
if (count($productImages)) {
self::$smarty->assign('images', $productImages);
//.........这里部分代码省略.........
示例4: init
public function init()
{
global $cookie, $smarty, $cart, $iso, $defaultCountry, $protocol_link, $protocol_content, $link, $css_files, $js_files;
if (self::$initialized) {
return;
}
self::$initialized = true;
$css_files = array();
$js_files = array();
if ($this->ssl and (empty($_SERVER['HTTPS']) or strtolower($_SERVER['HTTPS']) == 'off') and Configuration::get('PS_SSL_ENABLED')) {
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . Tools::getShopDomainSsl(true) . $_SERVER['REQUEST_URI']);
exit;
}
ob_start();
/* Loading default country */
$defaultCountry = new Country((int) Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
$cookie = new Cookie('ps');
$link = new Link();
if ($this->auth and !$cookie->isLogged($this->guestAllowed)) {
Tools::redirect('authentication.php' . ($this->authRedirection ? '?back=' . $this->authRedirection : ''));
}
/* Theme is missing or maintenance */
if (!is_dir(_PS_THEME_DIR_)) {
die(Tools::displayError('Current theme unavailable. Please check your theme directory name and permissions.'));
} elseif (basename($_SERVER['PHP_SELF']) != 'disabled.php' and !(int) Configuration::get('PS_SHOP_ENABLE')) {
$this->maintenance = true;
} elseif (Configuration::get('PS_GEOLOCATION_ENABLED')) {
if (!isset($cookie->iso_code_country)) {
if ($cookie->logged) {
$id_country = Customer::getCurrentCountry((int) $cookie->id_customer);
$cookie->iso_code_country = Country::getIsoById($id_country);
} else {
$this->geolocationManagement();
}
}
if (!isset($cookie->iso_code_country)) {
$current_country_id = Customer::getCurrentCountry((int) $cookie->id_customer);
} else {
$current_country_id = Country::getByIso($cookie->iso_code_country);
}
$current_country = new Country($current_country_id, 1);
$cookie->id_country = $current_country->id;
$smarty->assign('current_country', $current_country->name);
$smarty->assign('current_country_id', $current_country->id);
if ($cookie->id_country == 110 && !isset($cookie->id_currency)) {
$cookie->id_currency = 4;
}
}
//set imagesize if not set
if (!isset($cookie->image_size)) {
$cookie->image_size = IMAGE_SIZE_LARGE;
$cookie->write();
}
if (!isset($cookie->greetings) && !$cookie->logged) {
$cookie->greetings = 1;
$cookie->write();
$smarty->assign('show_greetings', 1);
}
//echo $cookie->image_size;
if ($image_size = Tools::getValue("is")) {
if ($image_size == "s" && $cookie->image_size == IMAGE_SIZE_LARGE) {
$cookie->image_size = IMAGE_SIZE_SMALL;
$cookie->write();
} else {
if ($image_size == "l" && $cookie->image_size == IMAGE_SIZE_SMALL) {
$cookie->image_size = IMAGE_SIZE_LARGE;
$cookie->write();
}
}
}
// Switch language if needed and init cookie language
if ($iso = Tools::getValue('isolang') and Validate::isLanguageIsoCode($iso) and $id_lang = (int) Language::getIdByIso($iso)) {
$_GET['id_lang'] = $id_lang;
}
Tools::switchLanguage();
Tools::setCookieLanguage();
/* attribute id_lang is often needed, so we create a constant for performance reasons */
if (!defined('_USER_ID_LANG_')) {
define('_USER_ID_LANG_', (int) $cookie->id_lang);
}
if (isset($_GET['logout']) or $cookie->logged and Customer::isBanned((int) $cookie->id_customer)) {
$cookie->logout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
} elseif (isset($_GET['mylogout'])) {
$this->logoutFacebook();
$cookie->mylogout();
Tools::redirect(isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : NULL);
}
if ($source = Tools::getValue('utm_source')) {
$cookie->last_source = $source;
$cookie->write();
}
if ($ref_source = Tools::getValue('vbref')) {
$cookie->last_ref_source = $ref_source;
$cookie->write();
}
/*else
{
if(!isset($cookie->last_ref_source))
//.........这里部分代码省略.........
示例5: getOrderShippingCost
/**
* Return shipping total
*
* @param integer $id_carrier Carrier ID (default : current carrier)
* @return float Shipping total
*/
function getOrderShippingCost($id_carrier = NULL, $useTax = true)
{
global $defaultCountry, $cookie;
if ($this->isVirtualCart()) {
return 0;
}
// Checking discounts in cart
$products = $this->getProducts();
$discounts = $this->getDiscounts(true);
if ($discounts) {
foreach ($discounts as $id_discount) {
if ($id_discount['id_discount_type'] == 3 || $id_discount['id_discount_type'] == 4 || $id_discount['id_discount_type'] == 5) {
if ($id_discount['minimal'] > 0) {
$total_cart = 0;
$categories = Discount::getCategories((int) $id_discount['id_discount']);
if (sizeof($categories)) {
foreach ($products as $product) {
if (Product::idIsOnCategoryId((int) $product['id_product'], $categories)) {
$total_cart += $product['total_wt'];
}
}
}
if ($total_cart >= $id_discount['minimal']) {
return 0;
}
} else {
return 0;
}
}
}
}
// Order total in default currency without fees
$order_total = $this->getOrderTotal(true, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING);
// Start with shipping cost at 0
$shipping_cost = 0;
// If no product added, return 0
if ($order_total <= 0 and !(int) self::getNbProducts($this->id)) {
return $shipping_cost;
}
// Get id zone
if (isset($this->id_address_delivery) and $this->id_address_delivery and Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
$id_zone = Address::getZoneById((int) $this->id_address_delivery);
} else {
if (!isset($cookie->iso_code_country)) {
$current_country_id = Customer::getCurrentCountry((int) $cookie->id_customer);
} else {
$current_country_id = Country::getByIso($cookie->iso_code_country);
}
// This method can be called from the backend, and $defaultCountry won't be defined
$current_country = new Country($current_country_id, 1);
if (!Validate::isLoadedObject($defaultCountry)) {
$current_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
}
if (!Validate::isLoadedObject($current_country)) {
$current_country = $defaultCountry;
}
$id_zone = (int) $current_country->id_zone;
}
// If no carrier, select default one
if (!$id_carrier) {
$id_carrier = $this->id_carrier;
}
//short circuit for flat shipping cost structure
//delivery zone = $id_zone
if ($id_zone == IND_ZONE_ID) {
return 0;
} else {
//check for free shipping
$free_fees_price = 99;
$orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING);
$totalUSD = Tools::convertPrice($orderTotalwithDiscounts, Currency::getCurrencyInstance((int) $this->id_currency), false);
if ($totalUSD >= (double) $free_fees_price and (double) $free_fees_price > 0) {
return $shipping_cost;
}
//check for virtual products (weight == 0)
if ($this->getTotalWeight() == 0) {
return 0;
}
//return nb_items * SHIPPING_PER_ITEM
$nb_items = $this->getNbProducts($this->id);
$unitCharge = 10;
switch ($nb_items) {
case 1:
$unitCharge = SHIPPING_PER_ITEM_1;
break;
case 2:
$unitCharge = SHIPPING_PER_ITEM_2;
break;
case 3:
$unitCharge = SHIPPING_PER_ITEM_3;
break;
default:
$unitCharge = SHIPPING_PER_ITEM_MORE;
}
//.........这里部分代码省略.........