0

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"?>
<config>
  <modules>
    <Manoj_AutoDiscount>
      <version>0.1.0</version>
    </Manoj_AutoDiscount>
  </modules>
  <global>
    <models>
      <checkout>
        <rewrite>
          <observer>Manoj_AutoDiscount_Model_Observer</observer>
        </rewrite>
      </checkout>
    </models>
    <events>
      <checkout_cart_add_product_complete>
        <observers>
          <checkoutApplyCouponToProduct>
            <type>singleton</type>
            <class>Manoj_AutoDiscount_Model_Observer</class>
            <method>applyAutoDiscount</method>
          </checkoutApplyCouponToProduct>
        </observers>
      </checkout_cart_add_product_complete>
      <sales_order_place_after>
        <observers>
          <checkoutRemoveCouponAuto>
            <type>singleton</type>
            <class>Manoj_AutoDiscount_Model_Observer</class>
            <method>removeAutoDiscount</method>
          </checkoutRemoveCouponAuto>
        </observers>
      </sales_order_place_after>
    </events>
  </global>
</config>

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

0

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');
            $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.. Practice makes man Pefect ;)

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.