0

I want add 2 lines code into but I want do this from my Extension How can I do this job ?

Don't want to add code to core file and then insert it into local folder

Is this possible add directly into my extension ?

I want add 2 lines below into

/code/core/Mage/Checkout/controllers/CartController.php

in the public function estimatePostAction()

under the $region = (string) $this->getRequest()->getParam('region');

Code is :

$cityDiff = $this->getRequest()->getParam('city');
Mage::getSingleton('core/session')->setEstimatedCity($cityDiff);
1

according to your requirement, if you expect you extension can work on further version I suggest you use Observer to listen Magento event then add data to core/session.

in your config.xml, define event listener. if you know the exactly event you want to listen, or listen all controller post dispatch.

<global>
<events>
    <controller_action_postdispatch>
        <observers>
            <controller_action_after>
                <class>YOUR_MODULE/observer</class>
                <method>listenControllerActionPostDispatch</method>
            </controller_action_after>
        </observers>
    </controller_action_postdispatch>

</events></global>

in your Model/Observer.php

class YOUDMOUDLE_Model_Observer {

public function listenControllerActionPostDispatch($observer)
{
    if($observer->getEvent()
        ->getControllerAction()->getFullActionName() == 'YOUR_TARGET')
    {
        $cityDiff = Mage::app()->getRequest()->getParam('city');
        Mage::getSingleton('core/session')->setEstimatedCity($cityDiff);
    }

}
  • 'YOUR_TARGET' is for example estimatePostAction ? that code will like ->getControllerAction()->getFullActionName() == 'estimatePostAction') or anything else ? – sIiiS Apr 9 '14 at 6:19
  • the fullActionName is following the route rule, for example cart page is checkout_cart_index, and your case might be checkout_cart_estimate_post – Tai Apr 9 '14 at 6:28
  • I have a file Observer in Model folder that use for another functions, added your code to it and code is public function listenControllerActionPostDispatch($observer) { if($observer->getEvent() ->getControllerAction()->getFullActionName() == 'checkout_cart_estimate_post') { $cityDiff = $this->getRequest()->getParam('city'); Mage::getSingleton('core/session')->setEstimatedCity($cityDiff); } } then added under my prev event in config.xml but nothing, seems your method is correct and I do wrong anything here! Is possible 2 observer function in one file ? – sIiiS Apr 9 '14 at 6:44
  • yes, you can have multiple method in one observer file. you can echo the actionName before go into your condition. make sure Event catch. – Tai Apr 9 '14 at 7:00
  • 1
    Finally work, thank you for your guide, but must use Mage::app() instead of $this in observer php file, also fullActionName is : checkout_cart_estimatePost – sIiiS Apr 9 '14 at 10:31
0

I'm no expert but think it would be something like this - anyway hopefully gets you on the right track:

Mage_Checkout_CartController_New extends Mage_Checkout_CartController { /** * Initialize shipping information */ public function estimatePostAction() { $country = (string) $this->getRequest()->getParam('country_id'); $postcode = (string) $this->getRequest()->getParam('estimate_postcode'); $city = (string) $this->getRequest()->getParam('estimate_city'); $regionId = (string) $this->getRequest()->getParam('region_id'); $region = (string) $this->getRequest()->getParam('region'); $cityDiff = $this->getRequest()->getParam('city'); Mage::getSingleton('core/session')->setEstimatedCity($cityDiff); $this->_getQuote()->getShippingAddress() ->setCountryId($country) ->setCity($city) ->setPostcode($postcode) ->setRegionId($regionId) ->setRegion($region) ->setCollectShippingRates(true); $this->_getQuote()->save(); $this->_goBack(); } }

Sometimes config XML also needs to be told about the new overriding class? http://www.magentocommerce.com/boards/viewthread/14103/

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.