本文整理汇总了PHP中Address::initialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Address::initialize方法的具体用法?PHP Address::initialize怎么用?PHP Address::initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Address
的用法示例。
在下文中一共展示了Address::initialize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPackageShippingCost
//.........这里部分代码省略.........
}
if (!isset($min_shipping_price)) {
$min_shipping_price = $shipping;
}
if ($shipping <= $min_shipping_price) {
$id_carrier = (int) $row['id_carrier'];
$min_shipping_price = $shipping;
}
}
}
if (empty($id_carrier)) {
$id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
}
if (!isset(self::$_carriers[$id_carrier])) {
self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
}
$carrier = self::$_carriers[$id_carrier];
// No valid Carrier or $id_carrier <= 0 ?
if (!Validate::isLoadedObject($carrier)) {
Cache::store($cache_id, 0);
return 0;
}
if (!$carrier->active) {
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
// Free fees if free carrier
if ($carrier->is_free == 1) {
Cache::store($cache_id, 0);
return 0;
}
// Select carrier tax
if ($use_tax && !Tax::excludeTaxeOption()) {
$address = Address::initialize((int) $address_id);
$carrier_tax = $carrier->getTaxesRate($address);
}
$configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
// Free fees
$free_fees_price = 0;
if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
$free_fees_price = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
}
$orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
if ($orderTotalwithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) {
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
// Get shipping cost using correct method
if ($carrier->range_behavior) {
if (!isset($id_zone)) {
// Get id zone
if (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 {
$id_zone = (int) $default_country->id_zone;
}
}
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !Carrier::checkDeliveryPriceByWeight($carrier->id, $this->getTotalWeight(), (int) $id_zone) || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !Carrier::checkDeliveryPriceByPrice($carrier->id, $total_package_without_shipping_tax_inc, $id_zone, (int) $this->id_currency)) {
$shipping_cost += 0;
} else {
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
$shipping_cost += $carrier->getDeliveryPriceByWeight($this->getTotalWeight($product_list), $id_zone);
示例2: createAddress
/**
* Create or Updates Prestashop address
* @return Address Address object
*/
protected function createAddress($addressInformations, $address = null)
{
$country = $this->getCountryByCode($addressInformations->country->alpha2Code);
if (!$country->active) {
$this->addError(sprintf($this->module->l('This country is not active : %s'), $addressInformations->country->alpha2Code), PowaTagErrorType::$MERCHANT_WRONG_COUNTRY);
return false;
}
if (!isset($addressInformations->friendlyName)) {
$friendlyName = $this->module->l('My address');
} else {
$friendlyName = $addressInformations->friendlyName;
}
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Create address', PowaTagLogs::IN_PROGRESS, $addressInformations->lastName . ' ' . $addressInformations->firstName . ' : ' . $friendlyName);
}
$address = $address != null ? $address : Address::initialize();
$address->id_customer = (int) $this->customer->id;
$address->id_country = (int) $country->id;
$address->alias = $friendlyName;
$address->lastname = $addressInformations->lastName;
$address->firstname = $addressInformations->firstName;
$address->address1 = $addressInformations->line1;
$address->address2 = $addressInformations->line2;
$address->postcode = $addressInformations->postCode;
$address->city = $addressInformations->city;
$address->phone = isset($addressInformations->phone) ? $addressInformations->phone : '0000000000';
$address->id_state = isset($addressInformations->state) ? (int) State::getIdByIso($addressInformations->state, (int) $country->id) : 0;
if (!$address->save()) {
$this->addError($this->module->l('Impossible to save address'), PowaTagErrorType::$INTERNAL_ERROR);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Create address', PowaTagLogs::ERROR, $this->error['message']);
}
return false;
}
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Create address', PowaTagLogs::SUCCESS, 'Address ID : ' . $address->id);
}
return $address;
}
示例3: create
public static function create(Order $order, $product_list, $shipping_cost = false, $amount = 0, $amount_choosen = false, $add_tax = true)
{
$currency = new Currency((int) $order->id_currency);
$order_slip = new OrderSlip();
$order_slip->id_customer = (int) $order->id_customer;
$order_slip->id_order = (int) $order->id;
$order_slip->conversion_rate = $currency->conversion_rate;
if ($add_tax) {
$add_or_remove = 'add';
$inc_or_ex_1 = 'excl';
$inc_or_ex_2 = 'incl';
} else {
$add_or_remove = 'remove';
$inc_or_ex_1 = 'incl';
$inc_or_ex_2 = 'excl';
}
$order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = 0;
$order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = 0;
$order_slip->partial = 0;
if ($shipping_cost !== false) {
$order_slip->shipping_cost = true;
$carrier = new Carrier((int) $order->id_carrier);
$address = Address::initialize($order->id_address_delivery, false);
$tax_calculator = $carrier->getTaxCalculator($address);
$order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = $shipping_cost === null ? $order->{'total_shipping_tax_' . $inc_or_ex_1} : (double) $shipping_cost;
if ($tax_calculator instanceof TaxCalculator) {
$order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($order_slip->{'total_shipping_tax_' . $inc_or_ex_1}), _PS_PRICE_COMPUTE_PRECISION_);
} else {
$order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
}
} else {
$order_slip->shipping_cost = false;
}
$order_slip->amount = 0;
$order_slip->{'total_products_tax_' . $inc_or_ex_1} = 0;
$order_slip->{'total_products_tax_' . $inc_or_ex_2} = 0;
foreach ($product_list as &$product) {
$order_detail = new OrderDetail((int) $product['id_order_detail']);
$price = (double) $product['unit_price'];
$quantity = (int) $product['quantity'];
$order_slip_resume = OrderSlip::getProductSlipResume((int) $order_detail->id);
if ($quantity + $order_slip_resume['product_quantity'] > $order_detail->product_quantity) {
$quantity = $order_detail->product_quantity - $order_slip_resume['product_quantity'];
}
if ($quantity == 0) {
continue;
}
if (!Tools::isSubmit('cancelProduct') && $order->hasBeenPaid()) {
$order_detail->product_quantity_refunded += $quantity;
}
$order_detail->save();
$address = Address::initialize($order->id_address_invoice, false);
$id_address = (int) $address->id;
$id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $order_detail->product_id);
$tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
$order_slip->{'total_products_tax_' . $inc_or_ex_1} += $price * $quantity;
if (in_array(Configuration::get('PS_ROUND_TYPE'), array(Order::ROUND_ITEM, Order::ROUND_LINE))) {
if (!isset($total_products[$id_tax_rules_group])) {
$total_products[$id_tax_rules_group] = 0;
}
} else {
if (!isset($total_products[$id_tax_rules_group . '_' . $id_address])) {
$total_products[$id_tax_rules_group . '_' . $id_address] = 0;
}
}
$product_tax_incl_line = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price) * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
switch (Configuration::get('PS_ROUND_TYPE')) {
case Order::ROUND_ITEM:
$product_tax_incl = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_) * $quantity;
$total_products[$id_tax_rules_group] += $product_tax_incl;
break;
case Order::ROUND_LINE:
$product_tax_incl = $product_tax_incl_line;
$total_products[$id_tax_rules_group] += $product_tax_incl;
break;
case Order::ROUND_TOTAL:
$product_tax_incl = $product_tax_incl_line;
$total_products[$id_tax_rules_group . '_' . $id_address] += $price * $quantity;
break;
}
$product['unit_price_tax_' . $inc_or_ex_1] = $price;
$product['unit_price_tax_' . $inc_or_ex_2] = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
$product['total_price_tax_' . $inc_or_ex_1] = Tools::ps_round($price * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
$product['total_price_tax_' . $inc_or_ex_2] = Tools::ps_round($product_tax_incl, _PS_PRICE_COMPUTE_PRECISION_);
}
unset($product);
foreach ($total_products as $key => $price) {
if (Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL) {
$tmp = explode('_', $key);
$address = Address::initialize((int) $tmp[1], true);
$tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator();
$order_slip->{'total_products_tax_' . $inc_or_ex_2} += Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
} else {
$order_slip->{'total_products_tax_' . $inc_or_ex_2} += $price;
}
}
$order_slip->{'total_products_tax_' . $inc_or_ex_2} -= (double) $amount && !$amount_choosen ? (double) $amount : 0;
$order_slip->amount = $amount_choosen ? (double) $amount : $order_slip->{'total_products_tax_' . $inc_or_ex_1};
$order_slip->shipping_cost_amount = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
if ((double) $amount && !$amount_choosen) {
//.........这里部分代码省略.........
示例4: getTaxesRate
/**
* @return the total taxes rate applied to the product
*/
public function getTaxesRate(Address $address = null)
{
if (!$address || !$address->id_country) {
$address = Address::initialize();
}
$tax_manager = TaxManagerFactory::getManager($address, $this->id_tax_rules_group);
$tax_calculator = $tax_manager->getTaxCalculator();
return $tax_calculator->getTotalRate();
}
示例5: getProductTaxRate
/**
* Returns the product tax
*
* @param integer $id_product
* @param integer $id_country
* @return Tax
*/
public static function getProductTaxRate($id_product, $id_address = null, Context $context = null)
{
if ($context == null) {
$context = Context::getContext();
}
$address = Address::initialize($id_address);
$id_tax_rules = (int) Product::getIdTaxRulesGroupByIdProduct($id_product, $context);
$tax_manager = TaxManagerFactory::getManager($address, $id_tax_rules);
$tax_calculator = $tax_manager->getTaxCalculator();
return $tax_calculator->getTotalRate();
}
示例6: getPackageShippingCost
//.........这里部分代码省略.........
} else {
$shipping = $carrier->getDeliveryPriceByPrice($order_total, (int) $id_zone, (int) $this->id_currency);
}
if (!isset($min_shipping_price)) {
$min_shipping_price = $shipping;
}
if ($shipping <= $min_shipping_price) {
$id_carrier = (int) $row['id_carrier'];
$min_shipping_price = $shipping;
}
}
}
if (empty($id_carrier)) {
$id_carrier = Configuration::get('PS_CARRIER_DEFAULT');
}
if (!isset(self::$_carriers[$id_carrier])) {
self::$_carriers[$id_carrier] = new Carrier((int) $id_carrier, Configuration::get('PS_LANG_DEFAULT'));
}
$carrier = self::$_carriers[$id_carrier];
if (!Validate::isLoadedObject($carrier)) {
die(Tools::displayError('Fatal error: "no default carrier"'));
}
if (!$carrier->active) {
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
// Free fees if free carrier
if ($carrier->is_free == 1) {
Cache::store($cache_id, 0);
return 0;
}
// Select carrier tax
if ($use_tax && !Tax::excludeTaxeOption()) {
$address = Address::initialize((int) $address_id);
$carrier_tax = $carrier->getTaxesRate($address);
}
$configuration = Configuration::getMultiple(array('PS_SHIPPING_FREE_PRICE', 'PS_SHIPPING_HANDLING', 'PS_SHIPPING_METHOD', 'PS_SHIPPING_FREE_WEIGHT'));
// Free fees
$free_fees_price = 0;
if (isset($configuration['PS_SHIPPING_FREE_PRICE'])) {
$free_fees_price = Tools::convertPrice((double) $configuration['PS_SHIPPING_FREE_PRICE'], Currency::getCurrencyInstance((int) $this->id_currency));
}
$orderTotalwithDiscounts = $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, null, null, false);
if ($orderTotalwithDiscounts >= (double) $free_fees_price && (double) $free_fees_price > 0) {
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
if (isset($configuration['PS_SHIPPING_FREE_WEIGHT']) && $this->getTotalWeight() >= (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] && (double) $configuration['PS_SHIPPING_FREE_WEIGHT'] > 0) {
Cache::store($cache_id, $shipping_cost);
return $shipping_cost;
}
// Get shipping cost using correct method
if ($carrier->range_behavior) {
// Get id zone
if (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 {
$id_zone = (int) $default_country->id_zone;
}
$check_delivery_price_by_weight = Carrier::checkDeliveryPriceByWeight((int) $carrier->id, $this->getTotalWeight(), (int) $id_zone);
// Code Review V&V TO FINISH
$check_delivery_price_by_price = Carrier::checkDeliveryPriceByPrice($carrier->id, $this->getOrderTotal(true, Cart::BOTH_WITHOUT_SHIPPING, $product_list), $id_zone, (int) $this->id_currency);
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT && !$check_delivery_price_by_weight || $carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_PRICE && !$check_delivery_price_by_price) {
$shipping_cost += 0;
} else {
if ($carrier->getShippingMethod() == Carrier::SHIPPING_METHOD_WEIGHT) {
示例7: _displaySpecificPriceModificationForm
protected function _displaySpecificPriceModificationForm($defaultCurrency, $shops, $currencies, $countries, $groups)
{
$lpdesmvcrvu = "specific_price_priorities";
${"GLOBALS"}["gwvlvnhgf"] = "group";
$plkmtiqjex = "specific_price_priorities";
${"GLOBALS"}["ertbhqqwavl"] = "tmp";
${"GLOBALS"}["glybiybrjmv"] = "group";
${"GLOBALS"}["nihfjn"] = "tmp";
$ivhgohevles = "taxRate";
${${"GLOBALS"}["nkvjzc"]} = "";
${"GLOBALS"}["ukanssy"] = "currencies";
if (!$this->object) {
return;
}
${"GLOBALS"}["tfufwuqnbgxc"] = "tmp";
${${"GLOBALS"}["ixsaqwcye"]} = SpecificPrice::getByProductId((int) $this->object->id);
$rarsexno = "shop";
$vrcmtksat = "shop";
$gedaion = "specific_price_priorities";
${"GLOBALS"}["xsrbwsm"] = "shops";
${$lpdesmvcrvu} = SpecificPrice::getPriority((int) $this->object->id);
${$ivhgohevles} = $this->object->getTaxesRate(Address::initialize());
$uhzkmfbqi = "shop";
$ahuedic = "specific_price_priorities";
${${"GLOBALS"}["bdtyklee"]} = array();
foreach (${${"GLOBALS"}["xsrbwsm"]} as ${$uhzkmfbqi}) {
${${"GLOBALS"}["bdtyklee"]}[${$rarsexno}["id_shop"]] = ${$vrcmtksat};
}
$rbdspr = "currencies";
${"GLOBALS"}["ruiubiwy"] = "countries";
$nyuyhmkcene = "content";
${${"GLOBALS"}["lazfnitt"]} = ${${"GLOBALS"}["bdtyklee"]};
$hcdvvpbef = "tmp";
$wdrtujtw = "currency";
${${"GLOBALS"}["nihfjn"]} = array();
foreach (${$rbdspr} as ${${"GLOBALS"}["qwffcfylwvlg"]}) {
${${"GLOBALS"}["bdtyklee"]}[${$wdrtujtw}["id_currency"]] = ${${"GLOBALS"}["qwffcfylwvlg"]};
}
${${"GLOBALS"}["ukanssy"]} = ${${"GLOBALS"}["ertbhqqwavl"]};
${${"GLOBALS"}["tfufwuqnbgxc"]} = array();
foreach (${${"GLOBALS"}["ruiubiwy"]} as ${${"GLOBALS"}["dtehljxk"]}) {
${${"GLOBALS"}["bdtyklee"]}[${${"GLOBALS"}["dtehljxk"]}["id_country"]] = ${${"GLOBALS"}["dtehljxk"]};
}
$tclsxk = "specific_price_priorities";
${${"GLOBALS"}["kroabu"]} = ${${"GLOBALS"}["bdtyklee"]};
${$hcdvvpbef} = array();
foreach (${${"GLOBALS"}["myyouyoez"]} as ${${"GLOBALS"}["gwvlvnhgf"]}) {
${${"GLOBALS"}["bdtyklee"]}[${${"GLOBALS"}["oxbcew"]}["id_group"]] = ${${"GLOBALS"}["glybiybrjmv"]};
}
${"GLOBALS"}["cptxpwqsgzo"] = "content";
${${"GLOBALS"}["myyouyoez"]} = ${${"GLOBALS"}["bdtyklee"]};
if (!is_array(${${"GLOBALS"}["ixsaqwcye"]}) || !count(${${"GLOBALS"}["ixsaqwcye"]})) {
${${"GLOBALS"}["nkvjzc"]} .= "\n\t\t\t\t<tr>\n\t\t\t\t\t<td colspan=\"13\">" . $this->l('No specific prices') . "</td>\n\t\t\t\t</tr>";
} else {
${"GLOBALS"}["ixvreqo"] = "specific_prices";
${${"GLOBALS"}["eqiehjn"]} = 0;
${"GLOBALS"}["xwjpok"] = "specific_price";
foreach (${${"GLOBALS"}["ixvreqo"]} as ${${"GLOBALS"}["xwjpok"]}) {
${"GLOBALS"}["jgkoendjlpt"] = "specific_price";
$sdpwvfzmwy = "current_specific_currency";
${"GLOBALS"}["drapxqkxjfw"] = "customer_full_name";
${"GLOBALS"}["wrefbrz"] = "specific_price";
$ywnqxjizw = "impact";
$pmhlqxsivhg = "currencies";
${"GLOBALS"}["lnqbpvxxuw"] = "i";
$qndkwpcllv = "specific_price";
${"GLOBALS"}["cfbvjzjfz"] = "specific_price";
${"GLOBALS"}["hyijedlreo"] = "specific_price";
${"GLOBALS"}["bdnvmedpllw"] = "customer_full_name";
${"GLOBALS"}["yonxxgguvyc"] = "shops";
${"GLOBALS"}["brpkiqjctz"] = "specific_price";
${"GLOBALS"}["cubiilo"] = "customer_full_name";
$msgvsejfwpg = "specific_price";
${"GLOBALS"}["ihxryxdypi"] = "groups";
$frcvwum = "rule";
$fpsxqukp = "price";
${"GLOBALS"}["ucfgiwdbfvge"] = "period";
${"GLOBALS"}["pjigladsg"] = "fixed_price";
${"GLOBALS"}["qrcsyna"] = "specific_price";
$nwumqlplzzwc = "specific_price";
$tihycjulltff = "impact";
${$sdpwvfzmwy} = ${$pmhlqxsivhg}[${${"GLOBALS"}["oudwfbvcvoj"]}["id_currency"] ? ${${"GLOBALS"}["cfbvjzjfz"]}["id_currency"] : $defaultCurrency->id];
${"GLOBALS"}["wxttwnsgf"] = "specific_price";
if (${${"GLOBALS"}["oudwfbvcvoj"]}["reduction_type"] == "percentage") {
${$ywnqxjizw} = "- " . ${${"GLOBALS"}["oudwfbvcvoj"]}["reduction"] * 100 . " %";
} elseif (${${"GLOBALS"}["oudwfbvcvoj"]}["reduction"] > 0) {
${${"GLOBALS"}["uaxmvunoy"]} = "- " . Tools::displayPrice(Tools::ps_round(${$nwumqlplzzwc}["reduction"], 2), ${${"GLOBALS"}["lbhedgts"]});
} else {
${$tihycjulltff} = "--";
}
${"GLOBALS"}["nwsoorkiv"] = "impact";
if (${${"GLOBALS"}["jgkoendjlpt"]}["from"] == "0000-00-00 00:00:00" && ${${"GLOBALS"}["oudwfbvcvoj"]}["to"] == "0000-00-00 00:00:00") {
${${"GLOBALS"}["zcpltzs"]} = $this->l('Unlimited');
} else {
${${"GLOBALS"}["zcpltzs"]} = $this->l('From') . " " . (${${"GLOBALS"}["wxttwnsgf"]}["from"] != "0000-00-00 00:00:00" ? ${${"GLOBALS"}["oudwfbvcvoj"]}["from"] : "0000-00-00 00:00:00") . "<br />" . $this->l('To') . " " . (${${"GLOBALS"}["oudwfbvcvoj"]}["to"] != "0000-00-00 00:00:00" ? ${${"GLOBALS"}["oudwfbvcvoj"]}["to"] : "0000-00-00 00:00:00");
}
if (${${"GLOBALS"}["oudwfbvcvoj"]}["id_product_attribute"]) {
${"GLOBALS"}["ysyybwjtlnlr"] = "attributes_name";
$supdob = "attributes_name";
$nwznli = "attribute";
//.........这里部分代码省略.........
示例8: getProducts
//.........这里部分代码省略.........
$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))
{
$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->id_lang.')
WHERE i.`id_product` = '.(int)$row['id_product'].' AND image_shop.`cover` = 1'
示例9: getAddressModel
public function getAddressModel()
{
$model = new Address();
return $model->initialize($this->getParameters());
}
示例10: addProductsToCart
/**
* Add Products to cart
* @param Cart $cart Cart object
*/
private function addProductsToCart($cart, $codeCountry)
{
$products = $this->datas->orderLineItems;
$country = $this->getCountry($codeCountry);
$address = Address::initialize();
$address->id_country = $country->id;
if ($products && count($products)) {
foreach ($products as $p) {
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::IN_PROGRESS, 'Product : ' . $p->product->code);
}
$product = PowaTagProductHelper::getProductByCode($p->product->code, $this->context->language->id);
if (!Validate::isLoadedObject($product)) {
$this->addError(sprintf($this->module->l('This product does not exists : %s'), $p->product->code), PowaTagErrorType::$SKU_NOT_FOUND);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
$variants = $p->product->productVariants;
$product_rate = 1 + $product->getTaxesRate($address) / 100;
foreach ($variants as $variant) {
$variantCurrency = $this->getCurrencyByIsoCode($variant->finalPrice->currency);
if (!PowaTagValidate::currencyEnable($variantCurrency)) {
$this->addError(sprintf($this->module->l('Currency not found : %s'), $variant->code), PowaTagErrorType::$CURRENCY_NOT_SUPPORTED);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
$variantAmount = $variant->finalPrice->amount;
$id_product_attribute = false;
$combination = false;
if ($id_product_attribute = PowaTagProductAttributeHelper::getCombinationByCode($product->id, $variant->code)) {
$combination = new Combination($id_product_attribute);
$priceAttribute = $product->getPrice($this->display_taxes, $id_product_attribute);
$qtyInStock = PowaTagProductQuantityHelper::getProductQuantity($product, $id_product_attribute);
} else {
if ($product) {
$priceAttribute = $product->getPrice($this->display_taxes);
$qtyInStock = PowaTagProductQuantityHelper::getProductQuantity($product);
} else {
$this->addError(sprintf($this->module->l('This variant does not exist : %s'), $variant->code), PowaTagErrorType::$SKU_NOT_FOUND);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
}
if ($qtyInStock == 0) {
$this->addError(sprintf($this->module->l('No Stock Available')), PowaTagErrorType::$SKU_OUT_OF_STOCK);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
if ($qtyInStock < $p->quantity) {
$this->addError(sprintf($this->module->l('Quantity > Stock Count')), PowaTagErrorType::$INSUFFICIENT_STOCK);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
if ($p->quantity < $product->minimal_quantity || $combination && $combination->minimal_quantity > $p->quantity) {
$this->addError(sprintf($this->module->l('Quantity < minimal quantity for product')), PowaTagErrorType::$OTHER_STOCK_ERROR);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::ERROR, 'Product : ' . $this->error['message']);
}
return false;
}
$cart->updateQty($p->quantity, $product->id, $id_product_attribute);
if (PowaTagAPI::apiLog()) {
PowaTagLogs::initAPILog('Add product to cart', PowaTagLogs::SUCCESS, 'Cart ID : ' . $cart->id . ' - Product ID : ' . $product->id);
}
break;
}
}
} else {
$this->addError($this->module->l('No product found in request'), PowaTagErrorType::$SKU_NOT_FOUND);
return false;
}
// add vouchers
if (isset($this->datas->vouchers)) {
$this->context->cart = $cart;
$vouchers = $this->datas->vouchers;
if ($vouchers && count($vouchers)) {
foreach ($vouchers as $voucher) {
$ci = CartRule::getIdByCode($voucher);
if (!$ci) {
continue;
}
$cr = new CartRule($ci);
if (!$cr) {
continue;
}
if ($error = $cr->checkValidity($this->context, false, true)) {
//.........这里部分代码省略.........
示例11: getGiftWrappingPrice
/**
* Get the gift wrapping price
* @param boolean $with_taxes With or without taxes
* @return float wrapping price
*/
public function getGiftWrappingPrice($with_taxes = true, $id_address = null)
{
static $address = null;
$wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
if ($with_taxes && $wrapping_fees > 0) {
if ($address === null) {
if ($id_address === null) {
$id_address = (int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
}
try {
$address = Address::initialize($id_address);
} catch (Exception $e) {
$address = new Address();
$address->id_country = Configuration::get('PS_COUNTRY_DEFAULT');
}
}
$tax_manager = TaxManagerFactory::getManager($address, (int) Configuration::get('PS_GIFT_WRAPPING_TAX_RULES_GROUP'));
$tax_calculator = $tax_manager->getTaxCalculator();
$wrapping_fees = $tax_calculator->addTaxes($wrapping_fees);
}
return $wrapping_fees;
}
示例12: create
public static function create(Order $order, $product_list, $shipping_cost = false, $amount = 0, $amount_choosen = false, $add_tax = true)
{
$currency = new Currency((int) $order->id_currency);
$order_slip = new OrderSlip();
$order_slip->id_customer = (int) $order->id_customer;
$order_slip->id_order = (int) $order->id;
$order_slip->conversion_rate = $currency->conversion_rate;
if ($add_tax) {
$add_or_remove = 'add';
$inc_or_ex_1 = 'excl';
$inc_or_ex_2 = 'incl';
} else {
$add_or_remove = 'remove';
$inc_or_ex_1 = 'incl';
$inc_or_ex_2 = 'excl';
}
$order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = 0;
$order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = 0;
$order_slip->partial = 0;
if ($shipping_cost !== false) {
$order_slip->shipping_cost = true;
$carrier = new Carrier((int) $order->id_carrier);
$address = Address::initialize($order->id_address_delivery, false);
$tax_calculator = $carrier->getTaxCalculator($address);
$order_slip->{'total_shipping_tax_' . $inc_or_ex_1} = $shipping_cost === null ? $order->{'total_shipping_tax_' . $inc_or_ex_1} : (double) $shipping_cost;
if ($tax_calculator instanceof TaxCalculator) {
$order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($order_slip->{'total_shipping_tax_' . $inc_or_ex_1}), _PS_PRICE_COMPUTE_PRECISION_);
} else {
$order_slip->{'total_shipping_tax_' . $inc_or_ex_2} = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
}
} else {
$order_slip->shipping_cost = false;
}
$order_slip->amount = 0;
$order_slip->{'total_products_tax_' . $inc_or_ex_1} = 0;
$order_slip->{'total_products_tax_' . $inc_or_ex_2} = 0;
foreach ($product_list as &$product) {
$order_detail = new OrderDetail((int) $product['id_order_detail']);
$price = (double) $product['unit_price'];
$quantity = (int) $product['quantity'];
$order_slip_resume = OrderSlip::getProductSlipResume((int) $order_detail->id);
if ($quantity + $order_slip_resume['product_quantity'] > $order_detail->product_quantity) {
$quantity = $order_detail->product_quantity - $order_slip_resume['product_quantity'];
}
if ($quantity == 0) {
continue;
}
$order_detail->product_quantity_refunded += $quantity;
$order_detail->save();
$address = Address::initialize($order->id_address_invoice, false);
$id_tax_rules_group = Product::getIdTaxRulesGroupByIdProduct((int) $order_detail->product_id);
$tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
$order_slip->{'total_products_tax_' . $inc_or_ex_1} += $price * $quantity;
if (in_array(Configuration::get('PS_ROUND_TYPE'), array(Order::ROUND_ITEM, Order::ROUND_LINE))) {
if (!isset($total_products[$id_tax_rules_group])) {
$total_products[$id_tax_rules_group] = 0;
} else {
if (!isset($total_products[$id_tax_rules_group . '_' . $id_address])) {
$total_products[$id_tax_rules_group . '_' . $id_address] = 0;
}
}
}
$product_tax_incl_line = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price) * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
switch (Configuration::get('PS_ROUND_TYPE')) {
case Order::ROUND_ITEM:
$product_tax_incl = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_) * $quantity;
$total_products[$id_tax_rules_group] += $product_tax_incl;
break;
case Order::ROUND_LINE:
$product_tax_incl = $product_tax_incl_line;
$total_products[$id_tax_rules_group] += $product_tax_incl;
break;
case Order::ROUND_TOTAL:
$product_tax_incl = $product_tax_incl_line;
$total_products[$id_tax_rules_group . '_' . $id_address] += $price * $quantity;
break;
}
$product['unit_price_tax_' . $inc_or_ex_1] = $price;
$product['unit_price_tax_' . $inc_or_ex_2] = Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
$product['total_price_tax_' . $inc_or_ex_1] = Tools::ps_round($price * $quantity, _PS_PRICE_COMPUTE_PRECISION_);
$product['total_price_tax_' . $inc_or_ex_2] = Tools::ps_round($product_tax_incl, _PS_PRICE_COMPUTE_PRECISION_);
$product['product_id'] = $order_detail->product_id;
}
unset($product);
foreach ($total_products as $key => $price) {
if (Configuration::get('PS_ROUND_TYPE') == Order::ROUND_TOTAL) {
$tmp = explode('_', $key);
$address = Address::initialize((int) $tmp[1], true);
$tax_calculator = TaxManagerFactory::getManager($address, $tmp[0])->getTaxCalculator();
$order_slip->{'total_products_tax_' . $inc_or_ex_2} += Tools::ps_round($tax_calculator->{$add_or_remove . 'Taxes'}($price), _PS_PRICE_COMPUTE_PRECISION_);
} else {
$order_slip->{'total_products_tax_' . $inc_or_ex_2} += $price;
}
}
$order_slip->{'total_products_tax_' . $inc_or_ex_2} -= (double) $amount && !$amount_choosen ? (double) $amount : 0;
$order_slip->amount = $amount_choosen ? (double) $amount : $order_slip->{'total_products_tax_' . $inc_or_ex_1};
$order_slip->shipping_cost_amount = $order_slip->{'total_shipping_tax_' . $inc_or_ex_1};
if ((double) $amount && !$amount_choosen) {
$order_slip->order_slip_type = 1;
}
//.........这里部分代码省略.........
示例13: 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;
}
示例14: 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])) {
//.........这里部分代码省略.........