1

I am developing a custom subscription module for one of my projects. A customer can have multiple subscriptions for multiple products. The data is stored in a custom database table. In the my accounts section I have added a link in the menu as follows:

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="beyondroid_subscribepro"><name>subscriptions</name><path>subscriptions</path><label>My Subscriptions</label></action>         </reference>
</customer_account>
<subscriptions_index_index translate="label">
    <update handle="customer_account" />
    <reference name="my.account.wrapper">
        <block type="beyondroid_subscribepro/mysubscriptions" name="mysubscriptions" as="mysubscriptions" template="subscribepro/mysubscriptions.phtml" before="content" />
    </reference>
</subscriptions_index_index>

The link redirects to a custom block, where I list each of the subscription object for that customer. Each subscription item has a balance_amount field that shows how much amount for that subscription is left in the customers account.

Now what I am trying to achieve is to show the total of each subscriptions balance amount in the link label in the customer account navigation menu.

If you look at the code above you can see currently the label shows My Subscriptions. So if a customer has 3 subscriptions with $15 balance in each subscription item, I would like to show My Subscriptions (Balance : $45) in the link label.

If I have a php function that adds up the subscription amounts, How can I include it in the above xml code to the <label></label> tag ? Is this even possible at all ?

1
  • Anyone ? How can I do this ? Is there even possible at all ?
    – Amyth
    Commented Nov 28, 2015 at 3:52

1 Answer 1

1

First you have to override customer_account_navigation block and add new method:

class [Namespace]_[ModuleName]_Block_AddSubscriptionLink 
    extends Mage_Customer_Block_Account_Navigation 
{
    public function addSubscriptionsLink() {
        $label = ''; // get label with balance here
        $this->addLink(
            $label,
            "[url]",
            "[title]"
        );
    }
}

Ad it in module config.xml file:

<config>
    <global>
        <blocks>
            <[namespace]_[moduleName]>
                <rewrite>
                    <account_navigation>[Namespace]_[ModuleName]_Block_AddSubscriptionLink</account_navigation>
                </rewrite>
            </[namespace]_[moduleName]>
        </blocks>
    </global>
</config>

And finally add link in layout:

<layout>
    <customer_account>
        <reference name="customer_account_navigation">
            <action method="addSubscriptionsLink" />
        </reference>
    </customer_account>
</layout>

Edit: You could also use core block and helper method (I think that it will be better solution):

<customer_account>
    <reference name="customer_account_navigation">
        <action method="addLink" translate="label" module="beyondroid_subscribepro">
            <label helper="beyondroid_subscribepro/getSubscriptionsLabel" />
            <path>subscriptions</path>
            <name>subscriptions</name>
        </action>         
    </reference>
</customer_account>

Ad helper in module config.xml file:

<config>
    <global>
        <helpers>
            <beyondroid_subscribepro>
                <class>Beyondroid_Subscribepro_Helper</class>
            </beyondroid_subscribepro>
        </blocks>
    </global>
</config>

And create helper class:

class Beyondroid_Subscribepro_Helper
    extends Mage_Core_Helper_Abstract
{
    public function getSubscriptionsLabel() {
        $label = ''; // get label with balance here
        return $label;
    }
}
2

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.