I have ques.

I want to get downloadable products link added in cart..

Mean I want total links added in cart

I have used below code..

I am developing functionality to auto discount if downloadable products links are more than 2 in cart.

I created event

    <?xml version="1.0"?>

and below method in observer

class Manoj_AutoDiscount_Model_Observer
    public function applyAutoDiscount($observer)

$items =Mage::getSingleton('checkout/session')->getQuote()->getAllItems();
        foreach($items as $item) {
            $_links = $item->getProduct()->getTypeInstance(true)->getLinks($item->getProduct());
echo count($_links)

            foreach ($_links as $link) {
                   // echo "<br/>Link ids".$linkId = $link->getLinkId();echo "<br/>";


Here I am getting all link of downloadable products. I need only links added in cart only.. e.g products has 3 links and we added only 2 links in cart then i want record of 2 links only not of 3.

Can you please provide solution for same.. Appreciate your help..

Thanks in adavnce

Manoj Ninave

1 Answer 1


Finally I developed solution for this issue..

$currentcart = Mage::getModel('checkout/cart');
        $quote = $currentcart->getQuote();
        $quoteItems = $quote->getAllVisibleItems();
        $totalLinks = 0;
        $linkIds = "";
        foreach ($quoteItems as $item) {
            $ItemId = $item->getId();
            $options = Mage::getResourceModel('sales/quote_item_option_collection');
            foreach ($options as $option) {
                if ($option['code'] == 'downloadable_link_ids') {
                    $linkIds .= $option['value'] . ",";

        $itemIds = substr($linkIds, 0, -1);
        //echo "Link Ids=" . $itemIds;
        $linkIdsArr = explode(',', $itemIds);
        $totalLinks = count($linkIdsArr);

        if ($totalLinks > 1) {
        //Get discount

It worked for me.. try yourself.. Practice makes man Pefect ;)

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.