4

I need to display points earned by customer on Order Information page under customer account.

module.xml

<sales_order_view>
    <reference name="order_items">
        <action method="addItemRender" ifconfig="mymodule/general/active"><type>default</type>
            <block>sales/order_item_renderer_default</block>
            <template>namespace/mymodule/sales/order/items/renderer/default.phtml</template>
        </action>
    </reference>
</sales_order_view>

Copied file from core - sales/order/items/renderer/default.phtml to namespace/mymodule/sales/order/items/renderer/default.phtml and along with default code, I added mine

<!--show points earned on each product-->
<?php $finalPointsEarned = ($_item->getCustomerProductPoints() * $_item->getQtyOrdered()); ?>
<div class="product-cart-sku">
    <span style="color: #d4af37; font-weight: bold;"><?php echo $this->__('Points Earned:'); ?>
        <?php echo $finalPointsEarned ?>
    </span>
</div>
<!--show points earned on each product-->

As shown in below image, this is how points earned are shown

Image

  1. Is this the correct approach/method to show custom data on Order Information page ?
  2. If not, how do I override Sales/Order/Item/Rendered/Default block to show the same without copying core file in my extension and then adding my code ?

Will it be same for below mentioned files too ?

sales/order/invoice/items/renderer/
sales/order/shipment/items/renderer/
sales/order/creditmemo/items/renderer/

Also, I am showing the same information in admin section by copying files in my extension

adminhtml\default\default\template\namespace\modulename\sales\order\total.phtml

P.S. The files belongs to community extension

EDIT AS PER CUSTOM BLOCK CREATION

config.xml

<global>
    <blocks>
        <productpoint>
            <class>Namespace_Modulename_Block</class>
        </productpoint>
        <sales>
            <rewrite>
                <order_item_renderer_default>Namespace_Modulename_Block_Sales_Order_Item_Renderer_Default</order_item_renderer_default>
            </rewrite>
        </sales>
    </blocks>
</global>

points.xml

<sales_order_invoice>
    <reference name="invoice_items">
        <block type="core/text_list" name="invoice.productpoints.info" translate="label">
            <label>Additional Points Info</label>
        </block>
    </reference>
</sales_order_invoice>

Sales/Order/Item/Renderer/Default.php

<?php

class Namespace_Modulename_Block_Sales_Order_Item_Renderer_Default extends Mage_Sales_Block_Order_Item_Renderer_Default
{
    public function getInvoiceProductPoints()
    {
        parent::getItem();
        $_item = $this->getItem();
        $finalPointsEarned = ($_item->getCustomerProductPoints() * $_item->getQty());
        return $finalPointsEarned;
    }
}

sales/order/items/renderer/default.phtml

<?php $addInfoBlock = $this->getInvoiceProductPoints(); ?>
<?php if ($addInfoBlock): ?>
    <?php echo $addInfoBlock ?>
<?php endif;?>

1 Answer 1

0

1.) Correct : Well, it largely depends upon the file/situation you are working in. But lot of core templates allow third party extensions to inject their code in a much decent manner, your condition happens to be one of those.

2.) Instead of copying over the entire core file, take a look at the template and layout files for the same. Inside template, you can see that there is a code block as <?php $addtInfoBlock = $this->getProductAdditionalInformationBlock(); ?>.

Now, if you search in corresponding block for the same, you'll see, it is calling the handle additional.product.info from layout, and in layout, it is core/text_list type of block. There you have it. You can simply reference your custom code aiming at this handle and Magento will pick up your information for the display and you won't need to copy over the entire template file to your extension.

Try this approach and see if you get a cleaner extension.

2
  • Prateek: Would be great if you could post some code snippet for Point #2 you mentioned considering block Mar 18, 2016 at 11:03
  • See CODE EDIT above. I still do not show core block being called. Do I need to put the core html file and then inject my block ? Mar 21, 2016 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.