Skip to content

Commit 6781606

Browse files
committed
1 parent b1eee2d commit 6781606

File tree

4 files changed

+168
-0
lines changed

4 files changed

+168
-0
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
class Dev_Productreview_Controller_Router extends Mage_Core_Controller_Varien_Router_Abstract{
3+
/**
4+
* Initialize Controller Router
5+
*
6+
* @param Varien_Event_Observer $observer
7+
*/
8+
9+
public function initControllerRouters($observer){
10+
$front=$observer->getEvent()->getFront();
11+
$front->addRouter('productreview',$this);
12+
13+
}
14+
15+
16+
/* validate and modify the request
17+
* Params Zend_Controller_Request_Htt
18+
*/
19+
public function match(Zend_Controller_Request_Http $request){
20+
21+
/* If Magento Magento is not install then
22+
* redirect to installer url
23+
*/
24+
If(!Mage::isInstalled()):
25+
Mage::app()->getFrontController()->getResponse()
26+
->setRedirect(Mage::getUrl('install'))
27+
->sendResponse();
28+
exit;
29+
30+
endif;
31+
$requestPathInfo=trim($request->getPathInfo(),'/');
32+
Mage::log('aaa'.$requestPathInfo.'StoreId'.Mage::app()->getStore()->getId(), null, 'logfile.log');
33+
/* check -review-form not exit
34+
* then immediate return false
35+
*/
36+
if(strpos($requestPathInfo,'-review-form')==false):
37+
return false;
38+
endif;
39+
40+
/* get productut from url
41+
by substr
42+
*/
43+
$producturl=str_replace('-review-form','',$requestPathInfo);
44+
45+
$condition=new Varien_Object(array('product_url'=>$producturl,
46+
'continue'=>true));
47+
48+
Mage::dispatchEvent('productreview_controller_router_match_before', array(
49+
'router' => $this,
50+
'condition' => $condition
51+
));
52+
53+
$identifier=$condition->getProductUrl();
54+
55+
if($condition->getRedirectUrl()){
56+
Mage::app()->getResponse()
57+
->setRedirect($condition->getReDirectUrl())
58+
->sendResponse();
59+
$request->setDispatched(true);
60+
return true;
61+
}
62+
63+
if(!$condition->getContinue()){
64+
return false;
65+
}
66+
/* now load product by url
67+
*
68+
*/
69+
$Rewrite=Mage::getModel('core/url_rewrite')
70+
->setStoreId(Mage::app()->getStore()->getId())
71+
->loadByRequestPath($identifier);
72+
73+
if(!$Rewrite->getId()):
74+
return false;
75+
endif;
76+
// if product id is null then return false
77+
78+
if(!$Rewrite->getProductId()):
79+
return false;
80+
endif;
81+
82+
83+
$request->setModuleName('review')
84+
->setControllerName('product')
85+
->setActionName('list')
86+
->setParam('id', $Rewrite->getProductId());
87+
$request->setAlias(
88+
Mage_Core_Model_Url_Rewrite::REWRITE_REQUEST_PATH_ALIAS,
89+
$identifier
90+
);
91+
92+
93+
return true;
94+
95+
}
96+
97+
98+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
class Dev_Productreview_Model_Observer{
3+
4+
public function add($observer){
5+
6+
$identifier=$observer->getEvent()->getCondition();
7+
Mage::log('aaa', null, 'logfile.log');
8+
9+
}
10+
11+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<cofig>
3+
<modules>
4+
<Dev_Productreview>
5+
<version>1.0.0</version>
6+
</Dev_Productreview>
7+
</modules>
8+
<!-- define route -->
9+
<frontend>
10+
<routers>
11+
<productview> <!-- router identifire -->
12+
<use>standard</use>
13+
<args>
14+
<modules>
15+
<module>Dev_Productreview</module>
16+
<frontName>productreview</frontName>
17+
</modules>
18+
</args>
19+
</productview>
20+
</routers>
21+
</frontend>
22+
<!-- model declare -->
23+
<global>
24+
<models>
25+
<productreview>
26+
<class>Dev_Productreview_Model</class>
27+
</productreview>
28+
</models>
29+
<!-- event for add a router -->
30+
<events>
31+
<controller_front_init_routers>
32+
<observers>
33+
<add_review_route> <!-- observer identifier -->
34+
<class>Dev_Productreview_Controller_Router</class>
35+
<method>initControllerRouters</method>
36+
</add_review_route>
37+
</observers>
38+
</controller_front_init_routers>
39+
<productreview_controller_router_match_before>
40+
<observers>
41+
<productreview_controller_router_match_before_a>
42+
<class>productreview/observer</class>
43+
<method>add</method>
44+
</productreview_controller_router_match_before_a>
45+
</observers>
46+
</productreview_controller_router_match_before>
47+
</events>
48+
</global>
49+
</cofig>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<config>
3+
<modules>
4+
<Dev_Productreview>
5+
<codePool>local</codePool>
6+
<active>true</active>
7+
<depends>Mage_Review</depends>
8+
</Dev_Productreview>
9+
</modules>
10+
</config>

0 commit comments

Comments
 (0)