Magento - Получите цену товара с налогом и скидками в корзине/заказе (теги Criteo)

Для реализации тегов Criteo я пытаюсь получить цену (среди прочего) всех товаров в корзине (и страницу успеха) с налогом и скидками. В настоящее время я делаю что-то подобное, но он отображает только цену со скидкой и без налога:

$cartAllItems = Mage::getModel('checkout/cart')->getItems();
foreach ($cartAllItems as $item){
    $price = Mage::helper('tax')->getPrice($item->getProduct(), $item->getProduct()->getFinalPrice());
    // other things
}

Я тестировал много вещей и не могу заставить это работать. Спасибо за помощь


person Krusty    schedule 18.08.2014    source источник


Ответы (2)


Я думаю, вы можете использовать,

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.'
';
 }
 ?>
person Niraj Jani    schedule 18.08.2014
comment
Эй, спасибо за ответ. Дело в том, что я хочу получить цену (со скидкой и с учетом налогов) для КАЖДОГО товара в моей корзине (отсюда и мой foreach). Есть ли способ сделать это с помощью вашего метода? Спасибо. - person Krusty; 18.08.2014
comment
попробуйте, ‹?php $store = Mage::app()-›getStore('default'); $request = Mage::getSingleton('налог/расчет')->getRateRequest(null, null, null, $store); $taxclassid = $item-›getData('tax_class_id') $percent = Mage::getSingleton('налог/расчет')-›getRate($request-›setProductClassId($taxclassid)); ?› - person Niraj Jani; 18.08.2014

Вы можете получить скидку и налоговую стоимость на единицу товара и сделать расчет.

$_item->getDiscountAmount
$_item->getTaxAmount

$totalItemPrice = $_item->getPrice - $_item->getDiscountAmount + $_item->getTaxAmount
person Gabriel G    schedule 05.04.2020