示例#1
0
 public static function getFirstAvailable()
 {
     $menus = AW_Collpur_Model_Source_Menus::getMenusArray(true);
     foreach ($menus as $menu) {
         if ($menu['skip'] == 0 && $menu['size']) {
             return $menu['key'];
         }
     }
     return false;
 }
示例#2
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();
 }
 private function _prepareIsAllowedConfig()
 {
     $config = AW_Collpur_Model_Source_Menus::getMenusArray(false);
     foreach ($config as $menu) {
         if ($menu['key'] == AW_Collpur_Helper_Deals::RUNNING || $menu['key'] == AW_Collpur_Helper_Deals::NOT_RUNNING) {
             Mage::app()->getStore(0)->setConfig("collpur/{$menu['alias']}/enabled", 0);
         }
     }
 }
 public function isAllowed()
 {
     $config = AW_Collpur_Model_Source_Menus::getMenusArray(false);
     foreach ($config as $element) {
         $validator = $element['validator'];
         if (!Mage::getStoreConfig("collpur/{$element['alias']}/enabled") && $this->{$validator}()) {
             return false;
         }
     }
     return true;
 }
 public function _modifyCrumbs($layout, $bridge = false, $deal = false, $mode = 'product')
 {
     $sections = AW_Collpur_Helper_Deals::getSectionsAssoc();
     if ($mode == 'category') {
         $currentSection = Mage::app()->getRequest()->getParam('section');
         $layout->getBlock('breadcrumbs')->addCrumb('home', array('label' => 'Home', 'title' => 'Home', 'link' => Mage::getBaseUrl()));
         if (array_key_exists($currentSection, $sections)) {
             $layout->getBlock('breadcrumbs')->addCrumb('category', array('label' => $this->__($sections[$currentSection]), 'title' => $this->__($sections[$currentSection])));
             $layout->getBlock('head')->setTitle($this->__($sections[$currentSection]));
         }
         return;
     }
     $deal = $this->getDealInstance($deal->getId());
     if (!$deal->getId()) {
         return;
     }
     $disallowActive = false;
     if ($deal->isNotRunning()) {
         $categoryCrumb = AW_Collpur_Helper_Deals::NOT_RUNNING;
         $categoryLabel = $this->__($sections[AW_Collpur_Helper_Deals::NOT_RUNNING]);
     } else {
         if ($deal->isRunning()) {
             $categoryCrumb = AW_Collpur_Helper_Deals::RUNNING;
             $categoryLabel = $this->__($sections[AW_Collpur_Helper_Deals::RUNNING]);
             $data = AW_Collpur_Model_Source_Menus::getMenusArray(false);
             foreach ($data as $info) {
                 if ($info['key'] == AW_Collpur_Helper_Deals::RUNNING) {
                     if (!Mage::getStoreConfig("collpur/{$info['alias']}/enabled")) {
                         $disallowActive = true;
                         break;
                     }
                     $disallowActive = false;
                     break;
                 }
                 $disallowActive = false;
             }
         } else {
             if ($deal->isClosed()) {
                 $categoryCrumb = AW_Collpur_Helper_Deals::CLOSED;
                 $categoryLabel = $this->__($sections[AW_Collpur_Helper_Deals::CLOSED]);
             }
         }
     }
     $layout->getBlock('breadcrumbs')->addCrumb('home', array('label' => 'Home', 'title' => 'Home', 'link' => Mage::getBaseUrl()));
     if (!$disallowActive) {
         $layout->getBlock('breadcrumbs')->addCrumb('category', array('label' => $categoryLabel, 'title' => $categoryLabel, 'link' => $this->getDealTabUrl($categoryCrumb)));
     }
     $layout->getBlock('breadcrumbs')->addCrumb('product', array('label' => $this->processDealName($deal)));
 }