2

I want to filter the addresses in the checkout process. For that I have to overwrite the function getAddressesHtmlSelect() in app\code\core\Mage\Checkout\Block\Onepage\Abstract.php

One way would be: take the file Abstract.php out of core into local. But that is a very dirty way, and I am not sure if I could just take out one file or if I had to take the hole Checkout module into the local folder? (that as a small side question)

What I search is a clean and good way to do what I want to do.

Can you lead me in the right direction?

  • @Marius: with this method I will destroy the update possibility of this installation, right? Hoped for a better solution to filter the addresses. – nbar Nov 11 '13 at 14:39
  • It won't change the required steps for an update, assuming it was a concrete implementation you could rewrite, you'd still be modifying a function which may change, so you'd still need to check after an upgrade, that you haven't lost / broke anything (relying on a function that is removed for example). It's not ideal, but the only other option I can think of would be to rewrite the individual blocks that extend this abstract class. – Peter O'Callaghan Nov 11 '13 at 14:55
2

You have to copy the file in local folder. And, yes, copying just one file works. You need this because the Abstract class is not instantiated, and in Magento you can rewrite using config.xml only classes that are instantiated.
See more words about this here:

1

You can duplicate the single file over to the local folder. This will be the easiest way of achieving a modification to that function. As somebody who has recently made some modifications to this function I can tell you that there is quite a lot of work involved in doing this the 'correct' way due to the fact that there are quite a few (10 I think) classes that extend this abstract class. Whilst I don't believe the function getAddressesHtmlSelect is used by all of them, due to it's dependency on other functions within the class though, you could be jumping into a rabbit hole if you attempt to rewrite all the instances in which it might be used.

Unless you have a specific reason to do this the 'correct' way (distributed module for example). I'd be tempted to take one on the chin and just copy it to local.

1

It depends on what you want to do when you say filter. One option would be to change the addresses when they are loaded. I would suggest that you could rewrite the customer model and change the getAddresses function.

public function getAddresses()
{
    $this->_addresses = $this->getAddressesCollection()->getItems();
    return $this->_addresses;
}

Or maybe even better you could find an appropriate event to observe maybe the collection load after would be a good one for this. But you would have to be careful to only change the addresses when you are in the checkout process.

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.