对于Criteo标签的实现,我试图获得购物车(和成功页面)中所有产品的价格(以及其他内容),包括税和折扣。我目前正在做这样的事情,但它只显示价格折扣和不含税:
$cartAllItems = Mage::getModel('checkout/cart')->getItems();
foreach ($cartAllItems as $item){
$price = Mage::helper('tax')->getPrice($item->getProduct(), $item->getProduct()->getFinalPrice());
// other things
}
我已经测试了很多东西,但不能使它工作。谢谢你的帮助
我想你可以用
Mage::helper('checkout')->getQuote()->getShippingAddress()->getData('tax_amount')
这将返回您的总税额。或者可以使用
$totalItemsInCart = Mage::helper('checkout/cart')->getItemsCount();
$totals = Mage::getSingleton('checkout/session')->getQuote()->getTotals();
$subtotal = round($totals["subtotal"]->getValue());
$grandtotal = round($totals["grand_total"]->getValue());
if(isset($totals['discount']) && $totals['discount']->getValue()) {
$discount = round($totals['discount']->getValue());
} else {
$discount = '';
}
if(isset($totals['tax']) && $totals['tax']->getValue()) {
$tax = round($totals['tax']->getValue());
} else {
$tax = '';
}
修改我想是符合你的要求的
foreach ($productIds as $productId) {
$_product = Mage::getModel('catalog/product')->load($productId);
$productsPrice = floatval($_product->getData("price"));
// Get the product's tax class' ID
$taxClassId = $_product->getData("tax_class_id");
echo 'Tax Class ID '.$taxClassId.'
';
// Get the tax rates of each tax class in an associative array
$taxClasses = Mage::helper("core")->jsonDecode( Mage::helper("tax")-
>getAllRatesByProductClass() );
echo 'Tax Classes '.$taxClasses.'
';
// Extract the tax rate from the array
$taxRate = $taxClasses["value_".$taxClassId];
echo 'Tax Rate '.$taxRate.'
';
}
?>
您可以获得每项商品的折扣和税额,并进行计算。
$_item->getDiscountAmount
$_item->getTaxAmount
$totalItemPrice = $_item->getPrice - $_item->getDiscountAmount + $_item->getTaxAmount