// Revert 10430

This commit is contained in:
mDeflotte
2011-11-22 15:25:47 +00:00
parent 84dfb3b643
commit 9fd1dc0c2f
+4 -131
View File
@@ -255,103 +255,11 @@ abstract class PaymentModuleCore extends Module
// Construct order detail table for the email // Construct order detail table for the email
$productsList = ''; $productsList = '';
$products = $cart->getProducts(); $products = $cart->getProducts();
$storeAllTaxes = array();
foreach ($products AS $key => $product) foreach ($products AS $key => $product)
{ {
$price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $price = Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 6, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
$price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')})); $price_wt = Product::getPriceStatic((int)($product['id_product']), true, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), 2, NULL, false, true, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}));
/* Store tax info */
$id_country = (int)$context->country->id;
$id_state = 0;
$id_county = 0;
$rate = 0;
$id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
$address_infos = Address::getCountryAndState($id_address);
if ($address_infos['id_country'])
{
$id_country = (int)($address_infos['id_country']);
$id_state = (int)$address_infos['id_state'];
$id_county = (int)County::getIdCountyByZipCode($address_infos['id_state'], $address_infos['postcode']);
}
$allTaxes = TaxRulesGroup::getTaxes((int)Product::getIdTaxRulesGroupByIdProduct((int)$product['id_product']), $id_country, $id_state, $id_county);
$nTax = 0;
foreach ($allTaxes AS $res)
{
if (!isset($storeAllTaxes[$res->id]))
$storeAllTaxes[$res->id] = array();
$storeAllTaxes[$res->id]['name'] = $res->name[(int)$order->id_lang];
$storeAllTaxes[$res->id]['rate'] = $res->rate;
if (!$nTax++)
$storeAllTaxes[$res->id]['amount'] = ($price * (1 + ($res->rate * 0.01))) - $price;
else
{
$priceTmp = $price_wt / (1 + ($res->rate * 0.01));
$storeAllTaxes[$res->id]['amount'] = $price_wt - $priceTmp;
}
}
/* End */
// Add some informations for virtual products
$deadline = '0000-00-00 00:00:00';
$download_hash = NULL;
if ($id_product_download = ProductDownload::getIdFromIdProduct((int)($product['id_product'])))
{
$productDownload = new ProductDownload((int)($id_product_download));
$deadline = $productDownload->getDeadLine();
$download_hash = $productDownload->getHash();
}
// Exclude VAT
if (Tax::excludeTaxeOption())
{
$product['tax'] = 0;
$product['rate'] = 0;
$tax_rate = 0;
}
else
$tax_rate = Tax::getProductTaxRate((int)($product['id_product']), $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$ecotaxTaxRate = 0;
if (!empty($product['ecotax']))
$ecotaxTaxRate = Tax::getProductEcotaxRate($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$product_price = (float)Product::getPriceStatic((int)($product['id_product']), false, ($product['id_product_attribute'] ? (int)($product['id_product_attribute']) : NULL), (Product::getTaxCalculationMethod((int)($order->id_customer)) == PS_TAX_EXC ? 2 : 6), NULL, false, false, $product['cart_quantity'], false, (int)($order->id_customer), (int)($order->id_cart), (int)($order->{Configuration::get('PS_TAX_ADDRESS_TYPE')}), $specificPrice, false, false);
$group_reduction = (float)GroupReduction::getValueForProduct((int)$product['id_product'], $customer->id_default_group) * 100;
if (!$group_reduction)
$group_reduction = Group::getReduction((int)$order->id_customer);
$quantityDiscount = SpecificPrice::getQuantityDiscount((int)$product['id_product'], Shop::getCurrentShop(), (int)$cart->id_currency, (int)$vat_address->id_country, (int)$customer->id_default_group, (int)$product['cart_quantity']);
$unitPrice = Product::getPriceStatic((int)$product['id_product'], true, ($product['id_product_attribute'] ? intval($product['id_product_attribute']) : NULL), 2, NULL, false, true, 1, false, (int)$order->id_customer, NULL, (int)$order->{Configuration::get('PS_TAX_ADDRESS_TYPE')});
$quantityDiscountValue = $quantityDiscount ? ((Product::getTaxCalculationMethod((int)$order->id_customer) == PS_TAX_EXC ? Tools::ps_round($unitPrice, 2) : $unitPrice) - $quantityDiscount['price'] * (1 + $tax_rate / 100)) : 0.00;
$query .= '('.(int)($order->id).',
'.(int)($product['id_product']).',
'.(isset($product['id_product_attribute']) ? (int)($product['id_product_attribute']) : 'NULL').',
\''.pSQL($product['name'].((isset($product['attributes']) AND $product['attributes'] != NULL) ? ' - '.$product['attributes'] : '')).'\',
'.(int)($product['cart_quantity']).',
'.$quantityInStock.',
'.$product_price.',
'.(float)(($specificPrice AND $specificPrice['reduction_type'] == 'percentage') ? $specificPrice['reduction'] * 100 : 0.00).',
'.(float)(($specificPrice AND $specificPrice['reduction_type'] == 'amount') ? (!$specificPrice['id_currency'] ? Tools::convertPrice($specificPrice['reduction'], $order->id_currency) : $specificPrice['reduction']) : 0.00).',
'.$group_reduction.',
'.$quantityDiscountValue.',
'.(empty($product['ean13']) ? 'NULL' : '\''.pSQL($product['ean13']).'\'').',
'.(empty($product['upc']) ? 'NULL' : '\''.pSQL($product['upc']).'\'').',
'.(empty($product['reference']) ? 'NULL' : '\''.pSQL($product['reference']).'\'').',
'.(empty($product['supplier_reference']) ? 'NULL' : '\''.pSQL($product['supplier_reference']).'\'').',
'.(float)($product['id_product_attribute'] ? $product['weight_attribute'] : $product['weight']).',
\''.(empty($tax_rate) ? '' : pSQL($product['tax'])).'\',
'.(float)($tax_rate).',
'.(float)Tools::convertPrice(floatval($product['ecotax']), intval($order->id_currency)).',
'.(float)$ecotaxTaxRate.',
'.(($specificPrice AND $specificPrice['from_quantity'] > 1) ? 1 : 0).',
\''.pSQL($deadline).'\',
\''.pSQL($download_hash).'\'),';
$customizationQuantity = 0; $customizationQuantity = 0;
if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']])) if (isset($customizedDatas[$product['id_product']][$product['id_product_attribute']]))
{ {
@@ -392,45 +300,10 @@ abstract class PaymentModuleCore extends Module
</tr>'; </tr>';
} // end foreach ($products) } // end foreach ($products)
$cartRulesList = '';
/* Add carrier tax */ $result = $cart->getCartRules();
$shippingCostTaxExcl = $cart->getOrderShippingCost((int)$order->id_carrier, false); $cartRules = ObjectModel::hydrateCollection('CartRule', $result, (int)$order->id_lang);
$allTaxes = TaxRulesGroup::getTaxes((int)Carrier::getIdTaxRulesGroupByIdCarrier((int)$order->id_carrier), $id_country, $id_state, $id_county); foreach ($cartRules as $cartRule)
$nTax = 0;
foreach ($allTaxes AS $res)
{
if (!isset($res->id))
continue;
if (!isset($storeAllTaxes[$res->id]))
$storeAllTaxes[$res->id] = array();
if (!isset($storeAllTaxes[$res->id]['amount']))
$storeAllTaxes[$res->id]['amount'] = 0;
$storeAllTaxes[$res->id]['name'] = $res->name[(int)$order->id_lang];
$storeAllTaxes[$res->id]['rate'] = $res->rate;
if (!$nTax++)
$storeAllTaxes[$res->id]['amount'] += ($shippingCostTaxExcl * (1 + ($res->rate * 0.01))) - $shippingCostTaxExcl;
else
{
$priceTmp = $order->total_shipping / (1 + ($res->rate * 0.01));
$storeAllTaxes[$res->id]['amount'] += $order->total_shipping - $priceTmp;
}
}
/* Store taxes */
foreach ($storeAllTaxes AS $t)
Db::getInstance()->Execute('
INSERT INTO '._DB_PREFIX_.'order_tax (id_order, tax_name, tax_rate, amount)
VALUES ('.(int)$order->id.', \''.pSQL($t['name']).'\', \''.(float)($t['rate']).'\', '.(float)$t['amount'].')');
// Insert discounts from cart into order_discount table
$discounts = $cart->getDiscounts();
$discountsList = '';
$total_discount_value = 0;
$shrunk = false;
foreach ($discounts AS $discount)
{ {
$value = $cartRule->getContextualValue(true); $value = $cartRule->getContextualValue(true);
// Todo : has not been tested because order processing wasn't functionnal // Todo : has not been tested because order processing wasn't functionnal