0

In an effort to learn how to work with Magento I have set myself a number of (what i believe will be) basic tasks. The aim being to give me an idea of how to access information of the customer, products etc and apply that to the dashboard, product page, payment page etc. I give this intro as my request my seem a little over the top for a real store.

=====

AIM

=====

  • get logged in customers name (DONE)
  • make sure the first name and last name are in capitals (DONE)

apply it to

  • Welcome, "logged in customer" (in the header)
  • MY ACCOUNT (left side bar)
  • My Dashboard (content area heading)
  • Hello "logged in customer" (content area above account information)
  • ACCOUNT INFORMATION (content area)

so the above locations, say:

  • "logged in customers" Account
  • "logged in customers" Dashboard
  • "logged in customer" has registered with main store
  • "logged in customers" Information
  • Contact information for "logged in customer"

Do I need to create a module containing a helper or observer or even override the core module (I have learnt enough to know I do not edit the core directly). I would also like to understand the reason why I would do one or another.

I appreciate that most of what i am trying to do is completed by adding a bit of code to the relevant template, what I am trying to do is work out the best way to do it

=======================

SUMMARY OF QUESTIONS

=======================

  • to add new data into a .phtml file should I copy that data and place it in my own file which I then customise or is there a better way?

  • to change the users first and last name to uppercase, should I override Mage_Page_Block_Html_Header or create a module that contains a helper or an observer to set the users name to uppercase first

1 Answer 1

1

If some text needs to be upper-cased then that counts as presentation and shouldn't be handled in PHP. Leave it to CSS and text-transform. That way the same data can be presented differently by different themes, in case a site has multiple stores. Sometimes the art of programming is knowing when not to program. :-)


For the "MY ACCOUNT" on the left nav bar for customers you can see it is generated in the file app/design/frontend/base/default/template/customer/account/navigation.phtml. When you need to find a file like that use template path hints. Copy the file to an equivalent location in your own theme to override it. Where you see this:

<?php echo $this->__('My Account'); ?>

You can amend it to this:

<?php echo $this->__('%s\'s Dashboard', Mage::helper('customer')->getCustomerName()); ?>

Here I used the sprintf() syntax to embed the customer's name. This way is useful because it allows you to make finer adjustments through Magento's translation later, if required. Inline translation is another way of making changes without programming, treasure it.


The "My Dashboard" heading is in the file app/design/frontend/base/default/template/customer/account/dashboard.phtml. Edit it in the same way changing:

$this->__('My Dashboard')

to:

$this->__('%s has registered with main store', Mage::helper('customer')->getCustomerName())

Whilst you have the dashboard file open also change:

$this->__('Account Information')

to:

$this->__('Contact information for %s', Mage::helper('customer')->getCustomerName())

The "Hello, customer!" message is generated in the template file, customer/account/dashboard/hello.phtml but this time you do not need to touch it at all. Use translation again. Change "Hello, %s!" to "%s's information".


I hope as part of your self-education you realise the best way to make changes is with a light touch and by doing as little as possible. If you need further convincing read The Pragmatic Programmer.

2
  • Sometimes the art of programming is knowing when not to program. :-) I really need to remember that!!! My sledge hammer for a walnut technique needs to be reigned in immediately!
    – tony09uk
    Commented Oct 7, 2013 at 8:39
  • I need to rephrase that as a haiku or something... Commented Oct 7, 2013 at 9:28

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.