本文整理汇总了PHP中TaxManagerFactory类的典型用法代码示例。如果您正苦于以下问题:PHP TaxManagerFactory类的具体用法?PHP TaxManagerFactory怎么用?PHP TaxManagerFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaxManagerFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: updateTaxAmount
public function updateTaxAmount($order, $tax_calculator = false)
{
$this->setContext((int) $this->id_shop);
$address = new Address((int) $order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$tax_manager = TaxManagerFactory::getManager($address, (int) Product::getIdTaxRulesGroupByIdProduct((int) $this->product_id, $this->context));
$this->tax_calculator = $tax_manager->getTaxCalculator();
return $tax_calculator ? $this->tax_calculator : $this->saveTaxCalculator($order, true);
}
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:8,代码来源:OrderDetail.php
示例2: getManager
/**
* Returns a tax manager able to handle this address
*
* @param Address $address
* @param string $type
*
* @return TaxManager
*/
public static function getManager(Address $address, $type)
{
$cache_id = TaxManagerFactory::getCacheKey($address) . '-' . $type;
if (!isset(TaxManagerFactory::$cache_tax_manager[$cache_id])) {
$tax_manager = TaxManagerFactory::execHookTaxManagerFactory($address, $type);
if (!$tax_manager instanceof TaxManagerInterface) {
$tax_manager = new TaxRulesTaxManager($address, $type);
}
TaxManagerFactory::$cache_tax_manager[$cache_id] = $tax_manager;
}
return TaxManagerFactory::$cache_tax_manager[$cache_id];
}
开发者ID:IngenioContenidoDigital,项目名称:americana,代码行数:20,代码来源:TaxManagerFactory.php
示例3: 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])) {
//.........这里部分代码省略.........
开发者ID:Oldwo1f,项目名称:yakaboutique,代码行数:101,代码来源:Cart.php
示例4: getTaxDetails
public function getTaxDetails($products = false)
{
if (!is_array($products) || !count($products)) {
$products = $this->getProducts();
}
$context = Context::getContext();
if (Configuration::get('PS_TAX_ADDRESS_TYPE') == 'id_address_invoice') {
$address = Address::initialize((int) $this->id_address_invoice);
} else {
$address = Address::initialize((int) $this->id_address_delivery);
}
if (!count($products)) {
return false;
}
$prepared_taxes = array();
$total_products_price = 0;
foreach ($products as $product) {
$id_tax_rules = (int) Product::getIdTaxRulesGroupByIdProduct((int) $product['id_product'], $context);
$tax_manager = TaxManagerFactory::getManager($address, $id_tax_rules);
$tax_calculator = $tax_manager->getTaxCalculator();
$product_taxes = $tax_calculator->getTaxData($product['price']);
$total_products_price += (double) $product['total_wt'];
foreach ($product_taxes as $tax_id => $tax_data) {
if (!array_key_exists($tax_id, $prepared_taxes)) {
$prepared_taxes[$tax_id] = $tax_data + array('total' => (double) $product['total_wt'] - (double) $product['total'], 'total_net' => (double) $product['total'], 'total_vat' => (double) $product['total_wt'], 'percentage' => 0);
} else {
$prepared_taxes[$tax_id]['total'] += (double) $product['total_wt'] - (double) $product['total'];
$prepared_taxes[$tax_id]['total_net'] += (double) $product['total'];
$prepared_taxes[$tax_id]['total_vat'] += (double) $product['total_wt'];
}
}
}
foreach ($prepared_taxes as &$tax) {
if ($total_products_price > 0 && $tax['total_vat'] > 0) {
$tax['percentage'] = 100 / ($total_products_price / $tax['total_vat']);
}
}
return count($prepared_taxes) ? $prepared_taxes : false;
}
开发者ID:juanchog,项目名称:modules-1.6.0.12,代码行数:39,代码来源:Cart.php
示例5: 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;
if ($id_address === null) {
$id_address = (int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
}
if ($address === null) {
$address = Address::initialize($id_address);
}
$wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
if ($with_taxes && $wrapping_fees > 0) {
$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;
}
开发者ID:dev-lav,项目名称:htdocs,代码行数:22,代码来源:Cart.php
示例6: getGiftWrappingPrice
/**
* Get the gift wrapping price
* @param bool $with_taxes With or without taxes
* @return float wrapping price
*/
public function getGiftWrappingPrice($with_taxes = true, $id_address = null)
{
static $address = array();
$wrapping_fees = (double) Configuration::get('PS_GIFT_WRAPPING_PRICE');
if ($wrapping_fees <= 0) {
return $wrapping_fees;
}
if ($with_taxes) {
if (Configuration::get('PS_ATCP_SHIPWRAP')) {
// With PS_ATCP_SHIPWRAP, wrapping fee is by default tax included
// so nothing to do here.
} else {
if (!isset($address[$this->id])) {
if ($id_address === null) {
$id_address = (int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
}
try {
$address[$this->id] = Address::initialize($id_address);
} catch (Exception $e) {
$address[$this->id] = new Address();
$address[$this->id]->id_country = Configuration::get('PS_COUNTRY_DEFAULT');
}
}
$tax_manager = TaxManagerFactory::getManager($address[$this->id], (int) Configuration::get('PS_GIFT_WRAPPING_TAX_RULES_GROUP'));
$tax_calculator = $tax_manager->getTaxCalculator();
$wrapping_fees = $tax_calculator->addTaxes($wrapping_fees);
}
} elseif (Configuration::get('PS_ATCP_SHIPWRAP')) {
// With PS_ATCP_SHIPWRAP, wrapping fee is by default tax included, so we convert it
// when asked for the pre tax price.
$wrapping_fees = Tools::ps_round($wrapping_fees / (1 + $this->getAverageProductsTaxRate()), _PS_PRICE_COMPUTE_PRECISION_);
}
return $wrapping_fees;
}
开发者ID:satanicman,项目名称:Pizzushi.loc,代码行数:39,代码来源:Cart.php
示例7: productImportOne
protected function productImportOne($info, $default_language_id, $id_lang, $force_ids, $regenerate, $shop_is_feature_active, $shop_ids, $match_ref, &$accessories, $validateOnly = false)
{
if ($force_ids && isset($info['id']) && (int) $info['id']) {
$product = new Product((int) $info['id']);
} elseif ($match_ref && array_key_exists('reference', $info)) {
$datas = Db::getInstance()->getRow('
SELECT p.`id_product`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
WHERE p.`reference` = "' . pSQL($info['reference']) . '"
', false);
if (isset($datas['id_product']) && $datas['id_product']) {
$product = new Product((int) $datas['id_product']);
} else {
$product = new Product();
}
} elseif (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
$product = new Product((int) $info['id']);
} else {
$product = new Product();
}
$update_advanced_stock_management_value = false;
if (isset($product->id) && $product->id && Product::existsInDatabase((int) $product->id, 'product')) {
$product->loadStockData();
$update_advanced_stock_management_value = true;
$category_data = Product::getProductCategories((int) $product->id);
if (is_array($category_data)) {
foreach ($category_data as $tmp) {
if (!isset($product->category) || !$product->category || is_array($product->category)) {
$product->category[] = $tmp;
}
}
}
}
AdminImportController::setEntityDefaultValues($product);
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
if (!$shop_is_feature_active) {
$product->shop = (int) Configuration::get('PS_SHOP_DEFAULT');
} elseif (!isset($product->shop) || empty($product->shop)) {
$product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
if (!$shop_is_feature_active) {
$product->id_shop_default = (int) Configuration::get('PS_SHOP_DEFAULT');
} else {
$product->id_shop_default = (int) Context::getContext()->shop->id;
}
// link product to shops
$product->id_shop_list = array();
foreach (explode($this->multiple_value_separator, $product->shop) as $shop) {
if (!empty($shop) && !is_numeric($shop)) {
$product->id_shop_list[] = Shop::getIdByName($shop);
} elseif (!empty($shop)) {
$product->id_shop_list[] = $shop;
}
}
if ((int) $product->id_tax_rules_group != 0) {
if (Validate::isLoadedObject(new TaxRulesGroup($product->id_tax_rules_group))) {
$address = $this->context->shop->getAddress();
$tax_manager = TaxManagerFactory::getManager($address, $product->id_tax_rules_group);
$product_tax_calculator = $tax_manager->getTaxCalculator();
$product->tax_rate = $product_tax_calculator->getTotalRate();
} else {
$this->addProductWarning('id_tax_rules_group', $product->id_tax_rules_group, $this->trans('Unknown tax rule group ID. You need to create a group with this ID first.', array(), 'Admin.Parameters.Notification'));
}
}
if (isset($product->manufacturer) && is_numeric($product->manufacturer) && Manufacturer::manufacturerExists((int) $product->manufacturer)) {
$product->id_manufacturer = (int) $product->manufacturer;
} elseif (isset($product->manufacturer) && is_string($product->manufacturer) && !empty($product->manufacturer)) {
if ($manufacturer = Manufacturer::getIdByName($product->manufacturer)) {
$product->id_manufacturer = (int) $manufacturer;
} else {
$manufacturer = new Manufacturer();
$manufacturer->name = $product->manufacturer;
$manufacturer->active = true;
if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $manufacturer->add()) {
$product->id_manufacturer = (int) $manufacturer->id;
$manufacturer->associateTo($product->id_shop_list);
} else {
if (!$validateOnly) {
$this->errors[] = sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
}
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($product->supplier) && is_numeric($product->supplier) && Supplier::supplierExists((int) $product->supplier)) {
$product->id_supplier = (int) $product->supplier;
} elseif (isset($product->supplier) && is_string($product->supplier) && !empty($product->supplier)) {
if ($supplier = Supplier::getIdByName($product->supplier)) {
$product->id_supplier = (int) $supplier;
} else {
$supplier = new Supplier();
$supplier->name = $product->supplier;
$supplier->active = true;
if (($field_error = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $supplier->add()) {
$product->id_supplier = (int) $supplier->id;
$supplier->associateTo($product->id_shop_list);
} else {
//.........这里部分代码省略.........
开发者ID:M03G,项目名称:PrestaShop,代码行数:101,代码来源:AdminImportController.php
示例8: initFormPrices
/**
* @param Product $obj
* @throws Exception
* @throws SmartyException
*/
public function initFormPrices($obj)
{
$data = $this->createTemplate($this->tpl_form);
$product = $obj;
if ($obj->id) {
$shops = Shop::getShops();
$countries = Country::getCountries($this->context->language->id);
$groups = Group::getGroups($this->context->language->id);
$currencies = Currency::getCurrencies();
$attributes = $obj->getAttributesGroups((int) $this->context->language->id);
$combinations = array();
foreach ($attributes as $attribute) {
$combinations[$attribute['id_product_attribute']]['id_product_attribute'] = $attribute['id_product_attribute'];
if (!isset($combinations[$attribute['id_product_attribute']]['attributes'])) {
$combinations[$attribute['id_product_attribute']]['attributes'] = '';
}
$combinations[$attribute['id_product_attribute']]['attributes'] .= $attribute['attribute_name'] . ' - ';
$combinations[$attribute['id_product_attribute']]['price'] = Tools::displayPrice(Tools::convertPrice(Product::getPriceStatic((int) $obj->id, false, $attribute['id_product_attribute']), $this->context->currency), $this->context->currency);
}
foreach ($combinations as &$combination) {
$combination['attributes'] = rtrim($combination['attributes'], ' - ');
}
$data->assign('specificPriceModificationForm', $this->_displaySpecificPriceModificationForm($this->context->currency, $shops, $currencies, $countries, $groups));
$data->assign('ecotax_tax_excl', (int) $obj->ecotax);
$this->_applyTaxToEcotax($obj);
$data->assign(array('shops' => $shops, 'admin_one_shop' => count($this->context->employee->getAssociatedShops()) == 1, 'currencies' => $currencies, 'countries' => $countries, 'groups' => $groups, 'combinations' => $combinations, 'multi_shop' => Shop::isFeatureActive(), 'link' => new Link(), 'pack' => new Pack()));
} else {
$this->displayWarning($this->l('You must save this product before adding specific pricing'));
$product->id_tax_rules_group = (int) Product::getIdTaxRulesGroupMostUsed();
$data->assign('ecotax_tax_excl', 0);
}
$address = new Address();
$address->id_country = (int) $this->context->country->id;
$tax_rules_groups = TaxRulesGroup::getTaxRulesGroups(true);
$tax_rates = array(0 => array('id_tax_rules_group' => 0, 'rates' => array(0), 'computation_method' => 0));
foreach ($tax_rules_groups as $tax_rules_group) {
$id_tax_rules_group = (int) $tax_rules_group['id_tax_rules_group'];
$tax_calculator = TaxManagerFactory::getManager($address, $id_tax_rules_group)->getTaxCalculator();
$tax_rates[$id_tax_rules_group] = array('id_tax_rules_group' => $id_tax_rules_group, 'rates' => array(), 'computation_method' => (int) $tax_calculator->computation_method);
if (isset($tax_calculator->taxes) && count($tax_calculator->taxes)) {
foreach ($tax_calculator->taxes as $tax) {
$tax_rates[$id_tax_rules_group]['rates'][] = (double) $tax->rate;
}
} else {
$tax_rates[$id_tax_rules_group]['rates'][] = 0;
}
}
// prices part
$data->assign(array('link' => $this->context->link, 'currency' => $currency = $this->context->currency, 'tax_rules_groups' => $tax_rules_groups, 'taxesRatesByGroup' => $tax_rates, 'ecotaxTaxRate' => Tax::getProductEcotaxRate(), 'tax_exclude_taxe_option' => Tax::excludeTaxeOption(), 'ps_use_ecotax' => Configuration::get('PS_USE_ECOTAX')));
$product->price = Tools::convertPrice($product->price, $this->context->currency, true, $this->context);
if ($product->unit_price_ratio != 0) {
$data->assign('unit_price', Tools::ps_round($product->price / $product->unit_price_ratio, 6));
} else {
$data->assign('unit_price', 0);
}
$data->assign('ps_tax', Configuration::get('PS_TAX'));
$data->assign('country_display_tax_label', $this->context->country->display_tax_label);
$data->assign(array('currency', $this->context->currency, 'product' => $product, 'token' => $this->token));
$this->tpl_form_vars['custom_form'] = $data->fetch();
}
开发者ID:Rohit-jn,项目名称:hotelcommerce,代码行数:65,代码来源:AdminProductsController.php
示例9: setInvoice
/**
* This method allows to generate first invoice of the current order
*/
public function setInvoice($use_existing_payment = false)
{
if (!$this->hasInvoice()) {
if ($id = (int) $this->hasDelivery()) {
$order_invoice = new OrderInvoice($id);
} else {
$order_invoice = new OrderInvoice();
}
$order_invoice->id_order = $this->id;
if (!$id) {
$order_invoice->number = 0;
}
$address = new Address((int) $this->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$carrier = new Carrier((int) $this->id_carrier);
$tax_calculator = $carrier->getTaxCalculator($address, $this->id, Configuration::get('PS_ATCP_SHIPWRAP'));
$order_invoice->total_discount_tax_excl = $this->total_discounts_tax_excl;
$order_invoice->total_discount_tax_incl = $this->total_discounts_tax_incl;
$order_invoice->total_paid_tax_excl = $this->total_paid_tax_excl;
$order_invoice->total_paid_tax_incl = $this->total_paid_tax_incl;
$order_invoice->total_products = $this->total_products;
$order_invoice->total_products_wt = $this->total_products_wt;
$order_invoice->total_shipping_tax_excl = $this->total_shipping_tax_excl;
$order_invoice->total_shipping_tax_incl = $this->total_shipping_tax_incl;
$order_invoice->shipping_tax_computation_method = $tax_calculator->computation_method;
$order_invoice->total_wrapping_tax_excl = $this->total_wrapping_tax_excl;
$order_invoice->total_wrapping_tax_incl = $this->total_wrapping_tax_incl;
// Save Order invoice
$order_invoice->save();
if (Configuration::get('PS_INVOICE')) {
$this->setLastInvoiceNumber($order_invoice->id, $this->id_shop);
}
if (Configuration::get('PS_ATCP_SHIPWRAP')) {
$wrapping_tax_calculator = Adapter_ServiceLocator::get('AverageTaxOfProductsTaxCalculator')->setIdOrder($this->id);
} else {
$wrapping_tax_manager = TaxManagerFactory::getManager($address, (int) Configuration::get('PS_GIFT_WRAPPING_TAX_RULES_GROUP'));
$wrapping_tax_calculator = $wrapping_tax_manager->getTaxCalculator();
}
$order_invoice->saveCarrierTaxCalculator($tax_calculator->getTaxesAmount($order_invoice->total_shipping_tax_excl, $order_invoice->total_shipping_tax_incl, _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode));
$order_invoice->saveWrappingTaxCalculator($wrapping_tax_calculator->getTaxesAmount($order_invoice->total_wrapping_tax_excl, $order_invoice->total_wrapping_tax_incl, _PS_PRICE_COMPUTE_PRECISION_, $this->round_mode));
// Update order_carrier
$id_order_carrier = Db::getInstance()->getValue('
SELECT `id_order_carrier`
FROM `' . _DB_PREFIX_ . 'order_carrier`
WHERE `id_order` = ' . (int) $order_invoice->id_order . '
AND (`id_order_invoice` IS NULL OR `id_order_invoice` = 0)');
if ($id_order_carrier) {
$order_carrier = new OrderCarrier($id_order_carrier);
$order_carrier->id_order_invoice = (int) $order_invoice->id;
$order_carrier->update();
}
// Update order detail
Db::getInstance()->execute('
UPDATE `' . _DB_PREFIX_ . 'order_detail`
SET `id_order_invoice` = ' . (int) $order_invoice->id . '
WHERE `id_order` = ' . (int) $order_invoice->id_order);
// Update order payment
if ($use_existing_payment) {
$id_order_payments = Db::getInstance()->executeS('
SELECT DISTINCT op.id_order_payment
FROM `' . _DB_PREFIX_ . 'order_payment` op
INNER JOIN `' . _DB_PREFIX_ . 'orders` o ON (o.reference = op.order_reference)
LEFT JOIN `' . _DB_PREFIX_ . 'order_invoice_payment` oip ON (oip.id_order_payment = op.id_order_payment)
WHERE (oip.id_order != ' . (int) $order_invoice->id_order . ' OR oip.id_order IS NULL) AND o.id_order = ' . (int) $order_invoice->id_order);
if (count($id_order_payments)) {
foreach ($id_order_payments as $order_payment) {
Db::getInstance()->execute('
INSERT INTO `' . _DB_PREFIX_ . 'order_invoice_payment`
SET
`id_order_invoice` = ' . (int) $order_invoice->id . ',
`id_order_payment` = ' . (int) $order_payment['id_order_payment'] . ',
`id_order` = ' . (int) $order_invoice->id_order);
}
// Clear cache
Cache::clean('order_invoice_paid_*');
}
}
// Update order cart rule
Db::getInstance()->execute('
UPDATE `' . _DB_PREFIX_ . 'order_cart_rule`
SET `id_order_invoice` = ' . (int) $order_invoice->id . '
WHERE `id_order` = ' . (int) $order_invoice->id_order);
// Keep it for backward compatibility, to remove on 1.6 version
$this->invoice_date = $order_invoice->date_add;
if (Configuration::get('PS_INVOICE')) {
$this->invoice_number = $this->getInvoiceNumber($order_invoice->id);
$invoice_number = Hook::exec('actionSetInvoice', array(get_class($this) => $this, get_class($order_invoice) => $order_invoice, 'use_existing_payment' => (bool) $use_existing_payment));
if (is_numeric($invoice_number)) {
$this->invoice_number = (int) $invoice_number;
} else {
$this->invoice_number = $this->getInvoiceNumber($order_invoice->id);
}
}
$this->update();
}
}
开发者ID:nmardones,项目名称:PrestaShop,代码行数:98,代码来源:Order.php
示例10: getProducts
//.........这里部分代码省略.........
}
}
// 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'
);
Cache::store($cache_id, $row2);
开发者ID:ecSta,项目名称:prestanight,代码行数:67,代码来源:Cart.php
示例11: 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;
}
//.........这里部分代码省略.........
开发者ID:ankkal,项目名称:SPN_project,代码行数:101,代码来源:OrderSlip.php
示例12: getOrderTotal
//.........这里部分代码省略.........
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) {
// products refer to the cart details
if ($virtual_context->shop->id != $product['id_shop']) {
$virtual_context->shop = new Shop((int) $product['id_shop']);
}
if ($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_factory->addressExists($id_address)) {
$id_address = null;
}
// The $null variable below is not used,
// but it is necessary to pass it to getProductPrice because
// it expects a reference.
$null = null;
$price = Product::getPriceStatic((int) $product['id_product'], $with_taxes, !empty($product['delivery_date']) ? 0 : (int) $product['id_product_attribute'], 6, null, false, true, $product['cart_quantity'], false, (int) $this->id_customer ? (int) $this->id_customer : null, (int) $this->id, $id_address, $null, $ps_use_ecotax, true, $virtual_context, NULL, $product['delivery_date'], $product['delivery_time_from'], $product['delivery_time_to']);
$address = $address_factory->findOrCreate($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();
} else {
$id_tax_rules_group = 0;
}
if (in_array($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;
}
} elseif (!isset($products_total[$id_tax_rules_group . '_' . $id_address])) {
$products_total[$id_tax_rules_group . '_' . $id_address] = 0;
}
switch ($ps_round_type) {
case Order::ROUND_TOTAL:
$products_total[$id_tax_rules_group . '_' . $id_address] += $price * (int) $product['cart_quantity'];
break;
case Order::ROUND_LINE:
$product_price = $price * $product['cart_quantity'];
$products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision);
break;
case Order::ROUND_ITEM:
default:
$product_price = $price;
$products_total[$id_tax_rules_group] += Tools::ps_round($product_price, $compute_precision) * (int) $product['cart_quantity'];
break;
}
}
foreach ($products_total as $key => $price) {
$order_total += $price;
}
$order_total_products = $order_total;
if ($type == Cart::ONLY_DISCOUNTS) {
$order_total = 0;
}
开发者ID:paolobattistella,项目名称:aphro,代码行数:67,代码来源:Cart.php
示例13: productImport
public function productImport()
{
$this->receiveTab();
$handle = $this->openCsvFile();
$default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
$id_lang = Language::getIdByIso(Tools::getValue('iso_lang'));
if (!Validate::isUnsignedId($id_lang)) {
$id_lang = $default_language_id;
}
AdminImportController::setLocale();
$shop_ids = Shop::getCompleteListOfShopsID();
for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
if (Tools::getValue('convert')) {
$line = $this->utf8EncodeArray($line);
}
$info = AdminImportController::getMaskedRow($line);
if (self::ignoreRow($info)) {
continue;
}
if (Tools::getValue('forceIDs') && isset($info['id']) && (int) $info['id']) {
$product = new Product((int) $info['id']);
} elseif (Tools::getValue('match_ref') && array_key_exists('reference', $info)) {
$datas = Db::getInstance()->getRow('
SELECT p.`id_product`
FROM `' . _DB_PREFIX_ . 'product` p
' . Shop::addSqlAssociation('product', 'p') . '
WHERE p.`reference` = "' . pSQL($info['reference']) . '"
');
if (isset($datas['id_product']) && $datas['id_product']) {
$product = new Product((int) $datas['id_product']);
} else {
$product = new Product();
}
} else {
if (array_key_exists('id', $info) && is_string($info['id'])) {
$prod = self::findProductByName($default_language_id, $info['id'], $info['name']);
if ($prod['id_product']) {
$info['id'] = (int) $prod['id_product'];
}
}
if (array_key_exists('id', $info) && (int) $info['id'] && Product::existsInDatabase((int) $info['id'], 'product')) {
$product = new Product((int) $info['id']);
$product->loadStockData();
$category_data = Product::getProductCategories((int) $product->id);
if (is_array($category_data)) {
foreach ($category_data as $tmp) {
if (!isset($product->category) || !$product->category || is_array($product->category)) {
$product->category[] = $tmp;
}
}
}
} else {
$product = new Product();
}
}
AdminImportController::setEntityDefaultValues($product);
AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $product);
if (!Shop::isFeatureActive()) {
$product->shop = 1;
} elseif (!isset($product->shop) || empty($product->shop)) {
$product->shop = implode($this->multiple_value_separator, Shop::getContextListShopID());
}
if (!Shop::isFeatureActive()) {
$product->id_shop_default = 1;
} else {
$product->id_shop_default = (int) Context::getContext()->shop->id;
}
$product->id_shop_list = array();
foreach (explod
|
请发表评论