0

I have a Magento CE 1.9.1 web store for downloadable products (images) which can be purchased individually.

What do I need to do to make it possible for a customer to pay for a whole month or several months and then be able to download a certain (limited) amount of different images every day or week, or for the whole period. Basically - just like he would by using Shutterstock or similar with a subscription pre-payment.

Is that possible?

1 Answer 1

0

Its little bit late to answering. But you can change downloadable links for every interval like below :

Mage_Downloadable_Model_Observer

/**
 * Save data from order to purchased links
 *
 * @param Varien_Object $observer
 * @return Mage_Downloadable_Model_Observer
 */
public function saveDownloadableOrderItem($observer)
{
    $orderItem = $observer->getEvent()->getItem();
    if (!$orderItem->getId()) {
        //order not saved in the database
        return $this;
    }
    $product = $orderItem->getProduct();
    if ($product && $product->getTypeId() != Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
        return $this;
    }
    if (Mage::getModel('downloadable/link_purchased')->load($orderItem->getId(), 'order_item_id')->getId()) {
        return $this;
    }
    if (!$product) {
        $product = Mage::getModel('catalog/product')
            ->setStoreId($orderItem->getOrder()->getStoreId())
            ->load($orderItem->getProductId());
    }
    if ($product->getTypeId() == Mage_Downloadable_Model_Product_Type::TYPE_DOWNLOADABLE) {
        $links = $product->getTypeInstance(true)->getLinks($product);

        if ($linkIds = $orderItem->getProductOptionByCode('links')) {
            $linkPurchased = Mage::getModel('downloadable/link_purchased');
            Mage::helper('core')->copyFieldset(
                'downloadable_sales_copy_order',
                'to_downloadable',
                $orderItem->getOrder(),
                $linkPurchased
            );
            Mage::helper('core')->copyFieldset(
                'downloadable_sales_copy_order_item',
                'to_downloadable',
                $orderItem,
                $linkPurchased
            );
            $linkSectionTitle = (
                $product->getLinksTitle()?
                $product->getLinksTitle():Mage::getStoreConfig(Mage_Downloadable_Model_Link::XML_PATH_LINKS_TITLE)
            );
            $linkPurchased->setLinkSectionTitle($linkSectionTitle)
                ->save();
            foreach ($linkIds as $linkId) {

                if (isset($links[$linkId])) {

           // ************** Make your changes here  ************
          // Here downloadable link with id 23 will assign to new order

                    if ($linkId == 23)
                    {
                        $linkPurchasedItem = Mage::getModel('downloadable/link_purchased_item')
                            ->setPurchasedId($linkPurchased->getId())
                            ->setOrderItemId($orderItem->getId());
                        Mage::helper('core')->copyFieldset(
                            'downloadable_sales_copy_link',
                            'to_purchased',
                            $links[$linkId],
                            $linkPurchasedItem
                        );
                        $linkHash = strtr(base64_encode(microtime() . $linkPurchased->getId() . $orderItem->getId()
                            . $product->getId()), '+/=', '-_,');
                        $numberOfDownloads = $links[$linkId]->getNumberOfDownloads()*$orderItem->getQtyOrdered();
                        $linkPurchasedItem->setLinkHash($linkHash)
                            ->setNumberOfDownloadsBought($numberOfDownloads)
                            ->setStatus(Mage_Downloadable_Model_Link_Purchased_Item::LINK_STATUS_PENDING)
                            ->setCreatedAt($orderItem->getCreatedAt())
                            ->setUpdatedAt($orderItem->getUpdatedAt())
                            ->save();
                    }
                }
            }
        }
    }
    return $this;
}

Please try to override this event in your module first.

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.