0

I want to get product detail and category of that product, which product is added in cart. But I want those product in shipping method. I am using Fedex Shipping method. I want those details in this function.

app\code\core\Mage\Usa\Model\Shipping\Carrier\Fedex.php

protected function _prepareRateResponse($response)
{
     // Need Product details and category id of that product
}

Thank you in advanced!

2 Answers 2

4

First off, please don't change the core class. Extend it from an extension or at least copy the file to the local directory.

You can access the quote object in the shipping method to get the product you want.

$quote= Mage::getSingleton('checkout/session')->getQuote();
foreach ($quote->getAllItems() as $item) 
{
   $product = $item->getProduct(); // the product instance
   var_dump($product->getName());
   var_dump($product->getCategoryIds());
}
2
  • Magel, Thanks for your post. But I need Cart details. As well as I need product qty. Commented Dec 21, 2013 at 10:39
  • var_dump($item->getData()); will show you the data available of the item (such as qty) and you can perform the same getData call on the quote item Commented Dec 21, 2013 at 10:40
1
$items = Mage::getSingleton('checkout/session')->getQuote()->getAllItems();

foreach($items as $item) {
    $proid=$item->getProduct()->getId();
    $categoryIds=$item->getProduct()->getCategoryIds($proid);
    foreach($categoryIds as $categoryId)
    {

        $category = Mage::getModel('catalog/category')->load($categoryId);

    }
    echo  "category: ".$category->getName();
    echo '<br/>';
    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 />";
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.