10
votes

I have a pretty weird issue, I hope someone can help me with this.

Here are the major config settings that influence my problem:

  • Catalog prices in admin panel are shown including tax
  • Catalog prices in frontend are shown including tax
  • Items in shopping cart are shown excluding tax (so it's displayed separately near the subtotal).

Everything is working fine so far. The problem comes in a custom ajax mini cart module. I grab the collection of items from the cart, but, since I'm getting the price from the shopping cart item, I get it without tax.

Here is some code to exemplify what I mean. I will assume a 20% tax and a product that has the admin price (including tax) set to 120$, an option that costs 60$ (also including tax). Excluding tax these would be 100$ and 50$. I want to get the price + option + tax => 180$

$quote = Mage::getSingleton('checkout/session')->getQuote();
$items = $quote->getAllVisibleItems();
foreach ($items as $item) {
    echo $item->getPrice(); // 150$ - price excluding tax
    echo $item->getPriceInclTax(); // 150$ - price excluding tax
    echo $item->getProduct()->getPrice(); // 120$ price including tax, BUT without the customer selected options.
}

PS: The custom option I am talking about is user selected, for example an install checkbox that adds +50$ to the price of the product.

6
FYI, Magento now has its own SE site: magento.stackexchange.comJohn Conde
Ah, thanks. I will post my next question related to magento there. Or should I move this one here ?Vlad Preda
Not sure. I would flag it to be moved and see what happens. It's a good question and it would help the new site get off to a good start IMHO.John Conde
Maybe this will help you: stackoverflow.com/questions/7270261/…Marceli Po

6 Answers

2
votes
- Get products id, name, price, quantity, etc. present in your cart.
- Get number of items in cart and total quantity in cart.
- Get base total price and grand total price of items in cart.

Get all items information in cart
// $items = Mage::getModel('checkout/cart')->getQuote()->getAllItems();
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();

foreach($items as $item) {
    echo 'ID: '.$item->getProductId().'<br />';
    echo 'Name: '.$item->getName().'<br />';
    echo 'Sku: '.$item->getSku().'<br />';
    echo 'Quantity: '.$item->getQty().'<br />';
    echo 'Price: '.$item->getPrice().'<br />';
    echo "<br />";           
}

Get total items and total quantity in cart
$totalItems = Mage::getModel('checkout/cart')->getQuote()->getItemsCount();
$totalQuantity = Mage::getModel('checkout/cart')->getQuote()->getItemsQty();

Get subtotal and grand total price of cart
$subTotal = Mage::getModel('checkout/cart')->getQuote()->getSubtotal();
$grandTotal = Mage::getModel('checkout/cart')->getQuote()->getGrandTotal();
1
votes

Have you tried:

$product->getFinalPrice();

// or this?
$product->getPriceModel()->getFinalPrice($qty, $product);
1
votes

what is the ouput of $item->getOptions()? Have you tried $item->getData('price')? How do you apply your custom options? What is the ouput of $item->debug()? Maybe you can find what you need there.

Regards Simon

1
votes

I didn't find a solution to my exact problem, but I changed the settings to mimic this exact functionality, and the problem I encountered was no longer there.

First of all, I removed all the taxes on the site, and told magento all the prices are excluding tax (even though they are including tax).

The tax reduction is now made through a promotion applied on a custom group, so for

$tax = 20; // percent 

I add a reduction of

(1 - (1 / ($tax / 100 + 1)))*100 
// for 20% tax => 16.6667% reduction
// for 24% tax => 19.3548% reduction

with 4 decimals (that's as much as magento accepts). It may have an error of 1 cent from time to time - so if this is not an issue, go for it!

Now the prices all over the website will be shown exactly for the product (because the promotion is applied per cart, not per product).

0
votes

You can try This :

$grandTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
echo $text .= $this->__(' Total: %s', $this->helper('core')->formatPrice($grandTotal, false));
0
votes

show the quantity of a cart in my header

if ($parentBlock = $this->getParentBlock()) {
$count = $this->helper('checkout/cart')->getSummaryCount();
if( $count == 1 ) {
echo $text = $this->__('My Cart (%s item)', $count);
} elseif( $count > 0 ) {
echo $text = $this->__('My Cart (%s items)', $count);
} else {
echo $text = $this->__('My Cart (0 items)');
}
}

show the total price of a cart in my header

$grandTotal = $this->helper('checkout/cart')->getQuote()->getGrandTotal();
echo $text .= $this->__(' Total: %s', $this->helper('core')->formatPrice($grandTotal, false));