Пример #1
0
 /**
  * Generate secret key for controller and action based on form key
  *
  * @param string $routeName
  * @param string $controller Controller name
  * @param string $action Action name
  * @return string
  */
 public function getSecretKey($routeName = null, $controller = null, $action = null)
 {
     $salt = $this->_coreSession->getFormKey();
     $request = $this->getRequest();
     if (!$routeName) {
         if ($request->getBeforeForwardInfo('route_name') !== null) {
             $routeName = $request->getBeforeForwardInfo('route_name');
         } else {
             $routeName = $request->getRouteName();
         }
     }
     if (!$controller) {
         if ($request->getBeforeForwardInfo('controller_name') !== null) {
             $controller = $request->getBeforeForwardInfo('controller_name');
         } else {
             $controller = $request->getControllerName();
         }
     }
     if (!$action) {
         if ($request->getBeforeForwardInfo('action_name') !== null) {
             $action = $request->getBeforeForwardInfo('action_name');
         } else {
             $action = $request->getActionName();
         }
     }
     $secret = $routeName . $controller . $action . $salt;
     return $this->_coreHelper->getHash($secret);
 }
Пример #2
0
 /**
  * Retrieve Session Form Key
  *
  * @return string A 16 bit unique key for forms
  */
 public function getFormKey()
 {
     if (Mage::registry('replace_form_key') && !Mage::app()->getRequest()->getParam('form_key', false)) {
         // flag request for ESI processing
         Mage::register('turpentine_esi_flag', true, true);
         return '{{form_key_esi_placeholder}}';
     } else {
         return parent::getFormKey();
     }
 }
Пример #3
0
 /**
  * Save block content to cache storage
  *
  * @param string $data
  * @return Mage_Core_Block_Abstract
  */
 protected function _saveCache($data)
 {
     if (is_null($this->getCacheLifetime()) || !$this->_cache->canUse(self::CACHE_GROUP)) {
         return false;
     }
     $cacheKey = $this->getCacheKey();
     $data = str_replace($this->_session->getSessionIdQueryParam() . '=' . $this->_session->getEncryptedSessionId(), $this->_getSidPlaceholder($cacheKey), $data);
     $this->_cache->save($data, $cacheKey, $this->getCacheTags(), $this->getCacheLifetime());
     return $this;
 }
Пример #4
0
 public function setUp()
 {
     $this->_menuMock = $this->getMock('Mage_Backend_Model_Menu', array(), array(), '', false);
     $this->_coreSessionMock = $this->getMock('Mage_Core_Model_Session', array('getFormKey'), array(), '', false);
     $this->_coreSessionMock->expects($this->any())->method('getFormKey')->will($this->returnValue('salt'));
     $this->_coreHelperMock = $this->getMock('Mage_Core_Helper_Data', array('getHash'), array(), '', false);
     $this->_coreHelperMock->expects($this->any())->method('getHash')->will($this->returnArgument(0));
     $mockItem = $this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false);
     $mockItem->expects($this->any())->method('isDisabled')->will($this->returnValue(false));
     $mockItem->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $mockItem->expects($this->any())->method('getId')->will($this->returnValue('Mage_Adminhtml::system_acl_roles'));
     $mockItem->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/user_role'));
     $this->_menuMock->expects($this->any())->method('get')->with($this->equalTo('Mage_Adminhtml::system_acl_roles'))->will($this->returnValue($mockItem));
     $helperMock = $this->getMock('Mage_Backend_Helper_Data', array(), array(), '', false);
     $helperMock->expects($this->any())->method('getAreaFrontName')->will($this->returnValue($this->_areaFrontName));
     $this->_routes = array('admin' => 'adminhtml', 'adminhtml' => '');
     $this->_model = new Mage_Backend_Model_Url(array('startupMenuItemId' => 'Mage_Adminhtml::system_acl_roles', 'menu' => $this->_menuMock, 'backendHelper' => $helperMock, 'coreSession' => $this->_coreSessionMock, 'coreHelper' => $this->_coreHelperMock, 'routes' => $this->_routes));
     $this->_requestMock = $this->getMock('Mage_Core_Controller_Request_Http', array(), array(), '', false);
     $this->_model->setRequest($this->_requestMock);
 }
Пример #5
0
 public function addMessage(Mage_Core_Model_Message_Abstract $message)
 {
     // ensure duplicate messages are not added
     $identifier = md5($message->getType() . '-' . $message->getText() . '-' . $message->getCode() . '-' . $message->getIdentifier() . '-' . (int) $message->getIsSticky());
     $messages = $this->getMessages()->getItems();
     foreach ($messages as $m) {
         $identifier2 = md5($m->getType() . '-' . $m->getText() . '-' . $m->getCode() . '-' . $m->getIdentifier() . '-' . (int) $m->getIsSticky());
         if ($identifier == $identifier2) {
             return $this;
         }
     }
     return parent::addMessage($message);
 }
