我想做什么让购物车物品对象并将其存储在新变量中,循环使用它们,更改价格然后我想重新计算新总额的税。
如何尽可能地实现这一目标。
这是我制作的代码,但可以理解的是,由于我无法做到这一点而无法重新计算税款:
$items=$address ;// add is of type Mage_Sales_Model_Quote_Address $address
foreach ($items->getQuote()->getAllVisibleItems() as $item){
if ($items->getParentItem()) {
continue;
}
try{
if ($item){
$qty = $item->getTotalQty();
$total = $item->getCalculationPrice()*$qty*2;
$baseTotal = $item->getBaseCalculationPrice()*$qty*2;
$item->setRowTotal(Mage::app()->getStore()->roundPrice($total));
$item->setBaseRowTotal(Mage::app()->getStore()->roundPrice($baseTotal));
$item->save();
}
}catch (Exception $e){
}
}
$baseTax = ($items->getTaxBeforeDiscount() ? $items->getTaxBeforeDiscount() : ($items->getTaxAmount() ? $items->getTaxAmount() : 0));
$tax = ($items->getBaseTaxBeforeDiscount() ? $items->getBaseTaxBeforeDiscount() : ($items->getBaseTaxAmount() ? $items->getBaseTaxAmount() : 0));
答案 0 :(得分:0)
您可以使用地址'税额和总额来计算税/增值税率。更新地址后,总计使用费率计算新的税额。
看一下以下示例
/* calculate ratio */
$ratio = ($address->getTaxAmount() / $address->getGrandTotal());
$baseRatio = ($address->getBaseTaxAmount() / $address->getBaseGrandTotal());
/* do price changes */
$address->setGrandTotal(...);
$address->setBaseGrandTotal(...);
/* ... */
/* set new tax amount */
$address->setTaxAmount($address->getGrandTotal() * $ratio);
$address->setBaseTaxAmount($address->getBaseGrandTotal() * $baseRatio);
$address->save();