【问题标题】:Magento - Get products price with tax and discounts in cart/order (Criteo tags)Magento - 在购物车/订单中获取含税和折扣的产品价格(Criteo 标签)
【发布时间】:2014-08-18 08:37:19
【问题描述】:

为了实现 Criteo 标签,我正在尝试获取购物车(和成功页面)中所有产品的价格(除其他外),包括税收和折扣。 我目前正在做这样的事情,但它只显示折扣和不含税的价格:

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

我已经测试了很多东西,但无法让它工作。 谢谢帮忙

【问题讨论】:

    标签: magento cart criteo


    【解决方案1】:

    我认为你可以使用,

    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.'
    ';
     }
     ?>
    

    【讨论】:

    • 您好,感谢您的回答。问题是,我正在寻找我购物车中每件商品的价格(折扣和含税)(因此是我的 foreach)。有没有办法用你的方法做到这一点?谢谢。
    • 试试,getStore('default'); $request = Mage::getSingleton('tax/calculation')->getRateRequest(null, null, null, $store); $taxclassid = $item->getData('tax_class_id') $percent = Mage::getSingleton('tax/calculation')->getRate($request->setProductClassId($taxclassid)); ?>
    【解决方案2】:

    您可以获取每件商品的折扣和税收价值并进行计算。

    $_item->getDiscountAmount
    $_item->getTaxAmount
    
    $totalItemPrice = $_item->getPrice - $_item->getDiscountAmount + $_item->getTaxAmount
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多