2

Each item in my checkout cart have deal_price. I want to get deal_price of each item. But it only get deal_price of first item.

$quote = Mage::getSingleton('checkout/cart')->getQuote();
        $discount = 0;
        if (Mage::getStoreConfigFlag('dailydeal/configuration/enabled')) {
            $resource = Mage::getSingleton('core/resource');
            $cartItems = $quote->getAllItems();
            $collection = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToSelect('*')
                ->joinTable($resource->getTableName('dailydeal_deal'), 'product_id = entity_id', array('deal_id' => 'deal_id', 'deal_price' => 'deal_price'), '{{table}}.status=1', 'inner');

            foreach ($cartItems as $item) {
                $productId = $item->getProductId();
                $qty = $item->getQty();
                $productPrice = $item->getPrice();
                echo $productPrice;
                echo "<br/>";
                $deal = $collection->addAttributeToFilter('entity_id', $productId)->getFirstItem();
                $dealPrice = $deal->getDealPrice();

                echo($dealPrice);
                echo "<br/>";

                $discount = ($productPrice - $dealPrice) * $qty + $discount;
                echo($discount);
            }
2

Put below this inside foreach loop instead of out side .Then it will be work.

$collection = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToSelect('*')
                ->joinTable($resource->getTableName('dailydeal_deal'), 'product_id = entity_id', array('deal_id' => 'deal_id', 'deal_price' => 'deal_price'), '{{table}}.status=1', 'inner');

So you need to change

$deal = $collection->addAttributeToFilter('entity_id', $productId)->getFirstItem();
                $dealPrice = $deal->getDealPrice();

to

$collection = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToSelect('*')
                ->joinTable($resource->getTableName('dailydeal_deal'), 'product_id = entity_id', array('deal_id' => 'deal_id', 'deal_price' => 'deal_price'), '{{table}}.status=1', 'inner'); 
$deal = $collection->addAttributeToFilter('entity_id', $productId)->getFirstItem();
$dealPrice = $deal->getDealPrice();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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