1

I have been tasked for creating a order for a downloadable product and placing a order via Paypal and fortunately I've done the task pretty well.

But when the customer get his order email the download link for the product is not showing.

Below in my code that I've used :

<?php
if(!isset($_GET['p'])){
    $msg = '<h2>Wrong data passed!!</h2>';
}
else{
$product = Mage::getModel('catalog/product')->load($_GET['p']);
$cancel_url = Mage::getURL('').'paypal/standard/cancel/';
$return_url = Mage::getURL('').'paypal/standard/success/';
$notify_url = Mage::getURL('').'paypal/ipn/';

if(Mage::getStoreConfig('payment/paypal_standard/sandbox_flag')=='1'){
    $paypal_url = 'https://www.sandbox.paypal.com/cgi-bin/webscr?';
}
else{
    $paypal_url = 'https://www.paypal.com/cgi-bin/webscr?';
}
$price = number_format((float)$product->getPrice(),2,'.',''); 
$quote = Mage::getModel('sales/quote');

$quote->setCustomerEmail('magegurusit@gmail.com');

$quote->setStore(Mage::app()->getStore());   

$quoteItem = Mage::getModel('sales/quote_item')->setProduct($product);
$quoteItem->setQuote($quote);
$quoteItem->setQty(1);
$quote->addItem($quoteItem);

$addressData = array(
'firstname' => 'Guest',
'lastname' => 'Customer',
'street' => 'Some address on the earth',
'city' => 'Somewhere',
'postcode' => '123456',
'telephone' => '123456',
'country_id' => 'US',
'region_id' => 12, // id from directory_country_region table,
'use_for_shipping'=>1
);

$billingAddress = $quote->getBillingAddress()->addData($addressData);
/*$shippingAddress = $quote->getShippingAddress()->addData($addressData);
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod('flatrate_flatrate')
->setPaymentMethod('paypal_standard');*/

$quote->getPayment()->importData(array('method'=>'paypal_standard'));
$quote->collectTotals()->save();
$service = Mage::getModel('sales/service_quote', $quote);
try {
    $service->submitAll();
    $order = $service->getOrder();
    $invoice = $order->getIncrementId();
} catch (Exception $e){   
    Mage::log($e->getMessage());
}

Order is creating properly. Don't know what little extra I'm missing in the above. Please help me on this. Thanks

  • Any one has any answer? – ravisoni Mar 24 '14 at 16:03
  • did you ever solve this problem? – David Manners May 24 '14 at 6:34
4

the download link for the product is not showing

This could mean the link as a whole does not show up, the link target is empty or it is not generated at all (no link_hash value) in the database.

The link to the downloadable Product gets generated within the sales_order_item_save_commit_after event in the saveDownloadableOrderItem method in Mage_Downloadable_Model_Observer.

So if it is not generated at all, have a look in your downloadable_link_purchased_item database table and check if there are values under link_hash and link_url or link_file fields.

If not, you might have another problem, with your e-mail template maybe.

1

add this, inspired from https://stackoverflow.com/questions/13712475/magento-adding-to-customers-available-downloadable-products

$order = $service->getOrder();
$orderItems = Mage::getModel('sales/order')->load($order->getId());
        foreach ($orderItems->getAllItems() as $itemId => $orderItem) {
            $product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
            if($product->getTypeId()=='downloadable') {
                $product_links = Mage::getModel('downloadable/product_type')->getLinks( $product );
                foreach ($product_links as $link) {
                    $downloadPurchase = Mage::getModel('downloadable/link_purchased')
                        ->setOrderId($orderItem->getOrderId())
                        ->setOrderIncrementId($orderItems->getIncrementId())
                        ->setOrderItemId($orderItem->getId())
                        ->setCreatedAt(date('Y-m-d H:i:s'))
                        ->setUpdatedAt(date('Y-m-d H:i:s'))
                        ->setCustomerId($orderItems->getCustomerId())
                        ->setProductName($product->getName())
                        ->setProductSku($product->getSku())
                        ->setLinkSectionTitle('Click here to download');

                    $downloadPurchase->save();

                    $linkHash = strtr(base64_encode(microtime() . $downloadPurchase->getId() . $orderItem->getId() . $product->getId()), '+/=', '-_,');
                    $downloadItem = Mage::getModel('downloadable/link_purchased_item')
                        ->setProductId($product->getId())
                        ->setNumberOfDownloadsBought(0)
                        ->setNumberOfDownloadsUsed(0)
                        ->setLinkTitle($link->getTitle())
                        ->setIsShareable($link->getData('is_shareable'))
                        ->setLinkFile($link->getData('link_file'))
                        ->setLinkType('file')
                        ->setStatus('available')
                        ->setCreatedAt(date('Y-m-d H:i:s'))
                        ->setUpdatedAt(date('Y-m-d H:i:s'))
                        ->setLinkHash($linkHash)
                        ->setOrderItemId($orderItem->getId())
                        ->setPurchasedId($downloadPurchase->getId());

                    $downloadItem->save();
                }
            }
        }

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.