Reputation: 495
I'm in the middle of developing a shipping module for Magento but get stuck on How to get the items that's currently in the cart for that session.
I follow some tutorial on the internet, they use:
if ($request->getAllItems()) {
foreach ($request->getAllItems() as $item) {
//do something here.....
}
}
My problem is that I don't know exactly what info/data that's on the $item variable??.
I want to get the weight and the price of the product that's currently on the cart to calculate the shipping fee. I tried to print the $item value by using Mage::log or printing it to the screen using print_r
or var_dump
but it's not successful. The log is empty and the variable won't be printed on screen.
Can somebody inform me of how to get the $item attributes/method
or is there any other way to get the product information that's currently in cart?
Upvotes: 0
Views: 8596
Reputation: 391
I was searching for this solution and found below. but not tested.
$CartSession = Mage::getSingleton('checkout/session');
foreach($CartSession->getQuote()->getAllItems() as $item)
{
$productWeight = $item->getWeight();
$productExPrice = $item->getPrice(); // price excluding tax
$productIncPrice = $item->getPriceInclTax(); // price excluding tax
}
Upvotes: 1
Reputation: 156
If you want to know information about $item, you can do this:
print_r($item->getData());
If you want to get item weight, here is it:
$item->getWeight();
Upvotes: 0
Reputation: 2282
you can achive this by using one of three methods which are available in Mage::getSingleton('checkout/session')->getQuote();
getItemsCollection()
- retrive sales/quote_items
collectiongetAllItems()
- retrive all itemsgetAllVisibleItems()
- retrive items which aren't deleted and have parent_item_id != null
Upvotes: 2