0

I want to change the data that is processed in the checkout_onepage_saveBilling controller action.

I am using an observer with the predispatch event to catch the POST data which is coming from the address form in the checkout and manipulate the values.

How can I transfer this data to the controller action now?

This is my observer:

public function validateAddress($observer)
{

    $controller = $observer->getControllerAction();
    $action = $controller->getFullActionName();

    if ($action == "checkout_onepage_saveBilling") {
        $post = Mage::app()->getRequest()->getPost();
        $post[billing][postcode] = trim($post[billing][postcode]);
        $post[billing][city] = trim($post[billing][city]);
    }

}
3
  • U need to use a plugin beforeExecute in this action Jan 27, 2020 at 14:27
  • So I cannot use the predispatch event for that? How would I do that?
    – Chaz
    Jan 27, 2020 at 14:32
  • Sorry for that in this case you can't use the plugin in Magento 1 you must override the controller. Jan 27, 2020 at 14:39

1 Answer 1

0

Solved it like this now, using the setPost method of the request:

public function validateAddress($observer)
    {
        /** @var Mage_Core_Controller_Request_Http $request */
        $request = $observer->getControllerAction()->getRequest();
        if (!$request->isPost() || !$request->isAjax()) {
            return;
        }

        $action = $request->getActionName();
        if ($action == "saveBilling") {
            $this->_fixAddress($request, "billing");
        } elseif ($action == "saveShipping") {
            $this->_fixAddress($request, "shipping");
        }
    }

    /**
     * @param Mage_Core_Controller_Request_Http $request
     * @param string                            $type
     */
    protected function _fixAddress($request, $type)
    {
        $address             = $request->getPost($type, array());
        $address["postcode"] = trim(htmlspecialchars($address["postcode"]));
        $address["city"]     = trim(htmlspecialchars($address["city"]));
        $request->setPost($type, $address);
    }

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.