Пример #6
0
 /**
  * Saving visitor information by request
  *
  * Used in event "controller_action_postdispatch"
  *
  * @param   Varien_Event_Observer $observer
  * @return  Mage_Log_Model_Visitor
  */
 public function saveByRequest($observer)
 {
     if ($this->_skipRequestLogging || $this->isModuleIgnored($observer)) {
         return $this;
     }
     try {
         $this->setLastVisitAt(now());
         $this->save();
         $this->_session->setVisitorData($this->getData());
     } catch (Exception $e) {
         Mage::logException($e);
     }
     return $this;
 }
Пример #7
0
 public function setUp()
 {
     $this->_menuMock = $this->getMock('Mage_Backend_Model_Menu', array(), array(), '', false);
     $this->_menuConfigMock = $this->getMock('Mage_Backend_Model_Menu_Config', array(), array(), '', false);
     $this->_menuConfigMock->expects($this->any())->method('getMenu')->will($this->returnValue($this->_menuMock));
     $this->_coreSessionMock = $this->getMock('Mage_Core_Model_Session', array('getFormKey'), array(), '', false);
     $this->_coreSessionMock->expects($this->any())->method('getFormKey')->will($this->returnValue('salt'));
     $this->_coreHelperMock = $this->getMock('Mage_Core_Helper_Data', array('getHash'), array(), '', false);
     $this->_coreHelperMock->expects($this->any())->method('getHash')->will($this->returnArgument(0));
     $mockItem = $this->getMock('Mage_Backend_Model_Menu_Item', array(), array(), '', false);
     $mockItem->expects($this->any())->method('isDisabled')->will($this->returnValue(false));
     $mockItem->expects($this->any())->method('isAllowed')->will($this->returnValue(true));
     $mockItem->expects($this->any())->method('getId')->will($this->returnValue('Mage_Adminhtml::system_acl_roles'));
     $mockItem->expects($this->any())->method('getAction')->will($this->returnValue('adminhtml/user_role'));
     $this->_menuMock->expects($this->any())->method('get')->with($this->equalTo('Mage_Adminhtml::system_acl_roles'))->will($this->returnValue($mockItem));
     $helperMock = $this->getMock('Mage_Backend_Helper_Data', array(), array(), '', false);
     $helperMock->expects($this->any())->method('getAreaFrontName')->will($this->returnValue($this->_areaFrontName));
     $this->_storeConfigMock = $this->getMock('Mage_Core_Model_Store_Config', array(), array(), '', false);
     $this->_storeConfigMock->expects($this->any())->method('getConfig')->with(Mage_Backend_Model_Url::XML_PATH_STARTUP_MENU_ITEM)->will($this->returnValue('Mage_Adminhtml::system_acl_roles'));
     $this->_model = new Mage_Backend_Model_Url($helperMock, $this->_coreHelperMock, $this->_coreSessionMock, $this->_storeConfigMock, $this->_menuConfigMock);
     $this->_requestMock = $this->getMock('Mage_Core_Controller_Request_Http', array(), array(), '', false);
     $this->_model->setRequest($this->_requestMock);
 }
 /**
  * After an order has been placed, surrounding Magento system should be
  * made aware of the new order - session data should be updated and an
  * event should be dispatched.
  */
 public function testSignalOrderSuccess()
 {
     // Setup quote and orders with relevant data.
     $orderId = 1;
     $incrementId = '005012345';
     $quoteId = 3;
     $this->_order->method('getId')->will($this->returnValue($orderId));
     $this->_order->method('getIncrementId')->will($this->returnValue($incrementId));
     $this->_quote->method('getId')->will($this->returnValue($quoteId));
     // Side-effect tests: ensure session data is updated with quote and
     // order data.
     $this->_coreSession->expects($this->once())->method('setOrderIds')->with($this->identicalTo([$orderId => $incrementId]))->will($this->returnSelf());
     $this->_checkoutSession->expects($this->once())->method('setLastQuoteId')->with($this->identicalTo($quoteId))->will($this->returnSelf());
     $this->assertSame($this->_multishippingCheckout, EcomDev_Utils_Reflection::invokeRestrictedMethod($this->_multishippingCheckout, '_signalOrderSuccess', [$this->_order]));
     // Ensure the event was dispatched once for the new order.
     $this->assertEventDispatchedExactly('checkout_submit_all_after', 1);
 }
