1.4 Toujours des problèmes sur les coupons de réduction et TVA (1 lecteur(s)) (1) Invité(s)
 | | |
|
SUJET: 1.4 Toujours des problèmes sur les coupons de réduction et TVA
|
|
|
1.4 Toujours des problèmes sur les coupons de réduction et TVA Il y a 1 Année, 11 Mois
|
Karma: 3
|
Bonjour,
grand regret pour moi aujourd'hui de voir que le système des remises est toujours bancal en 1.4, à moins que ce soit un problème de configuration...
Voici ma config de TVA :
Image réservée aux membres. Veuillez vous connecter ou vous enregistrer.
Le panier sans la réduc :
Image réservée aux membres. Veuillez vous connecter ou vous enregistrer.
Le panier avec la réduc :
Image réservée aux membres. Veuillez vous connecter ou vous enregistrer.
Il s'agit d'une remise de 3 euros sur le panier dont le montant est supérieur à 50 €.
Visiblement la condition s'applique toujours sur le montant HT. Dommage de ne pas pouvoir spécifier si c'est sur le HT ou TTC, c'est compliqué si on vend à plusieurs taux de TVA.
A 19,6% ça donne du 41,80 HT alors que ça donne 47,39 HT sur du 5,5%. Il faut donc faire un choix et pour être sûr que ça fonctionne à tous les coups, donc choisir le cas de la TVA à 19,6 (soit 41,80 HT), ce qui veut dire qu'un client n'achetant que des produits à 5,5% de TVA se verra appliquer la réduction dès 44,01 € TTC, pas top donc...
Enfin, et plus gênant, comme on le voit dans cette dernière capture, le prix TTC unitaire de mon produit passe de 15,90 € à 15,75 € alors que la règle de prix est censée s'appliquer sur le panier et non sur les produits...
Image réservée aux membres. Veuillez vous connecter ou vous enregistrer.
Avez-vous le même problème ?
Ou est-ce une erreur de configuration chez moi ?
|
|
|
|
Dernière édition: 12/03/10 à 17:42 Par chatlumo.
|
|
|
Re:1.4 Toujours des problèmes sur les remises Il y a 1 Année, 11 Mois
|
Karma: 3
|
|
Je reviens sur ce que j'ai dit.
Après d'autres tests il semble bien que la condition de remise sur le sous-total s'applique bien sur le sous-total des produits TTC...
Et le changement du prix de 15,90 à 15,75 € ne se produit que lorsque je fais l'estimation du port (et que celui-ci soit à 5 € ou à 0 €), bizarre...
A noter également que si j'ajoute d'autres lignes produits, le produit 1 a toujours le même bug mais pas les produits suivants... Si je supprime, c'est donc le produit de la ligne 2 (qui passe donc en ligne 1) qui est affecté par ce problème...
PS : J'utilise le module Owebia Shipping 2, je ne sais pas s'il y a un quelconque rapport avec ce bug, si ce n'est qu'il apparaît à l'estimation du port...
|
|
|
|
Dernière édition: 11/03/10 à 13:29 Par chatlumo.
|
|
|
Re:1.4 Toujours des problèmes sur les remises Il y a 1 Année, 10 Mois
|
Karma: 3
|
|
personne n'a constaté ce problème ?
|
|
|
|
|
|
|
Re:1.4 Toujours des problèmes sur les remises Il y a 1 Année, 10 Mois
|
Karma: 8
|
|
Nous avons trouvé une solution pour contrer ce soucis, en modifiant des éléments du core de Magento (nous n'avons pas averti la team Varien, car le bug est bien complexe à leur expliquer... donc si quelqu'un a le courage de leur expliquer, ça serait un bon avancement !).
Je me charge de te poster cela demain.
|
|
|
|
|
|
|
Re:1.4 Toujours des problèmes sur les remises Il y a 1 Année, 10 Mois
|
Karma: 3
|
|
N'étant pas super à l'aise en anglais, je préfère que quelqu'un d'autre s'y colle mais je suis preneur des explications et de la solution en français ;)
|
|
|
|
|
|
|
Re:1.4 Toujours des problèmes sur les remises Il y a 1 Année, 10 Mois
|
Karma: 0
|
|
Johan écrit:
Je me charge de te poster cela demain.
Je suis également intéressé.
Merci par avance!
De plus j'ai remarqué que dans l'admin, lors de la création d'un avoir, le taux de TVA calculé est faux.
J'espère comme vous que cela pourra être corrigé rapidement !
Antoine
|
|
|
|
|
|
|
Re:1.4 Toujours des problèmes sur les remises Il y a 1 Année, 10 Mois
|
Karma: 8
|
Bonjour,
Voici donc le correctif que nous avons apporté pour que ça soit fonctionnel : nous demandons vos retours pour être sûr que ça marche, et que ça ne provoque pas de plantages et / ou bugs.
/!\ PENSEZ À DUPLIQUER LES FICHIERS MODIFIÉS DANS LE RÉPERTOIRE LOCAL/
Étape 1 - - -
Mettre le code suivant dans le fichier Mage/Sales/Model/Order/Creditmemo/Total/Tax.php :
| Code : |
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Sales
* @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
class Mage_Sales_Model_Order_Creditmemo_Total_Tax extends Mage_Sales_Model_Order_Creditmemo_Total_Abstract
{
public function collect(Mage_Sales_Model_Order_Creditmemo $creditmemo)
{
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
$totalTax = 0;
$baseTotalTax = 0;
$order = $creditmemo->getOrder();
$ShippingTaxUnique = $order->shippingTaxAmount; // NIKED BY LUSODEV :)
foreach ($creditmemo->getAllItems() as $item) {
if ($item->getOrderItem()->isDummy()) {
continue;
}
$orderItemTax = $item->getOrderItem()->getTaxAmount();
$baseOrderItemTax = $item->getOrderItem()->getBaseTaxAmount();
$orderItemQty = $item->getOrderItem()->getQtyOrdered();
if ($orderItemTax && $orderItemQty) {
/**
* Check item tax amount
*/
if ($item->isLast()) {
$tax = $orderItemTax - $item->getOrderItem()->getTaxRefunded();
$baseTax = $baseOrderItemTax - $item->getOrderItem()->getTaxRefunded();
}
else {
$tax = $orderItemTax*$item->getQty()/$orderItemQty;
$baseTax = $baseOrderItemTax*$item->getQty()/$orderItemQty;
$tax = $creditmemo->getStore()->roundPrice($tax);
$baseTax = $creditmemo->getStore()->roundPrice($baseTax);
}
$item->setTaxAmount($tax);
$item->setBaseTaxAmount($baseTax);
$totalTax += $tax;
$baseTotalTax += $baseTax;
}
}
if ($invoice = $creditmemo->getInvoice()) {
$totalTax += $invoice->getShippingTaxAmount();
$baseTotalTax += $invoice->getBaseShippingTaxAmount();
$shippingTaxAmount = $invoice->getShippingTaxAmount();
$baseShippingTaxAmount = $invoice->getBaseShippingTaxAmount();
} else {
$orderShippingAmount = $order->getShippingAmount();
$baseOrderShippingAmount = $order->getBaseShippingAmount();
$baseOrderShippingRefundedAmount = $order->getBaseShippingRefunded();
$shippingTaxAmount = 0;
$baseShippingTaxAmount = 0;
if (($baseOrderShippingAmount - $baseOrderShippingRefundedAmount) > $creditmemo->getBaseShippingAmount()) {
$shippingTaxAmount = $creditmemo->getShippingAmount()*($order->getShippingTaxAmount()/$orderShippingAmount);
$baseShippingTaxAmount = $creditmemo->getBaseShippingAmount()*($order->getBaseShippingTaxAmount()/$baseOrderShippingAmount);
$shippingTaxAmount = $creditmemo->getStore()->roundPrice($shippingTaxAmount);
$baseShippingTaxAmount = $creditmemo->getStore()->roundPrice($baseShippingTaxAmount);
$allowedTax = $order->getTaxAmount() - $order->getTaxRefunded() - $ShippingTaxUnique; // NIKED BY LUSODEV :)
$allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxRefunded(); // NIKED BY LUSODEV :)
} elseif (($baseOrderShippingAmount - $baseOrderShippingRefundedAmount) == $creditmemo->getBaseShippingAmount()) {
$shippingTaxAmount = $order->getShippingTaxAmount() - $order->getShippingTaxRefunded();
$baseShippingTaxAmount = $order->getBaseShippingTaxAmount() - $order->getBaseShippingTaxRefunded();
$allowedTax = $order->getTaxAmount() - $order->getTaxRefunded(); // NIKED BY LUSODEV :)
$allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxRefunded(); // NIKED BY LUSODEV :)
}
$totalTax += $shippingTaxAmount;
$baseTotalTax += $baseShippingTaxAmount;
}
//$allowedTax = $order->getTaxAmount() - $order->getTaxRefunded(); // NIKED BY LUSODEV :)
//$allowedBaseTax = $order->getBaseTaxAmount() - $order->getBaseTaxRefunded(); // NIKED BY LUSODEV :)
$totalTax = min($allowedTax, $totalTax);
$baseTotalTax = min($allowedBaseTax, $baseTotalTax);
$creditmemo->setTaxAmount($totalTax);
$creditmemo->setBaseTaxAmount($baseTotalTax);
$creditmemo->setShippingTaxAmount($shippingTaxAmount);
$creditmemo->setBaseShippingTaxAmount($baseShippingTaxAmount);
$creditmemo->setGrandTotal($creditmemo->getGrandTotal() + $totalTax);
$creditmemo->setBaseGrandTotal($creditmemo->getBaseGrandTotal() + $baseTotalTax);
return $this;
}
}
|
Étape 2 - - -
Mettre le code suivant dans le fichier Mage/Tax/Model/Sales/Total/Quote/Tax.php :
| Code : |
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@magentocommerce.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Magento to newer
* versions in the future. If you wish to customize Magento for your
* needs please refer to http://www.magentocommerce.com for more information.
*
* @category Mage
* @package Mage_Tax
* @copyright Copyright (c) 2009 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/
/**
* Tax totals calculation model
*/
class Mage_Tax_Model_Sales_Total_Quote_Tax extends Mage_Sales_Model_Quote_Address_Total_Abstract
{
/**
* Tax module helper
*
* @var Mage_Tax_Helper_Data
*/
protected $_helper;
/**
* Tax calculation model
*
* @var Mage_Tax_Model_Calculation
*/
protected $_calculator;
/**
* Tax configuration object
*
* @var Mage_Tax_Model_Config
*/
protected $_config;
/**
* Flag which is initialized when collect method is start.
* Is used for checking if store tax and customer tax requests are similar
*
* @var bool
*/
protected $_areTaxRequestsSimilar = false;
protected $_roundingDeltas = array();
protected $_baseRoundingDeltas = array();
/**
* Class constructor
*/
public function __construct()
{
$this->setCode('tax');
$this->_helper = Mage::helper('tax');
$this->_calculator = Mage::getSingleton('tax/calculation');
$this->_config = Mage::getSingleton('tax/config');
}
/**
* Collect tax totals for quote address
*
* @param Mage_Sales_Model_Quote_Address $address
* @return Mage_Tax_Model_Sales_Total_Quote
*/
public function collect(Mage_Sales_Model_Quote_Address $address)
{
parent::collect($address);
$store = $address->getQuote()->getStore();
$customer = $address->getQuote()->getCustomer();
if ($customer) {
$this->_calculator->setCustomer($customer);
}
if (!$address->getAppliedTaxesReset()) {
$address->setAppliedTaxes(array());
}
$items = $address->getAllItems();
if (!count($items)) {
return $this;
}
$request = $this->_calculator->getRateRequest(
$address,
$address->getQuote()->getBillingAddress(),
$address->getQuote()->getCustomerTaxClassId(),
$store
);
$this->_areTaxRequestsSimilar = $this->_calculator->compareRequests(
$this->_calculator->getRateOriginRequest($address->getQuote()->getStore()),
$request
);
switch ($this->_config->getAlgorithm($store)) {
case Mage_Tax_Model_Calculation::CALC_UNIT_BASE:
$this->_unitBaseCalculation($address, $request);
break;
case Mage_Tax_Model_Calculation::CALC_ROW_BASE:
$this->_rowBaseCalculation($address, $request);
break;
case Mage_Tax_Model_Calculation::CALC_TOTAL_BASE:
$this->_totalBaseCalculation($address, $request);
break;
default:
break;
}
/**
* Subtract taxes from subtotal amount if prices include tax
*/
if ($this->_usePriceIncludeTax($store)) {
$subtotal = $address->getSubtotalInclTax() - $address->getTotalAmount('tax');
$baseSubtotal = $address->getBaseSubtotalInclTax() - $address->getBaseTotalAmount('tax');
$address->setTotalAmount('subtotal', $subtotal);
$address->setBaseTotalAmount('subtotal', $baseSubtotal);
}
$this->_addAmount($address->getExtraTaxAmount());
$this->_addBaseAmount($address->getBaseExtraTaxAmount());
$this->_calculateShippingTax($address, $request);
return $this;
}
/**
* Check if price include tax should be used for calculations.
* We are using price include tax just in case when catalog prices are including tax
* and customer tax requist is same as store tax request
*
* @param $store
* @return bool
*/
protected function _usePriceIncludeTax($store)
{
if ($this->_config->priceIncludesTax($store) || $this->_config->getNeedUsePriceExcludeTax()) {
return $this->_areTaxRequestsSimilar;
}
return false;
}
/**
* Tax caclulation for shipping price
*
* @param Mage_Sales_Model_Quote_Address $address
* @param Varien_Object $taxRateRequest
* @return Mage_Tax_Model_Sales_Total_Quote
*/
protected function _calculateShippingTax(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
{
$store = $address->getQuote()->getStore();
$shippingTaxClass = $this->_config->getShippingTaxClass($store);
$shippingAmount = $address->getShippingAmount();
$baseShippingAmount = $address->getBaseShippingAmount();
$shippingDiscountAmount = $address->getShippingDiscountAmount();
$baseShippingDiscountAmount = $address->getBaseShippingDiscountAmount();
/**
* Subtract discount before calculate tax amount
*/
if ($this->_config->applyTaxAfterDiscount($store)) {
$calcAmount = $shippingAmount - $shippingDiscountAmount;
$baseCalcAmount = $baseShippingAmount - $baseShippingDiscountAmount;
} else {
$calcAmount = $shippingAmount;
$baseCalcAmount = $baseShippingAmount;
}
$shippingTax = 0;
$shippingBaseTax = 0;
if ($shippingTaxClass) {
$taxRateRequest->setProductClassId($shippingTaxClass);
$rate = $this->_calculator->getRate($taxRateRequest);
if ($rate) {
if ($this->_config->shippingPriceIncludesTax($store) && $this->_areTaxRequestsSimilar) {
$shippingTax = $this->_calculator->calcTaxAmount($calcAmount, $rate, true, false);
$shippingBaseTax= $this->_calculator->calcTaxAmount($baseCalcAmount, $rate, true, false);
$shippingAmount-= $shippingTax;
$baseShippingAmount-=$shippingBaseTax;
} else {
$shippingTax = $this->_calculator->calcTaxAmount($calcAmount, $rate, false, false);
$shippingBaseTax= $this->_calculator->calcTaxAmount($baseCalcAmount, $rate, false, false);
}
$rateKey = (string) $rate;
if (isset($this->_roundingDeltas[$rateKey])) {
$shippingTax+= $this->_roundingDeltas[$rateKey];
}
if (isset($this->_baseRoundingDeltas[$rateKey])) {
$shippingBaseTax+= $this->_baseRoundingDeltas[$rateKey];
}
$shippingTax = $this->_calculator->round($shippingTax);
$shippingBaseTax = $this->_calculator->round($shippingBaseTax);
$address->setTotalAmount('shipping', $shippingAmount);
$address->setBaseTotalAmount('shipping', $baseShippingAmount);
/**
* Provide additional attributes for apply discount on price include tax
*/
if ($this->_config->discountTax($store)) {
$address->setShippingAmountForDiscount($shippingAmount+$shippingTax);
$address->setBaseShippingAmountForDiscount($baseShippingAmount+$shippingBaseTax);
}
$this->_addAmount($shippingTax);
$this->_addBaseAmount($shippingBaseTax);
$applied = $this->_calculator->getAppliedRates($taxRateRequest);
$this->_saveAppliedTaxes($address, $applied, $shippingTax, $shippingBaseTax, $rate);
}
}
$address->setShippingTaxAmount($shippingTax);
$address->setBaseShippingTaxAmount($shippingBaseTax);
return $this;
}
/**
* Calculate address tax amount based on one unit price and tax amount
*
* @param Mage_Sales_Model_Quote_Address $address
* @return Mage_Tax_Model_Sales_Total_Quote
*/
protected function _unitBaseCalculation(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
{
$items = $address->getAllItems();
foreach ($items as $item) {
/**
* Child item's tax we calculate for parent - that why we skip them
*/
if ($item->getParentItemId()) {
continue;
}
if ($item->getHasChildren() && $item->isChildrenCalculated()) {
foreach ($item->getChildren() as $child) {
$taxRateRequest->setProductClassId($child->getProduct()->getTaxClassId());
$rate = $this->_calculator->getRate($taxRateRequest);
$this->_calcUnitTaxAmount($child, $rate);
$this->_addAmount($child->getTaxAmount());
$this->_addBaseAmount($child->getBaseTaxAmount());
$applied = $this->_calculator->getAppliedRates($taxRateRequest);
$this->_saveAppliedTaxes($address, $applied, $child->getTaxAmount(), $child->getBaseTaxAmount(), $rate);
}
$this->_recalculateParent($item);
}
else {
$taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId());
$rate = $this->_calculator->getRate($taxRateRequest);
$this->_calcUnitTaxAmount($item, $rate);
$this->_addAmount($item->getTaxAmount());
$this->_addBaseAmount($item->getBaseTaxAmount());
$applied = $this->_calculator->getAppliedRates($taxRateRequest);
$this->_saveAppliedTaxes($address, $applied, $item->getTaxAmount(), $item->getBaseTaxAmount(), $rate);
}
}
return $this;
}
/**
* Calculate unit tax anount based on unit price
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @param float $rate
* @return Mage_Tax_Model_Sales_Total_Quote
*/
protected function _calcUnitTaxAmount(Mage_Sales_Model_Quote_Item_Abstract $item, $rate)
{
$store = $item->getStore();
$inclTax = $this->_usePriceIncludeTax($store);
$extra = $item->getExtraTaxableAmount();
$baseExtra = $item->getBaseExtraTaxableAmount();
if ($inclTax) {
$price = $store->roundPrice($item->getTaxCalcPrice()) + $extra;
$basePrice = $store->roundPrice($item->getBaseTaxCalcPrice()) + $baseExtra;
} else {
if ($item->hasCustomPrice() && $this->_helper->applyTaxOnCustomPrice($store)) {
$price = $store->roundPrice($item->getCalculationPrice()) + $extra;
$basePrice = $store->roundPrice($item->getBaseCalculationPrice()) + $baseExtra;
} else {
$price = $store->roundPrice($item->getOriginalPrice()) + $item->getExtraTaxableAmount();
$basePrice = $store->roundPrice($item->getBaseOriginalPrice()) + $item->getBaseExtraTaxableAmount();
}
}
$discountAmount = $item->getDiscountAmount();
$baseDiscountAmount = $item->getBaseDiscountAmount();
$qty = $item->getTotalQty();
$item->setTaxPercent($rate);
$rate = $rate/100;
$calculationSequence = $this->_config->getCalculationSequence($store);
switch ($calculationSequence) {
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL:
$unitTax = $this->_calculator->calcTaxAmount($price, $rate, $inclTax);
$baseUnitTax = $this->_calculator->calcTaxAmount($basePrice, $rate, $inclTax);
break;
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
$unitTax = $this->_calculator->calcTaxAmount($price, $rate, $inclTax);
$baseUnitTax = $this->_calculator->calcTaxAmount($basePrice, $rate, $inclTax);
if ($inclTax) {
$item->setDiscountCalculationPrice($price);
$item->setBaseDiscountCalculationPrice($basePrice);
} else {
$item->setDiscountCalculationPrice($price+$unitTax);
$item->setBaseDiscountCalculationPrice($basePrice+$baseUnitTax);
}
break;
case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL:
case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL:
$unitTax = $this->_calculator->calcTaxAmount($price-$discountAmount/$qty, $rate, $inclTax);
$baseUnitTax = $this->_calculator->calcTaxAmount($basePrice-$baseDiscountAmount/$qty, $rate, $inclTax);
break;
}
$totalTax = $store->roundPrice($qty*$unitTax);
$totalBaseTax = $store->roundPrice($qty*$baseUnitTax);
/**
* Renew item amounts in case if we are working with price include tax
*/
if ($inclTax) {
if ($item->hasCustomPrice()) {
$item->setCustomPrice($item->getPriceInclTax()-$unitTax);
$item->setBaseCustomPrice($item->getBasePriceInclTax()-$baseUnitTax);
} else {
$item->setOriginalPrice($item->getPriceInclTax()-$unitTax);
$item->setPrice($item->getBasePriceInclTax()-$baseUnitTax);
$item->setBasePrice($item->getBasePriceInclTax()-$baseUnitTax);
}
$item->setRowTotal($item->getRowTotalInclTax()-$totalTax);
$item->setBaseRowTotal($item->getBaseRowTotalInclTax()-$totalBaseTax);
}
$item->setTaxAmount($totalTax);
$item->setBaseTaxAmount($totalBaseTax);
return $this;
}
/**
* Calculate address total tax based on row total
*
* @param Mage_Sales_Model_Quote_Address $address
* @param Varien_Object $taxRateRequest
* @return Mage_Tax_Model_Sales_Total_Quote
*/
protected function _rowBaseCalculation(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
{
$items = $address->getAllItems();
foreach ($items as $item) {
/**
* Child item's tax we calculate for parent - that why we skip them
*/
if ($item->getParentItemId()) {
continue;
}
if ($item->getHasChildren() && $item->isChildrenCalculated()) {
foreach ($item->getChildren() as $child) {
$rate = $this->_calculator->getRate(
$taxRateRequest->setProductClassId($child->getProduct()->getTaxClassId())
);
$this->_calcRowTaxAmount($child, $rate);
$this->_addAmount($child->getTaxAmount());
$this->_addBaseAmount($child->getBaseTaxAmount());
$applied = $this->_calculator->getAppliedRates($taxRateRequest);
$this->_saveAppliedTaxes($address, $applied, $child->getTaxAmount(), $child->getBaseTaxAmount(), $rate);
}
$this->_recalculateParent($item);
}
else {
$rate = $this->_calculator->getRate(
$taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId())
);
$this->_calcRowTaxAmount($item, $rate);
$this->_addAmount($item->getTaxAmount());
$this->_addBaseAmount($item->getBaseTaxAmount());
$applied = $this->_calculator->getAppliedRates($taxRateRequest);
$this->_saveAppliedTaxes($address, $applied, $item->getTaxAmount(), $item->getBaseTaxAmount(), $rate);
}
}
return $this;
}
/**
* Calculate item tax amount based on row total
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @param float $rate
* @return Mage_Tax_Model_Sales_Total_Quote
*/
protected function _calcRowTaxAmount($item, $rate)
{
$store = $item->getStore();
$qty = $item->getTotalQty();
$inclTax = $this->_usePriceIncludeTax($store);
if ($inclTax) {
$subtotal = $item->getTaxCalcRowTotal();
$baseSubtotal = $item->getBaseTaxCalcRowTotal();
} else {
if ($item->hasCustomPrice() && $this->_helper->applyTaxOnCustomPrice($store)) {
$subtotal = $item->getRowTotal();
$baseSubtotal = $item->getBaseRowTotal();
} else {
$subtotal = $item->getTotalQty()*$item->getOriginalPrice();
$baseSubtotal = $item->getTotalQty()*$item->getBaseOriginalPrice();
}
}
$subtotal = $subtotal + $item->getExtraRowTaxableAmount();
$baseSubtotal = $baseSubtotal + $item->getBaseExtraRowTaxableAmount();
$discountAmount = $item->getDiscountAmount();
$baseDiscountAmount = $item->getBaseDiscountAmount();
$item->setTaxPercent($rate);
$rate = $rate/100;
$calculationSequence = $this->_helper->getCalculationSequence($store);
switch ($calculationSequence) {
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL:
$rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax);
$baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax);
break;
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
$rowTax = $this->_calculator->calcTaxAmount($subtotal, $rate, $inclTax);
$baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal, $rate, $inclTax);
$discountPrice = $inclTax ? ($subtotal/$qty) : ($subtotal+$rowTax)/$qty;
$baseDiscountPrice = $inclTax ? ($baseSubtotal/$qty) : ($baseSubtotal+$baseRowTax)/$qty;
$item->setDiscountCalculationPrice($discountPrice);
$item->setBaseDiscountCalculationPrice($baseDiscountPrice);
break;
case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL:
case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL:
$rowTax = $this->_calculator->calcTaxAmount($subtotal-$discountAmount, $rate, $inclTax);
$baseRowTax = $this->_calculator->calcTaxAmount($baseSubtotal-$baseDiscountAmount, $rate, $inclTax);
break;
}
/**
* Renew item amounts in case if we are working with price include tax
*/
if ($inclTax) {
$unitTax = $this->_calculator->round($rowTax/$qty);
$baseUnitTax = $this->_calculator->round($baseRowTax/$qty);
if ($item->hasCustomPrice()) {
$item->setCustomPrice($item->getPriceInclTax()-$unitTax);
$item->setBaseCustomPrice($item->getBasePriceInclTax()-$baseUnitTax);
} else {
$item->setOriginalPrice($item->getPriceInclTax()-$unitTax);
$item->setPrice($item->getBasePriceInclTax()-$baseUnitTax);
$item->setBasePrice($item->getBasePriceInclTax()-$baseUnitTax);
}
$item->setRowTotal($item->getRowTotalInclTax()-$rowTax);
$item->setBaseRowTotal($item->getBaseRowTotalInclTax()-$baseRowTax);
}
$item->setTaxAmount($rowTax);
$item->setBaseTaxAmount($baseRowTax);
return $this;
}
/**
* Calculate address total tax based on address subtotal
*
* @param Mage_Sales_Model_Quote_Address $address
* @param Varien_Object $taxRateRequest
* @return Mage_Tax_Model_Sales_Total_Quote
*/
protected function _totalBaseCalculation(Mage_Sales_Model_Quote_Address $address, $taxRateRequest)
{
$items = $address->getAllItems();
$store = $address->getQuote()->getStore();
$taxGroups = array();
foreach ($items as $item) {
/**
* Child item's tax we calculate for parent - that why we skip them
*/
if ($item->getParentItemId()) {
continue;
}
if ($item->getHasChildren() && $item->isChildrenCalculated()) {
foreach ($item->getChildren() as $child) {
$rate = $this->_calculator->getRate(
$taxRateRequest->setProductClassId($child->getProduct()->getTaxClassId())
);
$taxGroups[(string)$rate]['applied_rates'] = $this->_calculator->getAppliedRates($taxRateRequest);
$this->_aggregateTaxPerRate($child, $rate, $taxGroups);
}
$this->_recalculateParent($item);
} else {
$rate = $this->_calculator->getRate(
$taxRateRequest->setProductClassId($item->getProduct()->getTaxClassId())
);
$taxGroups[(string)$rate]['applied_rates'] = $this->_calculator->getAppliedRates($taxRateRequest);
$this->_aggregateTaxPerRate($item, $rate, $taxGroups);
}
}
$inclTax = $this->_usePriceIncludeTax($store);
foreach ($taxGroups as $rateKey => $data) {
$rate = (float) $rateKey;
$totalTax = $this->_calculator->calcTaxAmount(array_sum($data['totals']), $rate, $inclTax);
$baseTotalTax = $this->_calculator->calcTaxAmount(array_sum($data['base_totals']), $rate, $inclTax);
$this->_addAmount($totalTax);
$this->_addBaseAmount($baseTotalTax);
$this->_saveAppliedTaxes($address, $data['applied_rates'], $totalTax, $baseTotalTax, $rate);
}
return $this;
}
/**
* Aggregate row totals per tax rate in array
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @param float $rate
* @param array $taxGroups
* @return Mage_Tax_Model_Sales_Total_Quote
*/
protected function _aggregateTaxPerRate($item, $rate, &$taxGroups)
{
$store = $item->getStore();
$inclTax = $this->_usePriceIncludeTax($store);
if ($inclTax) {
$subtotal = $item->getTaxCalcRowTotal();
$baseSubtotal = $item->getBaseTaxCalcRowTotal();
} else {
if ($item->hasCustomPrice() && $this->_helper->applyTaxOnCustomPrice($store)) {
$subtotal = $item->getRowTotal();
$baseSubtotal = $item->getBaseRowTotal();
} else {
$subtotal = $item->getTotalQty()*$item->getOriginalPrice();
$baseSubtotal = $item->getTotalQty()*$item->getBaseOriginalPrice();
}
}
$discountAmount = $item->getDiscountAmount();
$baseDiscountAmount = $item->getBaseDiscountAmount();
$qty = $item->getTotalQty();
$rateKey = (string) $rate;
/**
* Add extra amounts which can be taxable too
*/
$calcTotal = $subtotal + $item->getExtraRowTaxableAmount();
$baseCalcTotal = $baseSubtotal + $item->getBaseExtraRowTaxableAmount();
$item->setTaxPercent($rate);
if (!isset($taxGroups[$rateKey]['totals'])) {
$taxGroups[$rateKey]['totals'] = array();
}
if (!isset($taxGroups[$rateKey]['totals'])) {
$taxGroups[$rateKey]['base_totals'] = array();
}
$calculationSequence = $this->_helper->getCalculationSequence($store);
switch ($calculationSequence) {
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL:
$rowTax = $this->_calculator->calcTaxAmount($calcTotal, $rate, $inclTax, false);
$baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false);
break;
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
$rowTax = $this->_calculator->calcTaxAmount($calcTotal, $rate, $inclTax, false);
$baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false);
$discountPrice = $inclTax ? ($subtotal/$qty) : ($subtotal+$rowTax)/$qty;
$baseDiscountPrice = $inclTax ? ($baseSubtotal/$qty) : ($baseSubtotal+$baseRowTax)/$qty;
$item->setDiscountCalculationPrice($discountPrice);
$item->setBaseDiscountCalculationPrice($baseDiscountPrice);
break;
case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL:
case Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL:
$calcTotal2 = $calcTotal; // NIKED BY LUSODEV :)
$calcTotal = $calcTotal-$discountAmount;
$baseCalcTotal = $baseCalcTotal-$baseDiscountAmount;
$rowTax = $this->_calculator->calcTaxAmount($calcTotal2, $rate, $inclTax, false); // NIKED BY LUSODEV :)
$baseRowTax = $this->_calculator->calcTaxAmount($baseCalcTotal, $rate, $inclTax, false);
break;
}
/**
* "Delta" rounding
*/
$delta = isset($this->_roundingDeltas[$rateKey]) ? $this->_roundingDeltas[$rateKey] : 0;
$baseDelta = isset($this->_baseRoundingDeltas[$rateKey]) ? $this->_baseRoundingDeltas[$rateKey] : 0;
$rowTax += $delta;
$baseRowTax += $baseDelta;
$this->_roundingDeltas[$rateKey] = $rowTax - $this->_calculator->round($rowTax);
$this->_baseRoundingDeltas[$rateKey] = $baseRowTax - $this->_calculator->round($baseRowTax);
$rowTax = $this->_calculator->round($rowTax);
$baseRowTax = $this->_calculator->round($baseRowTax);
/**
* Renew item amounts in case if we are working with price include tax
*/
if ($inclTax) {
$unitTax = $this->_calculator->round($rowTax/$qty);
$baseUnitTax = $this->_calculator->round($baseRowTax/$qty);
if ($item->hasCustomPrice()) {
$item->setCustomPrice($item->getPriceInclTax()-$unitTax);
$item->setBaseCustomPrice($item->getBasePriceInclTax()-$baseUnitTax);
} else {
$item->setOriginalPrice($item->getPriceInclTax()-$unitTax);
$item->setPrice($item->getBasePriceInclTax()-$baseUnitTax);
$item->setBasePrice($item->getBasePriceInclTax()-$baseUnitTax);
}
$item->setRowTotal($item->getRowTotalInclTax()-$rowTax);
$item->setBaseRowTotal($item->getBaseRowTotalInclTax()-$baseRowTax);
}
$item->setTaxAmount($rowTax);
$item->setBaseTaxAmount($baseRowTax);
$taxGroups[$rateKey]['totals'][] = $calcTotal;
$taxGroups[$rateKey]['base_totals'][] = $baseCalcTotal;
return $this;
}
/**
* Recalculate parent item amounts base on children data
*
* @param Mage_Sales_Model_Quote_Item_Abstract $item
* @return Mage_Tax_Model_Sales_Total_Quote
*/
protected function _recalculateParent(Mage_Sales_Model_Quote_Item_Abstract $item)
{
$calculationPrice = 0;
$baseCalculationPrice = 0;
$rowTaxAmount = 0;
$baseRowTaxAmount = 0;
$rowTotal = 0;
$baseRowTotal = 0;
foreach ($item->getChildren() as $child) {
$calculationPrice += $child->getCalculationPrice();
$baseCalculationPrice += $child->getBaseCalculationPrice();
$rowTaxAmount += $child->getTaxAmount();
$baseRowTaxAmount += $child->getBaseTaxAmount();
$rowTotal += $child->getRowTotal();
$baseRowTotal += $child->getBaseRowTotal();
}
$item->setOriginalPrice($calculationPrice);
$item->setPrice($baseCalculationPrice);
$item->setTaxAmount($rowTaxAmount);
$item->setBaseTaxAmount($baseRowTaxAmount);
$item->setRowTotal($rowTotal);
$item->setBaseRowTotal($baseRowTotal);
return $this;
}
/**
* Collect applied tax rates information on address level
*
* @param Mage_Sales_Model_Quote_Address $address
* @param array $applied
* @param float $amount
* @param float $baseAmount
* @param float $rate
*/
protected function _saveAppliedTaxes(Mage_Sales_Model_Quote_Address $address, $applied, $amount, $baseAmount, $rate)
{
$previouslyAppliedTaxes = $address->getAppliedTaxes();
$process = count($previouslyAppliedTaxes);
foreach ($applied as $row) {
if (!isset($previouslyAppliedTaxes[$row['id']])) {
$row['process'] = $process;
$row['amount'] = 0;
$row['base_amount'] = 0;
$previouslyAppliedTaxes[$row['id']] = $row;
}
if (!is_null($row['percent'])) {
$row['percent'] = $row['percent'] ? $row['percent'] : 1;
$rate = $rate ? $rate : 1;
$appliedAmount = $amount/$rate*$row['percent'];
$baseAppliedAmount = $baseAmount/$rate*$row['percent'];
} else {
$appliedAmount = 0;
$baseAppliedAmount = 0;
foreach ($row['rates'] as $rate) {
$appliedAmount += $rate['amount'];
$baseAppliedAmount += $rate['base_amount'];
}
}
if ($appliedAmount || $previouslyAppliedTaxes[$row['id']]['amount']) {
$previouslyAppliedTaxes[$row['id']]['amount'] += $appliedAmount;
$previouslyAppliedTaxes[$row['id']]['base_amount'] += $baseAppliedAmount;
} else {
unset($previouslyAppliedTaxes[$row['id']]);
}
}
$address->setAppliedTaxes($previouslyAppliedTaxes);
}
/**
* Add tax totals information to address object
*
* @param Mage_Sales_Model_Quote_Address $address
* @return Mage_Tax_Model_Sales_Total_Quote
*/
public function fetch(Mage_Sales_Model_Quote_Address $address)
{
$applied= $address->getAppliedTaxes();
$store = $address->getQuote()->getStore();
$amount = $address->getTaxAmount();
$area = null;
if ($this->_config->displayCartTaxWithGrandTotal($store) && $address->getGrandTotal()) {
$area = 'taxes';
}
if (($amount!=0) || ($this->_config->displayCartZeroTax($store))) {
$address->addTotal(array(
'code' => $this->getCode(),
'title' => Mage::helper('tax')->__('Tax'),
'full_info' => $applied ? $applied : array(),
'value' => $amount,
'area' => $area
));
}
$store = $address->getQuote()->getStore();
/**
* Modify subtotal
*/
if ($this->_config->displayCartSubtotalBoth($store) || $this->_config->displayCartSubtotalInclTax($store)) {
if ($address->getSubtotalInclTax() > 0) {
$subtotalInclTax = $address->getSubtotalInclTax();
} else {
$subtotalInclTax = $address->getSubtotal()+$address->getTaxAmount()-$address->getShippingTaxAmount();
}
$address->addTotal(array(
'code' => 'subtotal',
'title' => Mage::helper('sales')->__('Subtotal'),
'value' => $subtotalInclTax,
'value_incl_tax' => $subtotalInclTax,
'value_excl_tax' => $address->getSubtotal(),
));
}
return $this;
}
/**
* Process model configuration array.
* This method can be used for changing totals collect sort order
*
* @param array $config
* @param store $store
* @return array
*/
public function processConfigArray($config, $store)
{
$calculationSequence = $this->_helper->getCalculationSequence($store);
switch ($calculationSequence) {
case Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL:
$config['before'][] = 'discount';
break;
default:
$config['after'][] = 'discount';
break;
}
return $config;
}
}
|
Nous avons commenté les lignes sur lesquelles nous sommes intervenus, avec la mentions "// NIKED BY LUSODEV" : c'est un petit délire, faut bien après les heures passées dessus... !
Tenez-moi informé pour savoir si tout se passe sans problème, ainsi que vos tests
Voici la configuration à faire dans l'onglet TVA du menu SYSTÈME > CONFIGURATION (soumis à test, car je ne sais plus si j'avais bien fini de paramétrer cette boutique...) :
|
|
|
|
Dernière édition: 22/03/10 à 18:27 Par Johan.
|
|
|
Re:1.4 Toujours des problèmes sur les remises Il y a 1 Année, 10 Mois
|
Karma: 0
|
|
De mon côté, cela n'a pas corrigé le problème de mettre à jour les fichiers mentionnés.
Par contre, je n'ai pu respecter la configuration des Taxes jointes.
Mes prix boutiques sont TTC et doivent s'afficher comme tels dans le panier.
|
|
|
|
|
|
 | | |
|