/**
  * Get banner(s) content to display
  *
  * @return array
  */
 public function getBannersContent()
 {
     $aplliedRules = null;
     $segmentIds = array();
     $customer = Mage::registry('segment_customer');
     if (!$customer) {
         $customer = Mage::getSingleton('customer/session')->getCustomer();
     }
     $websiteId = Mage::app()->getWebsite()->getId();
     if (!$customer->getId()) {
         $allSegmentIds = Mage::getSingleton('customer/session')->getCustomerSegmentIds();
         if (is_array($allSegmentIds) && isset($allSegmentIds[$websiteId])) {
             $segmentIds = $allSegmentIds[$websiteId];
         }
     } else {
         $segmentIds = Mage::getSingleton('enterprise_customersegment/customer')->getCustomerSegmentIdsForWebsite($customer->getId(), $websiteId);
     }
     $this->_bannerResource->filterByTypes($this->getTypes());
     // Choose display mode
     switch ($this->getDisplayMode()) {
         case self::BANNER_WIDGET_DISPLAY_SALESRULE:
             if (Mage::getSingleton('checkout/session')->getQuoteId()) {
                 $quote = Mage::getSingleton('checkout/session')->getQuote();
                 $aplliedRules = explode(',', $quote->getAppliedRuleIds());
             }
             $bannerIds = $this->_bannerResource->getSalesRuleRelatedBannerIds($segmentIds, $aplliedRules, false);
             $bannerIds = array_intersect($bannerIds, $this->getEnabledBannerIds());
             $bannersContent = $this->_getBannersContent(!empty($bannerIds) ? $bannerIds : array(0), $segmentIds);
             break;
         case self::BANNER_WIDGET_DISPLAY_CATALOGRULE:
             $bannerIds = $this->_bannerResource->getCatalogRuleRelatedBannerIds(Mage::app()->getWebsite()->getId(), Mage::getSingleton('customer/session')->getCustomerGroupId(), $segmentIds, false);
             $bannerIds = array_intersect($bannerIds, $this->getEnabledBannerIds());
             $bannersContent = $this->_getBannersContent(!empty($bannerIds) ? $bannerIds : array(0), $segmentIds);
             break;
         case self::BANNER_WIDGET_DISPLAY_FIXED:
         default:
             $bannersContent = $this->_getBannersContent($this->getEnabledBannerIds(), $segmentIds);
             break;
     }
     // Unset types filter from resource
     $this->_bannerResource->filterByTypes();
     // Filtering directives
     /** @var $helper Mage_Cms_Helper_Data */
     $helper = Mage::helper('cms');
     $processor = $helper->getPageTemplateProcessor();
     foreach ($bannersContent as $bannerId => $content) {
         $bannersContent[$bannerId] = $processor->filter($content);
     }
     return $bannersContent;
 }
Example #2
0
 /**
  * Get banners content by specified banners IDs depend on Rotation mode
  *
  * @param array $bannerIds
  * @param array $segmentIds
  * @param int $storeId
  * @return array
  */
 protected function _getBannersContent($bannerIds, $segmentIds = array())
 {
     $bannersSequence = $content = array();
     if (!empty($bannerIds)) {
         //Choose rotation mode
         switch ($this->getRotate()) {
             case self::BANNER_WIDGET_RORATE_RANDOM:
                 $bannerId = $bannerIds[array_rand($bannerIds, 1)];
                 $_content = $this->_bannerResource->getStoreContent($bannerId, $this->_currentStoreId, $segmentIds);
                 if (!empty($_content)) {
                     $content[$bannerId] = $_content;
                 }
                 break;
             case self::BANNER_WIDGET_RORATE_SHUFFLE:
             case self::BANNER_WIDGET_RORATE_SERIES:
                 $bannerId = $bannerIds[0];
                 if (!$this->_sessionInstance->_getData($this->getUniqueId())) {
                     $this->_sessionInstance->setData($this->getUniqueId(), array($bannerIds[0]));
                 } else {
                     $bannersSequence = $this->_sessionInstance->_getData($this->getUniqueId());
                     $canShowIds = array_merge(array_diff($bannerIds, $bannersSequence), array());
                     if (!empty($canShowIds)) {
                         $showId = 0;
                         if ($this->getRotate() == self::BANNER_WIDGET_RORATE_SHUFFLE) {
                             $showId = array_rand($canShowIds, 1);
                         }
                         $bannersSequence[] = $canShowIds[$showId];
                         $bannerId = $canShowIds[$showId];
                     } else {
                         $bannersSequence = array($bannerIds[0]);
                     }
                     $this->_sessionInstance->setData($this->getUniqueId(), $bannersSequence);
                 }
                 $_content = $this->_bannerResource->getStoreContent($bannerId, $this->_currentStoreId, $segmentIds);
                 if (!empty($_content)) {
                     $content[$bannerId] = $_content;
                 }
                 break;
             default:
                 $content = $this->_bannerResource->getBannersContent($bannerIds, $this->_currentStoreId, $segmentIds);
                 break;
         }
     }
     return $content;
 }
 /**
  * Filter active banners
  *
  * @param array $bannerIds
  * @return array
  */
 protected function _filterActive($bannerIds)
 {
     return $this->_bannerResource->getExistingBannerIdsBySpecifiedIds($bannerIds);
 }