Пример #9
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;
 }
 /**
  * Redirect and notify the customer of an order could not be canceled.
  *
  * @param  Exception
  * @param  Mage_Core_Model_Session
  * @param  string
  * @return self
  */
 protected function _handleRomCancelException(Exception $e, Mage_Core_Model_Session $session, $redirectUrl)
 {
     $session->addError($this->_orderHelper->__($e->getMessage()));
     $this->_redirectUrl($redirectUrl);
     return $this;
 }
 /**
  * Get banners content by specified banners IDs depend on Rotation mode
  *
  * @param array $bannerIds
  * @param array $segmentIds
  * @return array
  */
 protected function _getBannersContent($bannerIds, $segmentIds = array())
 {
     $this->_setRenderedParam('bannerIds', $bannerIds)->_setRenderedParam('renderedBannerIds', array());
     $content = array();
     if (!empty($bannerIds)) {
         $bannerResource = $this->_bannerResource;
         // Process suggested params
         $suggestedParams = $this->getSuggestedParams();
         $suggBannersSelected = $suggestedParams['bannersSelected'];
         $suggBannersSequence = $suggestedParams['bannersSequence'];
         // Choose banner depending on rotation mode
         switch ($this->getRotate()) {
             case self::BANNER_WIDGET_RORATE_RANDOM:
                 // Choose banner either as suggested or randomly
                 $bannerId = null;
                 if ($suggBannersSelected && count($suggBannersSelected) == 1) {
                     $suggBannerId = $suggBannersSelected[0];
                     if (array_search($suggBannerId, $bannerIds) !== false) {
                         $bannerId = $suggBannerId;
                     }
                 }
                 if ($bannerId === null) {
                     $bannerId = $bannerIds[array_rand($bannerIds, 1)];
                 }
                 $_content = $bannerResource->getStoreContent($bannerId, $this->_currentStoreId, $segmentIds);
                 if (!empty($_content)) {
                     $content[$bannerId] = $_content;
                 }
                 $this->_setRenderedParam('renderedBannerIds', array($bannerId));
                 break;
             case self::BANNER_WIDGET_RORATE_SHUFFLE:
             case self::BANNER_WIDGET_RORATE_SERIES:
                 $isShuffle = $this->getRotate() == self::BANNER_WIDGET_RORATE_SHUFFLE;
                 $bannerId = null;
                 $bannersSequence = null;
                 // Compose banner sequence either from suggested sequence or from user session data
                 if ($suggBannersSequence !== null) {
                     // Check that suggested sequence is valid - contains only banner ids from list
                     if (!array_diff($suggBannersSequence, $bannerIds)) {
                         $bannersSequence = $suggBannersSequence;
                     }
                 }
                 if ($bannersSequence === null) {
                     $bannersSequence = $this->_sessionInstance->_getData($this->getUniqueId());
                 }
                 // Check that we have suggested banner to render
                 $suggBannerId = null;
                 if ($suggBannersSelected && count($suggBannersSelected) == 1) {
                     $suggBannerId = $suggBannersSelected[0];
                 }
                 // If some banners were shown, get the list of unshown ones and choose banner to show
                 if ($bannersSequence) {
                     $canShowIds = array_merge(array_diff($bannerIds, $bannersSequence), array());
                     if (!empty($canShowIds)) {
                         // Stil not whole serie is shown, choose the banner to show
                         if ($suggBannerId && array_search($suggBannerId, $canShowIds) !== false) {
                             $bannerId = $suggBannerId;
                         } else {
                             $canShowKeys = array_keys($canShowIds);
                             $showKey = $isShuffle ? array_rand($canShowIds, 1) : $canShowKeys[0];
                             $bannerId = $canShowIds[$showKey];
                         }
                         $bannersSequence[] = $bannerId;
                     }
                 }
                 // Start new serie (either no banners has been shown at all or whole serie has been shown)
                 if (!$bannerId) {
                     if ($suggBannerId && array_search($suggBannerId, $bannerIds) !== false) {
                         $bannerId = $suggBannerId;
                     } else {
                         $bannerKeys = array_keys($bannerIds);
                         $bannerKey = $isShuffle ? array_rand($bannerIds, 1) : $bannerKeys[0];
                         $bannerId = $bannerIds[$bannerKey];
                     }
                     $bannersSequence = array($bannerId);
                 }
                 $this->_sessionInstance->setData($this->getUniqueId(), $bannersSequence);
                 $_content = $bannerResource->getStoreContent($bannerId, $this->_currentStoreId, $segmentIds);
                 if (!empty($_content)) {
                     $content[$bannerId] = $_content;
                 }
                 $this->_setRenderedParam('renderedBannerIds', array($bannerId))->_setRenderedParam('bannersSequence', $bannersSequence);
                 break;
             default:
                 // We must always render all available banners - so suggested values are ignored
                 $content = $bannerResource->getBannersContent($bannerIds, $this->_currentStoreId, $segmentIds);
                 $this->_setRenderedParam('renderedBannerIds', $bannerIds);
                 break;
         }
     }
     $this->_prepareCacheTags();
     return $content;
 }
Пример #12
0
 /**
  * Retrive add to cart url
  *
  * @param Mage_Catalog_Model_Product $product
  * @return string
  */
 public function getAddToCartUrl($product)
 {
     $beforeCompareUrl = $this->_catalogSession->getBeforeCompareUrl();
     $params = array('product' => $product->getId(), Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl($beforeCompareUrl), Mage_Core_Model_Url::FORM_KEY => $this->_coreSession->getFormKey());
     return $this->_getUrl('checkout/cart/add', $params);
 }
 public function __construct($data = array())
 {
     parent::__construct($data);
     $this->init(HooshMarketing_Marketo_Model_Opportunity::SESSION_NAMESPACE);
 }