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

Use below code to get link which added in cart:

foreach ($links as $link) {
    if (preg_match("/epub/i", $link->getTitle())) {
        $linkId = $link->getLinkId();
    }
}
|improve this answer|||||
  • Where did you get that /epub/ string in the regex from? – Anna Völkl Aug 19 '15 at 15:57
  • Looks to me like he is just filtering the links for epub links. – MB34 Nov 17 '15 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

|improve this answer|||||

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.