Comment obtenir des liens de produits téléchargeables après commande réussie
Question
Après un ordre Successfull je voudrais proposer directement l'URL téléchargeable pour les produits achetés acheteur dans le fichier success.phtml.
J'ai écrit ce morceau de code pour connaître les valeurs de produits de la dernière commande:
// Get the latest Order ID
$order = Mage::getModel('sales/order')->load(Mage::getSingleton('checkout/session')->getLastOrderId());
// Get every products on the latest order
$items = $order->getAllItems();
// Loop the products
foreach ($items as $item){
$product = Mage::getModel('catalog/product')->setStoreId($order->getStoreId())->load($item->getProductId());
// HERE I NEED FUNCTION TO GET DOWNLOADABLE URL LINK
}
La solution
J'ai trouvé une solution, la voici:
Tout d'abord, créez un nouveau fichier dans .phtml / template / téléchargeable, je le mien appelé downloadablelist.phtml
Copiez alors tous template / téléchargeable / client / produits / list.phtml dans notre nouvelle downloadablelist.phtml
Cela nous donnera une copie du compte client ma liste de produits téléchargeables.
Appelez notre bloc page succès:
<?php echo $this->getLayout()->createBlock('downloadable/customer_products_list')->setTemplate('downloadable/checkout/downloadablelist.phtml')->toHtml(); ?>
Maintenant, je nettoyais ce que je ne ai pas besoin de la liste des produits. J'ai enlevé la table et a ajouté un ul à la place.
Ensuite est de montrer que les produits qui sont fabriqués à partir de la dernière commande.
<?php
$_items = $this->getItems();
$orderId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
if(count($_items)):
$_group_id = Mage::helper('customer')->getCustomer()->getGroupId();
echo '<p><strong>'.$this->__('Downloadable products').' : </strong></p>'; ?>
<ul style="margin-left: 30px; list-style: disc;">
<?php foreach ($_items as $_item):
$itemOrderId = $_item->getPurchased()->getOrderIncrementId();
if($itemOrderId == $orderId) {?>
<li><?php echo $this->htmlEscape($_item->getPurchased()->getProductName()) ?> - <a href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>" title="<?php echo Mage::helper('downloadable')->__('Start Download') ?>" <?php echo $this->getIsOpenInNewWindow()?'onclick="this.target=\'_blank\'"':''; ?>><?php echo $_item->getLinkTitle() ?></a></li>
<?php }
endforeach; ?>
</ul>
<?php endif; ?>
J'ai changé l'URL du fichier téléchargeable d'origine a dû:
href="<?php echo $this->getUrl('downloadable/download/link/', array('id' => $_item->getLinkHash(), '_secure' => true)) ?>"
Merci
Autres conseils
Cela a fonctionné pour moi:
$links = Mage::getModel('downloadable/link_purchased_item')->getCollection()
->addFieldToFilter('order_item_id', $item->getId());
foreach ($links as $link) {
echo Mage::helper('downloadable')->__('download') .
$this->getUrl('downloadable/download/link',
array('id' => $link->getLinkHash(), '_store' => $order()->getStore(),
'_secure' => true, '_nosid' => true));
}