示例#1
0
 private function _combineRequest($request)
 {
     $identifier = $request->getPathInfo();
     /*
      *  Immidiate return if
      *  It's not a deal module      
      */
     if (!preg_match("#(^/)*deals/#is", $identifier)) {
         return false;
     }
     if (!AW_Collpur_Model_Source_Menus::getFirstAvailable() && $identifier == '/deals/') {
         /* No deals available and we redirect to the empty page and only if user clicks deals link i.e goes to the route page
          * otherwise redirect to 404             
          */
         $request->setModuleName('deals')->setControllerName('index')->setActionName('empty');
         return true;
     }
     /* As a default start page assumed to be featured deal, but if it's unavailable,
      * there is no choice but redirect to the first available list section
      */
     if ($identifier == '/deals/' || preg_match("#/deals/" . AW_Collpur_Helper_Deals::FEATURED . "#is", $identifier)) {
         if (AW_Collpur_Model_Source_Menus::isNotAllowed(AW_Collpur_Helper_Deals::FEATURED) || !Mage::getModel('collpur/deal')->getRandomFeaturedId()) {
             $startPage = AW_Collpur_Model_Source_Menus::getFirstAvailable();
             $request->setModuleName('deals')->setControllerName('index')->setActionName('list')->setParam('section', $startPage);
             return true;
         }
         $request->setModuleName('deals')->setControllerName('index')->setActionName('view')->setParam('id', Mage::getModel('collpur/deal')->getRandomFeaturedId())->setParam('mode', AW_Collpur_Helper_Deals::FEATURED);
         return true;
     }
     /* Handle list category  mode */
     $key = preg_replace("#(/|deals/|\\..+)#is", "", $identifier);
     /* Clearing $key */
     if (in_array($key, AW_Collpur_Helper_Deals::getSectionsKeys())) {
         $request->setModuleName('deals')->setControllerName('index')->setActionName('list')->setParam('section', $key);
         return true;
     }
     /* Default handle for deal view */
     if ($dealId = $this->_rewriteResource->loadByKey($key, Mage::app()->getStore()->getId())) {
         $deal = Mage::getModel('collpur/deal')->load($dealId);
         if ($deal->isAllowed() && !$deal->isArchived() && $deal->getId()) {
             $request->setModuleName('deals')->setControllerName('index')->setActionName('view')->setParam('id', $dealId);
             return true;
         }
     }
 }
 public function listAction()
 {
     $section = (string) @strip_tags(Mage::app()->getRequest()->getParam('section'));
     if (AW_Collpur_Model_Source_Menus::isNotAllowed($section)) {
         $this->norouteAction();
         return;
     }
     if (!$section || $section == AW_Collpur_Helper_Deals::FEATURED) {
         $startPage = AW_Collpur_Model_Source_Menus::getFirstAvailable();
         if ($startPage == AW_Collpur_Helper_Deals::FEATURED) {
             $this->getResponse()->setRedirect(Mage::getUrl('deals/index/view', array('_secure' => Mage::app()->getStore(true)->isCurrentlySecure(), '_store' => Mage::app()->getStore()->getId(), 'id' => Mage::getModel('collpur/deal')->getRandomFeaturedId(), 'mode' => AW_Collpur_Helper_Deals::FEATURED)));
         } elseif ($startPage) {
             $this->getResponse()->setRedirect(Mage::getUrl('deals/index/list', array('_secure' => Mage::app()->getStore(true)->isCurrentlySecure(), '_store' => Mage::app()->getStore()->getId(), 'section' => $startPage)));
         }
     }
     $this->loadLayout();
     $this->_initLayoutMessages('catalog/session');
     $this->_initLayoutMessages('tag/session');
     $this->_initLayoutMessages('checkout/session');
     $layout = $this->getLayout();
     $layout->getBlock('content')->append($layout->createBlock('collpur/deals'));
     $this->renderLayout();
 }