本文整理汇总了PHP中Address::addressExists方法的典型用法代码示例。如果您正苦于以下问题:PHP Address::addressExists方法的具体用法?PHP Address::addressExists怎么用?PHP Address::addressExists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::addressExists方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: pwa_order
public function pwa_order($data)
{
$prefix = _DB_PREFIX_;
$pwa_order_status = $data['amznPmtsPaymentStatus'];
$pwa_order_id = $data['amznPmtsOrderIds'];
if (isset($data['refresh']) && $data['refresh'] != '') {
$refresh = $data['refresh'];
} else {
$refresh = 'yes';
}
if (isset($data['CartId']) && $data['CartId'] > 0) {
$CartId = $data['CartId'];
} else {
$CartId = 0;
}
$tablename = $prefix . 'pwa_orders';
$sql = 'SELECT * from `' . $tablename . '` where `amazon_order_id` = "' . $pwa_order_id . '" ';
$result = Db::getInstance()->ExecuteS($sql);
if (empty($result)) {
$tablename = $prefix . 'orders';
$date = date('Y-m-d H:i:s');
$sql = 'INSERT into `' . $tablename . '` (`current_state` , `id_cart` , `payment` , `module` , `date_add` ) VALUES( 99, "' . $CartId . '", "Pay with Amazon", "pwapresta", "' . $date . '" )';
Db::getInstance()->Execute($sql);
$order_id = Db::getInstance()->Insert_ID();
$tablename = $prefix . 'pwa_orders';
$sql = 'INSERT into `' . $tablename . '` (`prestashop_order_id` , `amazon_order_id` ) VALUES( "' . $order_id . '", "' . $pwa_order_id . '" )';
Db::getInstance()->Execute($sql);
} else {
$order_id = $result[0]['prestashop_order_id'];
}
$products = $this->context->cart->getProducts();
foreach ($products as $product) {
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address_id = (int) $this->id_address_invoice;
} else {
$address_id = (int) $product['id_address_delivery'];
}
// Get delivery address of the product from the cart
if (!Address::addressExists($address_id)) {
$address_id = null;
}
$virtual_context = Context::getContext()->cloneContext();
$virtual_context->cart = $this->context->cart;
$product_price = Product::getPriceStatic((int) $product['id_product'], false, (int) $product['id_product_attribute'], 2, null, false, true, $product['quantity'], false, (int) $this->context->cart->id_customer ? (int) $this->context->cart->id_customer : null, (int) $this->context->cart->id, (int) $address_id ? (int) $address_id : null, $null, true, true, $virtual_context);
$tablename = $prefix . 'pwa_order_products';
$sql = 'INSERT into `' . $tablename . '` (`id_cart` , `id_product` , `id_product_attribute` , `quantity` , `amount` , `amount_excl` , `sku` , `title` ) VALUES( "' . $this->context->cart->id . '", "' . $product["id_product"] . '", "' . $product["id_product_attribute"] . '", "' . $product["quantity"] . '", "' . $product["price_wt"] . '", "' . $product_price . '", "' . $product["reference"] . '", "' . $product["name"] . '" )';
Db::getInstance()->Execute($sql);
//$this->context->cart->deleteProduct($product["id_product"]);
}
$this->context->smarty->assign(array('order_id' => $order_id, 'pwa_order_id' => $pwa_order_id, 'pwa_order_status' => $pwa_order_status, 'refresh' => $refresh));
$this->setTemplate('pwa_order.tpl');
}
示例2: getPackageShippingCost
public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null, $id_zone = null)
{
if (!Configuration::get('LEGAL_SHIPTAXMETH')) {
return parent::getPackageShippingCost($id_carrier, $use_tax, $default_country, $product_list, $id_zone);
}
if ($this->isVirtualCart()) {
return 0;
}
if (!$default_country) {
$default_country = Context::getContext()->country;
}
if (!is_null($product_list)) {
foreach ($product_list as $key => $value) {
if ($value['is_virtual'] == 1) {
unset($product_list[$key]);
}
}
}
$complete_product_list = $this->getProducts();
if (is_null($product_list)) {
$products = $complete_product_list;
} else {
$products = $product_list;
}
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address_id = (int) $this->id_address_invoice;
} elseif (count($product_list)) {
$prod = current($product_list);
$address_id = (int) $prod['id_address_delivery'];
} else {
$address_id = null;
}
if (!Address::addressExists($address_id)) {
$address_id = null;
}
$cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id;
if ($products) {
foreach ($products as $product) {
$cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute'];
}
}
if (Cache::isStored($cache_id)) {
return Cache::retrieve($cache_id);
}
// Order total in default currency without fees
$order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list);
// Start with shipping cost at 0
$shipping_cost = 0;
// If no product added, return 0
if (!count($products)) {
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
if (!isset($id_zone)) {
// Get id zone
if (!$this->isMultiAddressDelivery() && isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
$id_zone = Address::getZoneById((int) $this->id_address_delivery);
} else {
if (!Validate::isLoadedObject($default_country)) {
$default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
}
$id_zone = (int) $default_country->id_zone;
}
}
if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) {
$id_carrier = '';
}
if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) {
$id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
}
$total_package_without_shipping_tax_inc = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
if (empty($id_carrier)) {
if ((int) $this->id_customer) {
$customer = new Customer((int) $this->id_customer);
$result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
unset($customer);
} else {
$result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
}
foreach ($result as $k => $row) {
if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
continue;
}
if (!isset(self::$_carriers[$row['id_carrier']])) {
self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
}
$carrier = self::$_carriers[$row['id_carrier']];
// Get only carriers that are compliant with shipping method
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) {
unset($result[$k]);
continue;
}
// If out-of-range behavior carrier is set on "Desactivate carrier"
if ($row['range_behavior']) {
$check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone);
$total_order = $total_package_without_shipping_tax_inc;
$check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency);
// Get only carriers that have a range compatible with cart
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
unset($result[$k]);
//.........这里部分代码省略.........
示例3: addressImportOne
protected function addressImportOne($info, $force_ids, $validateOnly = false)
{
AdminImportController::setDefaultValues($info);
if ($force_ids && isset($info['id']) && (int) $info['id']) {
$address = new Address((int) $info['id']);
} else {
if (array_key_exists('id', $info) && (int) $info['id'] && Address::addressExists((int) $info['id'])) {
$address = new Address((int) $info['id']);
} else {
$address = new Address();
}
}
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address);
if (isset($address->country) && is_numeric($address->country)) {
if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
$address->id_country = (int) $address->country;
}
} elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) {
if ($id_country = Country::getIdByName(null, $address->country)) {
$address->id_country = (int) $id_country;
} else {
$country = new Country();
$country->active = 1;
$country->name = AdminImportController::createMultiLangField($address->country);
$country->id_zone = 0;
// Default zone for country to create
$country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2));
// Default iso for country to create
$country->contains_states = 0;
// Default value for country to create
$lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $country->add()) {
$address->id_country = (int) $country->id;
} else {
if (!$validateOnly) {
$default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
$this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $country->name[$default_language_id]);
}
if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
}
if (isset($address->state) && is_numeric($address->state)) {
if (State::getNameById((int) $address->state)) {
$address->id_state = (int) $address->state;
}
} elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) {
if ($id_state = State::getIdByName($address->state)) {
$address->id_state = (int) $id_state;
} else {
$state = new State();
$state->active = 1;
$state->name = $address->state;
$state->id_country = isset($country->id) ? (int) $country->id : 0;
$state->id_zone = 0;
// Default zone for state to create
$state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2));
// Default iso for state to create
$state->tax_behavior = 0;
if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $state->add()) {
$address->id_state = (int) $state->id;
} else {
if (!$validateOnly) {
$this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $state->name);
}
if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
$this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
}
}
}
}
if (isset($address->customer_email) && !empty($address->customer_email)) {
if (Validate::isEmail($address->customer_email)) {
// a customer could exists in different shop
$customer_list = Customer::getCustomersByEmail($address->customer_email);
if (count($customer_list) == 0) {
$this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
}
} else {
$this->errors[] = sprintf($this->trans('"%s" is not a valid email address.', array(), 'Admin.Parameters.Notification'), $address->customer_email);
return;
}
} elseif (isset($address->id_customer) && !empty($address->id_customer)) {
if (Customer::customerIdExistsStatic((int) $address->id_customer)) {
$customer = new Customer((int) $address->id_customer);
// a customer could exists in different shop
$customer_list = Customer::getCustomersByEmail($customer->email);
if (count($customer_list) == 0) {
$this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer);
}
} else {
$this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be ' . ($validateOnly ? 'validated' : 'saved')), $address->id_customer);
}
} else {
$customer_list = array();
$address->id_customer = 0;
}
if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) {
//.........这里部分代码省略.........
示例4: addressExists
/**
* Check if an address exists depending on given $id_address
* @param $id_address
* @return bool
*/
public function addressExists($id_address)
{
return Address::addressExists($id_address);
}
示例5: getPackageShippingCost
/**
* Return package shipping cost
*
* @param integer $id_carrier Carrier ID (default : current carrier)
* @param booleal $use_tax
* @param Country $default_country
* @param Array $product_list
* @param array $product_list List of product concerned by the shipping. If null, all the product of the cart are used to calculate the shipping cost
*
* @return float Shipping total
*/
public function getPackageShippingCost($id_carrier = null, $use_tax = true, Country $default_country = null, $product_list = null)
{
if ($this->isVirtualCart()) {
return 0;
}
if (!$default_country) {
$default_country = Context::getContext()->country;
}
$complete_product_list = $this->getProducts();
if (is_null($product_list)) {
$products = $complete_product_list;
} else {
$products = $product_list;
}
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address_id = (int) $this->id_address_invoice;
} elseif (count($product_list)) {
$prod = current($product_list);
$address_id = (int) $prod['id_address_delivery'];
} else {
$address_id = null;
}
if (!Address::addressExists($address_id)) {
$address_id = null;
}
$cache_id = 'getPackageShippingCost_' . (int) $this->id . '_' . (int) $address_id . '_' . (int) $id_carrier . '_' . (int) $use_tax . '_' . (int) $default_country->id;
if ($products) {
foreach ($products as $product) {
$cache_id .= '_' . (int) $product['id_product'] . '_' . (int) $product['id_product_attribute'];
}
}
if (Cache::isStored($cache_id)) {
return Cache::retrieve($cache_id);
}
// Order total in default currency without fees
$order_total = $this->getOrderTotal(true, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING, $product_list);
// Start with shipping cost at 0
$shipping_cost = 0;
// If no product added, return 0
if (!count($products)) {
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
// Get id zone
if (!$this->isMultiAddressDelivery() && isset($this->id_address_delivery) && $this->id_address_delivery && Customer::customerHasAddress($this->id_customer, $this->id_address_delivery)) {
$id_zone = Address::getZoneById((int) $this->id_address_delivery);
} else {
if (!Validate::isLoadedObject($default_country)) {
$default_country = new Country(Configuration::get('PS_COUNTRY_DEFAULT'), Configuration::get('PS_LANG_DEFAULT'));
}
$id_zone = (int) $default_country->id_zone;
}
if ($id_carrier && !$this->isCarrierInRange((int) $id_carrier, (int) $id_zone)) {
$id_carrier = '';
}
if (empty($id_carrier) && $this->isCarrierInRange((int) Configuration::get('PS_CARRIER_DEFAULT'), (int) $id_zone)) {
$id_carrier = (int) Configuration::get('PS_CARRIER_DEFAULT');
}
if (empty($id_carrier)) {
if ((int) $this->id_customer) {
$customer = new Customer((int) $this->id_customer);
$result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone, $customer->getGroups());
unset($customer);
} else {
$result = Carrier::getCarriers((int) Configuration::get('PS_LANG_DEFAULT'), true, false, (int) $id_zone);
}
foreach ($result as $k => $row) {
if ($row['id_carrier'] == Configuration::get('PS_CARRIER_DEFAULT')) {
continue;
}
if (!isset(self::$_carriers[$row['id_carrier']])) {
self::$_carriers[$row['id_carrier']] = new Carrier((int) $row['id_carrier']);
}
$carrier = self::$_carriers[$row['id_carrier']];
// Get only carriers that are compliant with shipping method
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && $carrier->getMaxDeliveryPriceByWeight((int) $id_zone) === false || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && $carrier->getMaxDeliveryPriceByPrice((int) $id_zone) === false) {
unset($result[$k]);
continue;
}
// If out-of-range behavior carrier is set on "Desactivate carrier"
if ($row['range_behavior']) {
$check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight($row['id_carrier'], $this->getTotalWeight(), (int) $id_zone);
$total_order = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list);
$check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($row['id_carrier'], $total_order, (int) $id_zone, (int) $this->id_currency);
// Get only carriers that have a range compatible with cart
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
unset($result[$k]);
continue;
}
//.........这里部分代码省略.........
示例6: getProducts
//.........这里部分代码省略.........
$result = Db::getInstance()->executeS($sql);
// Reset the cache before the following return, or else an empty cart will add dozens of queries
$products_ids = array();
$pa_ids = array();
if ($result) {
foreach ($result as $row) {
$products_ids[] = $row['id_product'];
$pa_ids[] = $row['id_product_attribute'];
}
}
// Thus you can avoid one query per product, because there will be only one query for all the products of the cart
Product::cacheProductsFeatures($products_ids);
Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang);
$this->_products = array();
if (empty($result)) {
return array();
}
$cart_shop_context = Context::getContext()->cloneContext();
foreach ($result as &$row) {
if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) {
$row['ecotax'] = (double) $row['ecotax_attr'];
}
$row['stock_quantity'] = (int) $row['quantity'];
// for compatibility with 1.2 themes
$row['quantity'] = (int) $row['cart_quantity'];
if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) {
$row['weight'] = (double) $row['weight_attribute'];
}
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address_id = (int) $this->id_address_invoice;
} else {
$address_id = (int) $row['id_address_delivery'];
}
if (!Address::addressExists($address_id)) {
$address_id = null;
}
if ($cart_shop_context->shop->id != $row['id_shop']) {
$cart_shop_context->shop = new Shop((int) $row['id_shop']);
}
$address = Address::initialize($address_id, true);
$id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $row['id_product'], $cart_shop_context);
$tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
$row['price'] = Product::getPriceStatic((int) $row['id_product'], false, isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null, 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, false, true, $cart_shop_context);
switch (Configuration::get('PS_ROUND_TYPE')) {
case Order::ROUND_TOTAL:
case Order::ROUND_LINE:
$row['total'] = Tools::ps_round($row['price'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
$row['total_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['price']) * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
break;
case Order::ROUND_ITEM:
default:
$row['total'] = Tools::ps_round($row['price'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
$row['total_wt'] = Tools::ps_round($tax_calculator->addTaxes($row['price']), _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
break;
}
$row['price_wt'] = $tax_calculator->addTaxes($row['price']);
$row['description_short'] = Tools::nl2br($row['description_short']);
/**
* ABU: correction bug
* https://github.com/PrestaShop/PrestaShop/commit/bbc5591495b12021aa95421af1a0d27acd7a378e?diff=split
*/
/*if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0)
{
$cache_id = 'Cart::getProducts_'.'-pai_id_image-'.(int)$row['id_product'].'-'.(int)$this->id_lang.'-'.(int)$row['id_shop'];
if (!Cache::isStored($cache_id))
{
示例7: getTaxesAverageUsed
public static function getTaxesAverageUsed($id_cart)
{
$cart = new Cart((int) $id_cart);
if (!Validate::isLoadedObject($cart)) {
die(Tools::displayError());
}
if (!Configuration::get('PS_TAX')) {
return 0;
}
$products = $cart->getProducts();
$total_products_moy = 0;
$ratio_tax = 0;
if (!count($products)) {
return 0;
}
foreach ($products as $product) {
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address_id = (int) $cart->id_address_invoice;
} else {
$address_id = (int) $product['id_address_delivery'];
}
// Get delivery address of the product from the cart
if (!Address::addressExists($address_id)) {
$address_id = null;
}
$total_products_moy += $product['total_wt'];
$ratio_tax += $product['total_wt'] * Tax::getProductTaxRate((int) $product['id_product'], (int) $address_id);
}
if ($total_products_moy > 0) {
return $ratio_tax / $total_products_moy;
}
return 0;
}
示例8: initialize
/**
* Initiliaze an address corresponding to the specified id address or if empty to the
* default shop configuration
*
* @param int $id_address
* @param bool $with_geoloc
* @return Address address
*
* @throws PrestaShopException
*/
public static function initialize($id_address = null, $with_geoloc = false)
{
$context = Context::getContext();
$exists = (int) $id_address && (bool) Address::addressExists($id_address);
if ($exists) {
$context_hash = (int) $id_address;
} elseif ($with_geoloc && isset($context->customer->geoloc_id_country)) {
$context_hash = md5((int) $context->customer->geoloc_id_country . '-' . (int) $context->customer->id_state . '-' . $context->customer->postcode);
} else {
$context_hash = md5((int) $context->country->id);
}
$cache_id = 'Address::initialize_' . $context_hash;
if (!Cache::isStored($cache_id)) {
// if an id_address has been specified retrieve the address
if ($exists) {
$address = new Address((int) $id_address);
if (!Validate::isLoadedObject($address)) {
throw new PrestaShopException('Invalid address #' . (int) $id_address);
}
} elseif ($with_geoloc && isset($context->customer->geoloc_id_country)) {
$address = new Address();
$address->id_country = (int) $context->customer->geoloc_id_country;
$address->id_state = (int) $context->customer->id_state;
$address->postcode = $context->customer->postcode;
} else {
// set the default address
$address = new Address();
$address->id_country = (int) $context->country->id;
$address->id_state = 0;
$address->postcode = 0;
}
Cache::store($cache_id, $address);
return $address;
}
return Cache::retrieve($cache_id);
}
示例9: getProducts
//.........这里部分代码省略.........
$sql->leftJoin('product_attribute_shop', 'product_attribute_shop', '(product_attribute_shop.`id_shop` = cp.`id_shop` AND product_attribute_shop.`id_product_attribute` = pa.`id_product_attribute`)');
} else {
$sql->select('p.`reference` AS reference, p.`ean13`,
p.`upc` AS upc, product_shop.`minimal_quantity` AS minimal_quantity, product_shop.`wholesale_price` wholesale_price');
}
$sql->select('image_shop.`id_image` id_image, il.`legend`');
$sql->leftJoin('image_shop', 'image_shop', 'image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $this->id_shop);
$sql->leftJoin('image_lang', 'il', 'il.`id_image` = image_shop.`id_image` AND il.`id_lang` = ' . (int) $this->id_lang);
$result = Db::getInstance()->executeS($sql);
// Reset the cache before the following return, or else an empty cart will add dozens of queries
$products_ids = array();
$pa_ids = array();
if ($result) {
foreach ($result as $key => $row) {
$products_ids[] = $row['id_product'];
$pa_ids[] = $row['id_product_attribute'];
$specific_price = SpecificPrice::getSpecificPrice($row['id_product'], $this->id_shop, $this->id_currency, $id_country, $this->id_shop_group, $row['cart_quantity'], $row['id_product_attribute'], $this->id_customer, $this->id);
if ($specific_price) {
$reduction_type_row = array('reduction_type' => $specific_price['reduction_type']);
} else {
$reduction_type_row = array('reduction_type' => 0);
}
$result[$key] = array_merge($row, $reduction_type_row);
}
}
// Thus you can avoid one query per product, because there will be only one query for all the products of the cart
Product::cacheProductsFeatures($products_ids);
Cart::cacheSomeAttributesLists($pa_ids, $this->id_lang);
$this->_products = array();
if (empty($result)) {
return array();
}
$ecotax_rate = (double) Tax::getProductEcotaxRate($this->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$apply_eco_tax = Product::$_taxCalculationMethod == PS_TAX_INC && (int) Configuration::get('PS_TAX');
$cart_shop_context = Context::getContext()->cloneContext();
foreach ($result as &$row) {
if (isset($row['ecotax_attr']) && $row['ecotax_attr'] > 0) {
$row['ecotax'] = (double) $row['ecotax_attr'];
}
$row['stock_quantity'] = (int) $row['quantity'];
// for compatibility with 1.2 themes
$row['quantity'] = (int) $row['cart_quantity'];
if (isset($row['id_product_attribute']) && (int) $row['id_product_attribute'] && isset($row['weight_attribute'])) {
$row['weight'] = (double) $row['weight_attribute'];
}
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address_id = (int) $this->id_address_invoice;
} else {
$address_id = (int) $row['id_address_delivery'];
}
if (!Address::addressExists($address_id)) {
$address_id = null;
}
if ($cart_shop_context->shop->id != $row['id_shop']) {
$cart_shop_context->shop = new Shop((int) $row['id_shop']);
}
$row['shop_name'] = $cart_shop_context->shop->name;
$address = Address::initialize($address_id, true);
$id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $row['id_product'], $cart_shop_context);
$tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
$row['price_without_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, !empty($row['delivery_date']) && $row['delivery_date'] != '0000-00-00' ? 0 : (isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null), 6, null, false, false, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context, true, $row['delivery_date'], $row['delivery_time_from'], $row['delivery_time_to']);
$row['price_with_reduction'] = Product::getPriceStatic((int) $row['id_product'], true, !empty($row['delivery_date']) && $row['delivery_date'] != '0000-00-00' ? 0 : (isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null), 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context, true, $row['delivery_date'], $row['delivery_time_from'], $row['delivery_time_to']);
$row['price'] = $row['price_with_reduction_without_tax'] = Product::getPriceStatic((int) $row['id_product'], false, !empty($row['delivery_date']) && $row['delivery_date'] != '0000-00-00' ? 0 : (isset($row['id_product_attribute']) ? (int) $row['id_product_attribute'] : null), 6, null, false, true, $row['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $specific_price_output, true, true, $cart_shop_context, true, $row['delivery_date'], $row['delivery_time_from'], $row['delivery_time_to']);
switch (Configuration::get('PS_ROUND_TYPE')) {
case Order::ROUND_TOTAL:
$row['total'] = $row['price_with_reduction_without_tax'] * (int) $row['cart_quantity'];
$row['total_wt'] = $row['price_with_reduction'] * (int) $row['cart_quantity'];
break;
case Order::ROUND_LINE:
$row['total'] = Tools::ps_round($row['price_with_reduction_without_tax'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
$row['total_wt'] = Tools::ps_round($row['price_with_reduction'] * (int) $row['cart_quantity'], _PS_PRICE_COMPUTE_PRECISION_);
break;
case Order::ROUND_ITEM:
default:
$row['total'] = Tools::ps_round($row['price_with_reduction_without_tax'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
$row['total_wt'] = Tools::ps_round($row['price_with_reduction'], _PS_PRICE_COMPUTE_PRECISION_) * (int) $row['cart_quantity'];
break;
}
$row['price_wt'] = $row['price_with_reduction'];
$row['description_short'] = Tools::nl2br($row['description_short']);
// check if a image associated with the attribute exists
if ($row['id_product_attribute']) {
$row2 = Image::getBestImageAttribute($row['id_shop'], $this->id_lang, $row['id_product'], $row['id_product_attribute']);
if ($row2) {
$row = array_merge($row, $row2);
}
}
$row['reduction_applies'] = $specific_price_output && (double) $specific_price_output['reduction'];
$row['quantity_discount_applies'] = $specific_price_output && $row['cart_quantity'] >= (int) $specific_price_output['from_quantity'];
$row['id_image'] = Product::defineProductImage($row, $this->id_lang);
$row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']);
$row['features'] = Product::getFeaturesStatic((int) $row['id_product']);
if (array_key_exists($row['id_product_attribute'] . '-' . $this->id_lang, self::$_attributesLists)) {
$row = array_merge($row, self::$_attributesLists[$row['id_product_attribute'] . '-' . $this->id_lang]);
}
$row = Product::getTaxesInformations($row, $cart_shop_context);
$this->_products[] = $row;
}
return $this->_products;
}
示例10: getProducts
//.........这里部分代码省略.........
$query .= JeproshopShopModelShop::addSqlRestrictionOnLang('product_lang', 'cart_product.' . $db->quoteName('shop_id')) . "é LEFT JOIN " . $db->quoteName('#__jeproshop_category_lang') . " AS category_lang";
$query .= " product_shop." . $db->quoteName('default_category_id') . " = category_lang." . $db->quoteName('category_id') . " AND category_lang." . $db->quoteName('lang_id') . " = " . (int) $this->lang_id;
$query .= JeproshopShopModelShop::addSqlRestrictionOnLang('category_lang', 'cart_product.' . $db->quoteName('shop_id')) . "LEFT JOIN " . $db->quoteName('#__jeproshop_product_supplier') . " AS product_supplier ";
$query .= " ON (product_supplier." . $db->quoteName('product_id') . " = cart_product." . $db->quoteName('product_id') . " AND product_supplier." . $db->quoteName('product_attribute_id') . " = cart_product.";
$query .= $db->quoteName('product_attribute_id') . " AND product_supplier." . $db->quoteName('supplier_id') . " = product." . $db->quoteName('supplier_id') . ") LEFT JOIN " . $db->quoteName('#__jeproshop_specific_price');
$query .= " AS specific_price ON specific_price." . $db->quoteName('product_id') . " = cart_product." . $db->quoteName('product_id') . " JOIN " . JeproshopProductModelProduct::sqlStock('cart_product') . $left_join . " WHERE ";
$query .= " cart_product." . $db->quopteName('cart_id') . "= " . (int) $this->cart_id . ($product_id ? " AND cart_product." . $db->quoteName('product_id') . " = " . (int) $product_id : "") . " AND product." . $db->quoteName('product_id');
$query .= " IS NOT NULL GROUP BY unique_id ORDER BY cart_product." . $db->quoteName('date_add') . ", product." . $db->quoteName('product_id') . ", cart_product." . $db->quoteName('product_attribute_id') . " ASC";
$db->setQuery($query);
$result = $db->loadObjectList();
// Reset the cache before the following return, or else an empty cart will add dozens of queries
$products_ids = array();
$product_attribute_ids = array();
if ($result) {
foreach ($result as $row) {
$products_ids[] = $row->product_id;
$product_attribute_ids[] = $row->product_attribute_id;
}
}
// Thus you can avoid one query per product, because there will be only one query for all the products of the cart
JeproshopProductModelProduct::cacheProductsFeatures($products_ids);
JeproshopCartModelCart::cacheSomeAttributesLists($product_attribute_ids, $this->lang_id);
$this->_products = array();
if (empty($result)) {
return array();
}
$cart_shop_context = JeproshopContext::getContext()->cloneContext();
foreach ($result as &$row) {
if (isset($row->ecotax_attr) && $row->ecotax_attr > 0) {
$row->ecotax = (double) $row->ecotax_attr;
}
$row->stock_quantity = (int) $row->quantity;
// for compatibility with 1.2 themes
$row->quantity = (int) $row->cart_quantity;
if (isset($row->product_attribute_id) && (int) $row->product_attribute_id && isset($row->weight_attribute)) {
$row->weight = (double) $row->weight_attribute;
}
if (JeproshopSettingModelSeting::getValue('PS_TAX_ADDRESS_TYPE') == 'address_invoice_id') {
$address_id = (int) $this->address_invoice_id;
} else {
$address_id = (int) $row->address_delivery_id;
}
if (!Address::addressExists($address_id)) {
$address_id = null;
}
if ($cart_shop_context->shop->shop_id != $row['id_shop']) {
$cart_shop_context->shop = new Shop((int) $row['id_shop']);
}
$specific_price_output = null;
$null = null;
if ($this->_taxCalculationMethod == PS_TAX_EXC) {
$row->price = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, isset($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, true, (int) $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context);
// Here taxes are computed only once the quantity has been applied to the product price
$row->price_wt = JeproshopProductModelProduct::getStaticPrice((int) $row->product_id, true, isset($row->product_attribute_id) ? (int) $row->product_attribute_id : null, 2, null, false, true, (int) $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context);
$tax_rate = JeproshopTaxModelTax::getProductTaxRate((int) $row->product_id, (int) $address_id);
$row->total_wt = JeproshopValidator::roundPrice($row->price * (double) $row->cart_quantity * (1 + (double) $tax_rate / 100), 2);
$row->total = $row->price * (int) $row->cart_quantity;
} else {
$row->price = JreproshopProductModelProduct::getStaticPrice((int) $row->product_id, false, (int) $row->product_attribute_id, 2, null, false, true, $row->cart_quantity, false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $specific_price_output, true, true, $cart_shop_context);
$row->price_wt = JeproshopProductModelProduct::getStaticPrice((int) $row['id_product'], true, (int) $row['id_product_attribute'], 2, null, false, true, $row['cart_quantity'], false, (int) $this->customer_id ? (int) $this->customer_id : null, (int) $this->cart_id, (int) $address_id ? (int) $address_id : null, $null, true, true, $cart_shop_context);
// In case when you use QuantityDiscount, getPriceStatic() can be return more of 2 decimals
$row->price_wt = JeproshopValidator::roundPrice($row->price_wt, 2);
$row->total_wt = $row->price_wt * (int) $row->cart_quantity;
$row->total = JeproshopValidator::roundPrice($row['price'] * (int) $row['cart_quantity'], 2);
$row->description_short = Tools::nl2br($row['description_short']);
}
if (!isset($row['pai_id_image']) || $row['pai_id_image'] == 0) {
$cache_id = 'Cart::getProducts_' . '-pai_id_image-' . (int) $row['id_product'] . '-' . (int) $this->lang_id . '-' . (int) $row['id_shop'];
if (!Cache::isStored($cache_id)) {
$row2 = Db::getInstance()->getRow('
SELECT image_shop.`id_image` id_image, il.`legend`
FROM `' . _DB_PREFIX_ . 'image` i
JOIN `' . _DB_PREFIX_ . 'image_shop` image_shop ON (i.id_image = image_shop.id_image AND image_shop.cover=1 AND image_shop.id_shop=' . (int) $row['id_shop'] . ')
LEFT JOIN `' . _DB_PREFIX_ . 'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = ' . (int) $this->lang_id . ')
WHERE i.`id_product` = ' . (int) $row['id_product'] . ' AND image_shop.`cover` = 1');
Cache::store($cache_id, $row2);
}
$row2 = Cache::retrieve($cache_id);
if (!$row2) {
$row2 = array('id_image' => false, 'legend' => false);
} else {
$row = array_merge($row, $row2);
}
} else {
$row->image_id = $row['pai_id_image'];
$row->legend = $row['pai_legend'];
}
$row->reduction_applies = $specific_price_output && (double) $specific_price_output->reduction;
$row->quantity_discount_applies = $specific_price_output && $row->cart_quantity >= (int) $specific_price_output->from_quantity;
$row->image_id = JeproshopProductModelProduct::defineProductImage($row, $this->lang_id);
$row->allow_oosp = JeproshopProductModelProduct::isAvailableWhenOutOfStock($row->out_of_stock);
$row->features = JeproshopProductModelProduct::getStaticFeatures((int) $row->product_id);
if (array_key_exists($row->product_attribute_id . '_' . $this->lang_id, self::$_attributesLists)) {
$row = array_merge($row, self::$_attributesLists[$row->product_attribute_id . '_' . $this->lang_id]);
}
$row = JeproshopProductModelProduct::getTaxesInformations($row, $cart_shop_context);
$this->_products[] = $row;
}
return $this->_products;
}
示例11: getCartXML
/**
* Replace with your own cart here to try out
* different promotions, tax, shipping, etc.
*
* @param merchantID
* @param awsAccessKeyID
*/
private function getCartXML($merchantID, $awsAccessKeyID)
{
$context = Context::getContext();
if ($context->customer->isLogged()) {
$cart_id = (int) $context->cart->id;
$client_id = $context->customer->id . '/' . $cart_id;
} else {
$cart_id = (int) $context->cart->id;
$client_id = '0/' . $cart_id;
}
$site = _PS_BASE_URL_ . __PS_BASE_URI__;
$ReturnUrl = $site . 'module/pwapresta/pwaorder?action=pwa_order&CartId=' . $cart_id;
$doc = new DOMDocument('1.0');
$doc->formatOutput = true;
$root = $doc->createElement('Order');
$attribute = $doc->createAttribute('xmlns');
$attribute->value = 'http://payments.amazon.com/checkout/2009-05-15/';
$root_attr = $root->appendChild($attribute);
$root = $doc->appendChild($root);
$ClientRequestId = $doc->createElement('ClientRequestId', $cart_id);
$ClientRequestId = $root->appendChild($ClientRequestId);
$Cart = $doc->createElement('Cart');
$Cart = $root->appendChild($Cart);
$Items = $doc->createElement('Items');
$Items = $Cart->appendChild($Items);
$CartPromotionId = $doc->createElement('CartPromotionId', 'Total_Discount');
$CartPromotionId = $Cart->appendChild($CartPromotionId);
$Promotions = $doc->createElement('Promotions');
$Promotions = $root->appendChild($Promotions);
$cart_rules = $context->cart->getCartRules();
$total_product_with_tax = $context->cart->getOrderTotal(true, Cart::ONLY_PRODUCTS);
$total_discount_at_amazon_with_tax = $context->cart->getOrderTotal(true, Cart::ONLY_DISCOUNTS);
$total_wrapping_with_tax = $context->cart->getOrderTotal(true, Cart::ONLY_WRAPPING);
global $currency;
$currency_iso_code = $currency->iso_code;
if ($total_discount_at_amazon_with_tax) {
$Promotion = $doc->createElement('Promotion');
$Promotion = $Promotions->appendChild($Promotion);
$Promotion_pro_id = $doc->createElement('PromotionId', 'Total_Discount');
$Promotion_pro_id = $Promotion->appendChild($Promotion_pro_id);
$Promotion_pro_desc = $doc->createElement('Description', 'Total discount at cart level');
$Promotion_pro_desc = $Promotion->appendChild($Promotion_pro_desc);
$Promotion_pro_benf = $doc->createElement('Benefit');
$Promotion_pro_benf = $Promotion->appendChild($Promotion_pro_benf);
$Promotion_pro_benf_fad = $doc->createElement('FixedAmountDiscount');
$Promotion_pro_benf_fad = $Promotion_pro_benf->appendChild($Promotion_pro_benf_fad);
$Promotion_pro_benf_fad_amount = $doc->createElement('Amount', $total_discount_at_amazon_with_tax);
$Promotion_pro_benf_fad_amount = $Promotion_pro_benf_fad->appendChild($Promotion_pro_benf_fad_amount);
$Promotion_pro_benf_fad_currency = $doc->createElement('CurrencyCode', $currency_iso_code);
$Promotion_pro_benf_fad_currency = $Promotion_pro_benf_fad->appendChild($Promotion_pro_benf_fad_currency);
}
$products = $context->cart->getProducts();
foreach ($products as $key => $product) {
$product_id = $product['id_product'];
$sku = $product['reference'];
$sku = substr($sku, 0, 40);
$sku = $this->replace_char($sku);
$sku = htmlentities($sku, ENT_QUOTES, 'UTF-8');
$title = $product['name'];
if (!$title) {
$title = 'Title';
}
$title = substr($title, 0, 80);
$title = $this->replace_char($title);
$title = htmlentities($title, ENT_QUOTES, 'UTF-8');
$description = $product['description_short'];
$description = substr($description, 0, 1900);
$description = $this->replace_char($description);
$description = htmlentities($description, ENT_QUOTES, 'UTF-8');
$quantity = $product['quantity'];
$weight = $product['weight'];
$weight_unit = Configuration::get('PS_WEIGHT_UNIT');
if ($weight_unit != 'kg' && $weight > 0) {
$weight = $weight / 1000;
$weight_unit = 'kg';
}
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address_id = (int) $this->id_address_invoice;
} else {
$address_id = (int) $product['id_address_delivery'];
}
// Get delivery address of the product from the cart
if (!Address::addressExists($address_id)) {
$address_id = null;
}
$virtual_context = Context::getContext()->cloneContext();
$virtual_context->cart = $context->cart;
$product_price = Product::getPriceStatic((int) $product['id_product'], true, (int) $product['id_product_attribute'], 2, null, false, true, $product['cart_quantity'], false, (int) $context->cart->id_customer ? (int) $context->cart->id_customer : null, (int) $context->cart->id, (int) $address_id ? (int) $address_id : null, $null, true, true, $virtual_context);
$product_price_exl_tax = Product::getPriceStatic((int) $product['id_product'], false, (int) $product['id_product_attribute'], 2, null, false, true, $product['cart_quantity'], false, (int) $context->cart->id_customer ? (int) $context->cart->id_customer : null, (int) $context->cart->id, (int) $address_id ? (int) $address_id : null, $null, true, true, $virtual_context);
$Item = $doc->createElement('Item');
$Item = $Items->appendChild($Item);
$SKU = $doc->createElement('SKU', $sku);
$SKU = $Item->appendChild($SKU);
//.........这里部分代码省略.........
示例12: getOrderTotal
public function getOrderTotal($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true)
{
static $address = null;
if (!$this->id) {
return 0;
}
$type = (int) $type;
$array_type = array(Cart::ONLY_PRODUCTS, Cart::ONLY_DISCOUNTS, Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_SHIPPING, Cart::ONLY_WRAPPING, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING);
// Define virtual context to prevent case where the cart is not the in the global context
$virtual_context = Context::getContext()->cloneContext();
$virtual_context->cart = $this;
if (!in_array($type, $array_type)) {
die(Tools::displayError());
}
$with_shipping = in_array($type, array(Cart::BOTH, Cart::ONLY_SHIPPING));
// if cart rules are not used
if ($type == Cart::ONLY_DISCOUNTS && !CartRule::isFeatureActive()) {
return 0;
}
// no shipping cost if is a cart with only virtuals products
$virtual = $this->isVirtualCart();
if ($virtual && $type == Cart::ONLY_SHIPPING) {
return 0;
}
if ($virtual && $type == Cart::BOTH) {
$type = Cart::BOTH_WITHOUT_SHIPPING;
}
if ($with_shipping || $type == Cart::ONLY_DISCOUNTS) {
if (is_null($products) && is_null($id_carrier)) {
$shipping_fees = $this->getTotalShippingCost(null, (bool) $with_taxes);
} else {
$shipping_fees = $this->getPackageShippingCost($id_carrier, (bool) $with_taxes, null, $products);
}
} else {
$shipping_fees = 0;
}
if ($type == Cart::ONLY_SHIPPING) {
return $shipping_fees;
}
if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING) {
$type = Cart::ONLY_PRODUCTS;
}
$param_product = true;
if (is_null($products)) {
$param_product = false;
$products = $this->getProducts();
}
if ($type == Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING) {
foreach ($products as $key => $product) {
if ($product['is_virtual']) {
unset($products[$key]);
}
}
$type = Cart::ONLY_PRODUCTS;
}
$order_total = 0;
if (Tax::excludeTaxeOption()) {
$with_taxes = false;
}
$products_total = array();
$ecotax_total = 0;
foreach ($products as $product) {
if ($virtual_context->shop->id != $product['id_shop']) {
$virtual_context->shop = new Shop((int) $product['id_shop']);
}
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$id_address = (int) $this->id_address_invoice;
} else {
$id_address = (int) $product['id_address_delivery'];
}
// Get delivery address of the product from the cart
if (!Address::addressExists($id_address)) {
$id_address = null;
}
$null = null;
$price = Product::getPriceStatic((int) $product['id_product'], false, (int) $product['id_product_attribute'], 6, null, false, true, array($product['cart_quantity'], $product['cart_quantity_fractional']), false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $id_address, $null, false, true, $virtual_context);
if (Configuration::get('PS_USE_ECOTAX')) {
$ecotax = $product['ecotax'];
if (isset($product['attribute_ecotax']) && $product['attribute_ecotax'] > 0) {
$ecotax = $product['attribute_ecotax'];
}
} else {
$ecotax = 0;
}
$address = Address::initialize($id_address, true);
if ($with_taxes) {
$id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $product['id_product'], $virtual_context);
$tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
if ($ecotax) {
$ecotax_tax_calculator = TaxManagerFactory::getManager($address, (int) Configuration::get('PS_ECOTAX_TAX_RULES_GROUP_ID'))->getTaxCalculator();
}
} else {
$id_tax_rules_group = 0;
}
if (in_array(Configuration::get('PS_ROUND_TYPE'), array(Order::ROUND_ITEM, Order::ROUND_LINE))) {
if (!isset($products_total[$id_tax_rules_group])) {
$products_total[$id_tax_rules_group] = 0;
}
} else {
if (!isset($products_total[$id_tax_rules_group . '_' . $id_address])) {
//.........这里部分代码省略.........
示例13: getOrderTotal
/**
* This function returns the total cart amount
*
* Possible values for $type:
* Cart::ONLY_PRODUCTS
* Cart::ONLY_DISCOUNTS
* Cart::BOTH
* Cart::BOTH_WITHOUT_SHIPPING
* Cart::ONLY_SHIPPING
* Cart::ONLY_WRAPPING
* Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING
* Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING
*
* @param boolean $withTaxes With or without taxes
* @param integer $type Total type
* @param boolean $use_cache Allow using cache of the method CartRule::getContextualValue
* @return float Order total
*/
public function getOrderTotal($with_taxes = true, $type = Cart::BOTH, $products = null, $id_carrier = null, $use_cache = true)
{
if (!$this->id) {
return 0;
}
$type = (int) $type;
$array_type = array(Cart::ONLY_PRODUCTS, Cart::ONLY_DISCOUNTS, Cart::BOTH, Cart::BOTH_WITHOUT_SHIPPING, Cart::ONLY_SHIPPING, Cart::ONLY_WRAPPING, Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING, Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING);
// Define virtual context to prevent case where the cart is not the in the global context
$virtual_context = Context::getContext()->cloneContext();
$virtual_context->cart = $this;
if (!in_array($type, $array_type)) {
die(Tools::displayError());
}
$with_shipping = in_array($type, array(Cart::BOTH, Cart::ONLY_SHIPPING));
// if cart rules are not used
if ($type == Cart::ONLY_DISCOUNTS && !CartRule::isFeatureActive()) {
return 0;
}
// no shipping cost if is a cart with only virtuals products
$virtual = $this->isVirtualCart();
if ($virtual && $type == Cart::ONLY_SHIPPING) {
return 0;
}
if ($virtual && $type == Cart::BOTH) {
$type = Cart::BOTH_WITHOUT_SHIPPING;
}
if ($with_shipping || $type == Cart::ONLY_DISCOUNTS) {
if (is_null($products) && is_null($id_carrier)) {
$shipping_fees = $this->getTotalShippingCost(null, (bool) $with_taxes);
} else {
$shipping_fees = $this->getPackageShippingCost($id_carrier, (bool) $with_taxes, null, $products);
}
} else {
$shipping_fees = 0;
}
$shipping_fees = self::updateShippingCost($shipping_fees);
if ($type == Cart::ONLY_SHIPPING) {
$shipping_fees;
}
if ($type == Cart::ONLY_PRODUCTS_WITHOUT_SHIPPING) {
$type = Cart::ONLY_PRODUCTS;
}
$param_product = true;
if (is_null($products)) {
$param_product = false;
$products = $this->getProducts();
}
if ($type == Cart::ONLY_PHYSICAL_PRODUCTS_WITHOUT_SHIPPING) {
foreach ($products as $key => $product) {
if ($product['is_virtual']) {
unset($products[$key]);
}
}
$type = Cart::ONLY_PRODUCTS;
}
$order_total = 0;
if (Tax::excludeTaxeOption()) {
$with_taxes = false;
}
foreach ($products as $product) {
if ($virtual_context->shop->id != $product['id_shop']) {
$virtual_context->shop = new Shop((int) $product['id_shop']);
}
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address_id = (int) $this->id_address_invoice;
} else {
$address_id = (int) $product['id_address_delivery'];
}
// Get delivery address of the product from the cart
if (!Address::addressExists($address_id)) {
$address_id = null;
}
if ($this->_taxCalculationMethod == PS_TAX_EXC) {
// Here taxes are computed only once the quantity has been applied to the product price
$price = Product::getPriceStatic((int) $product['id_product'], false, (int) $product['id_product_attribute'], 2, null, false, true, $product['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $address_id, $null, true, true, $virtual_context);
$total_ecotax = $product['ecotax'] * (int) $product['cart_quantity'];
$total_price = $price * (int) $product['cart_quantity'];
if ($with_taxes) {
$product_tax_rate = (double) Tax::getProductTaxRate((int) $product['id_product'], (int) $address_id, $virtual_context);
$product_eco_tax_rate = Tax::getProductEcotaxRate((int) $address_id);
$total_price = ($total_price - $total_ecotax) * (1 + $product_tax_rate / 100);
$total_ecotax = $total_ecotax * (1 + $product_eco_tax_rate / 100);
//.........这里部分代码省略.........