2

Downloadable product have multiple download link and i want to get link which added in cart. I have tried this code but it gives all availbale links

$_links = $_item->getProduct()->getTypeInstance(true)->getLinks($_item->getProduct()); 
1

2 Answers 2

1

Use below code to get link which added in cart:

foreach ($links as $link) {
    if (preg_match("/epub/i", $link->getTitle())) {
        $linkId = $link->getLinkId();
    }
}
2
  • Where did you get that /epub/ string in the regex from? Aug 19, 2015 at 15:57
  • Looks to me like he is just filtering the links for epub links.
    – MB34
    Nov 17, 2015 at 16:10
1

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');
            $options->addItemFilter($ItemId);
            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);
        //print_r($linkIdsArr);
        $totalLinks = count($linkIdsArr);
        //die;


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

It worked for me.. try yourself.. find link

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.