0

I'm trying to add an extra data to the file:

/app/design/adminhtml/default/ad02/template/downloadable/sales/items/column/downloadable/name.phtml

Target idea: provide a link with a href="....":

<?php if ($this->getLinks()): ?>
        <dl class="item-options">
            <dt><?php echo $this->getLinksTitle(); ?></dt>
            <?php foreach ($this->getLinks()->getPurchasedItems() as $_link): ?>
                <dd>
                  <a title="Download" href="<?php echo $_link->getLinkHref() ?>">
                    <?php echo $_link->getLinkTitle() ?>
                  </a> (<?php echo $_link->getNumberOfDownloadsUsed() . ' / ' . ($_link->getNumberOfDownloadsBought()?$_link->getNumberOfDownloadsBought():Mage::helper('downloadable')->__('U')) ?>)</dd>
            <?php endforeach; ?>
        </dl>
    <?php endif; ?>
    <?php echo $this->htmlEscape($_item->getDescription()) ?>

I suppose to do that by extending a related Magento Block with a new method getLinkHref()(see above). This is current Block Class contents:

class Mage_Downloadable_Block_Adminhtml_Sales_Items_Column_Downloadable_Name extends Mage_Adminhtml_Block_Sales_Items_Column_Name
{
    protected $_purchased = null;
    public function getLinks()
    {
        $this->_purchased = Mage::getModel('downloadable/link_purchased')
            ->load($this->getItem()->getOrder()->getId(), 'order_id');
        $purchasedItem = Mage::getModel('downloadable/link_purchased_item')->getCollection()
            ->addFieldToFilter('order_item_id', $this->getItem()->getId());
        $this->_purchased->setPurchasedItems($purchasedItem);
        return $this->_purchased;
    }

    public function getLinksTitle()
    {
        if ($this->_purchased && $this->_purchased->getLinkSectionTitle()) {
            return $this->_purchased->getLinkSectionTitle();
        }
        return Mage::getStoreConfig(Mage_Downloadable_Model_Link::XML_PATH_LINKS_TITLE);
    }

    /* I want to insert this method */
    public function getLinksHref()
    {
        return 'http://google.com/'
    }
}

But. I don't want to edit the original file but I want to override this Block Class. And actually the question is how to Override this block?

My Module's config.xml

<?xml version="1.0"?> <config>
    <modules>
        <AD_DownloadablesGeneratedLink>
            <version>1.0.0</version>
        </AD_DownloadablesGeneratedLink>
    </modules>
    <global>
        <blocks>
            <adminhtml>
                <rewrite>
                    <order_items>AD_DownloadablesGeneratedLink_Block_Adminhtml_Sales_Items_Column_Downloadable_Name</order_items>
                </rewrite>
            </adminhtml>
            <AD_DownloadablesGeneratedLink>
                <class>AD_DownloadablesGeneratedLink_Block</class>
            </AD_DownloadablesGeneratedLink>
        </blocks>
     </global>

Thank you so much for you help in advance!

P.S. v1.4.0.1

1

Please try this

if you are trying to extend this block, Mage_Downloadable_Block_Adminhtml_Sales_Items_Column_Downloadable_Name

<global>
        <blocks>
            <downloadable>
                <rewrite>
                    <adminhtml_sales_items_column_downloadable_name>AD_DownloadablesGeneratedLink_Block_Adminhtml_Sales_Items_Column_Downloadable_Name</adminhtml_sales_items_column_downloadable_name>
                </rewrite>
            </downloadable>           
        </blocks>
     </global>

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.