1

I am using magento 1.9.1.0 in that i want to trap the event observer for product detail page .So for that we had created a custom observer and it is working properly for target_path url present in core_url_rewrite like (1.e catalog/product/view/id/1241641/category/352/store/2) but when i am using request path for the same (i.e /women/accessories/handbags/bag.html) then we are getting "The page you requested was not found".

My custom Module details are given below

Observer.php

class Gamer_CustomProduct_Model_Observer {

    public function getProductView(Varien_Event_Observer $observer) {

            echo "In getProductView";
            exit;

            }

} 

Config.xml

<config>
    <modules>
        <Gamer_CustomProduct>
            <version>0.1.0</version>
        </Gamer_CustomProduct>
    </modules>
    <global>
        <models>
            <customproduct>
                <class>Gamer_CustomProduct_Model</class>
            </customproduct>
        </models>
        <events>
            <catalog_controller_product_init_before> 
                <observers>
                    <catalog_controller_product_init_before_handler> 
                        <type>model</type> 
                        <class>customproduct/observer</class> <!-- observers class alias -->
                        <method>getProductView</method>  
                    </catalog_controller_product_init_before_handler>
                </observers>
            </catalog_controller_product_init_before>
        </events>

    </global>
</config>
12
  • what your problem "/women/accessories/handbags/bag.html 404 issue" or 'catalog_controller_product_init_before' not fire
    – Amit Bera
    Commented Jun 25, 2015 at 7:43
  • Hi Amit, when I type Target Path in browser address bar it works. However when I type request path I am unable to trap the event. We want to trap the event when 'request path' is entered in browser for a product.
    – RickyN73
    Commented Jun 25, 2015 at 7:46
  • k can you please tell me what will be happen whenever hit /women/accessories/handbags/bag.html on browser
    – Amit Bera
    Commented Jun 25, 2015 at 7:51
  • ideally it should navigate to product detail page. In this case it will show up details of the bag. However currently since I am not able to trap the event I am getting 404 not found page.
    – RickyN73
    Commented Jun 25, 2015 at 7:55
  • 2
    Can you explain what you are actually trying to do? I mean tell us why you need to capture a specific product page. There might be an easier way to do it than observing catalog_controller_product_init_before.
    – Marius
    Commented Jun 25, 2015 at 8:00

1 Answer 1

0

You should observe some generic event, such as controller_front_send_response_before and check if 404 page is going to be rendered. I show you an approach using a 301 redirect

public function yourFunction($observer){

    $resp = $observer->getEvent()->getFront()->getAction()->getRequest();
    if ($resp->getActionName() == 'noRoute'){

        $requestUri = $resp->getRequestString();
        // match this with your url rewrites table
        // maybe you should want to trim the / in $requestUri, print_r() it
        // if it is found then...
        header("Location: " . Mage::getBaseUrl() . $yourMatchedUrl, 301);
        exit;
    }

}
11
  • catalog_controller_product_view even for this event if we provide target_url_path then it is working but for request_url_path it is not working and we would be entering request url path in the address bar
    – RickyN73
    Commented Jun 25, 2015 at 10:25
  • mmm... In a clean installation you'd always see a Mage_Catalog_ProductController->viewAction() call if you debug in view.phtml template, independently of the url provided Commented Jun 25, 2015 at 10:43
  • I think your problem is your rewrite urls are not working, reading your comment: "The page you requested was not found". But that's not about your module or your observer, that's about your Magento configuration, indexes, etc... Commented Jun 25, 2015 at 10:45
  • i want to show this product details on Website A which doesn't consist of any product details in data base it consist of only core_url_rewrites from website B so i want to just use Request_path_url from core_url_rewrites and call my website A custom observer so that from there i can make a call to a api request to website b and fetch product details and display it on my custom view page of Website A
    – RickyN73
    Commented Jun 25, 2015 at 10:50
  • ok please update it
    – RickyN73
    Commented Jun 25, 2015 at 10:54

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.