public function indexAction()
 {
     if (Praxigento_LoginAs_Config::cfgGeneralEnabled()) {
         /** define operator name */
         /** @var $session Mage_Admin_Model_Session */
         $session = Mage::getSingleton('admin/session');
         if ($session->isLoggedIn()) {
             /** @var $user Mage_Admin_Model_User */
             $user = $session->getUser();
             $operator = $user->getName() . ' (' . $user->getEmail() . ')';
             /** if there is customer data in request */
             if (!is_null($this->getRequest()->getParams())) {
                 $params = $this->getRequest()->getParams();
                 if (!is_null($params[Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID])) {
                     /** extract customer ID from request and load customer data */
                     $customerId = $params[Praxigento_LoginAs_Config::REQ_PARAM_LAS_ID];
                     /** @var $customer Mage_Customer_Model_Customer */
                     $customer = Mage::getModel('customer/customer')->load($customerId);
                     if ($customer->getId() == $customerId) {
                         $customerName = $customer->getName();
                         /** define URL to login to customer's website */
                         $wsId = $customer->getData('website_id');
                         if (is_null($wsId)) {
                             $wsId = Mage::app()->getStore()->getWebsiteId();
                         }
                         /** @var $website Mage_Core_Model_Website */
                         $website = Mage::getModel('core/website')->load($wsId);
                         $defStoreId = $website->getDefaultStore()->getId();
                         $baseTarget = Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL, $defStoreId);
                         $baseSource = Mage::getStoreConfig(Mage_Core_Model_Url::XML_PATH_SECURE_URL);
                         /** compose redirection URL and replace current base by target base */
                         $urlModel = Mage::getModel('core/url');
                         $store = Mage::getModel('core/store')->load($defStoreId);
                         $urlModel->setStore($store);
                         $url = $urlModel->getUrl(Praxigento_LoginAs_Config::XMLCFG_ROUTER_FRONT . Praxigento_LoginAs_Config::ROUTE_CUSTOMER_LOGINAS);
                         $url = str_replace($baseSource, $baseTarget, $url);
                         /** compose authentication package */
                         /** @var $authPack Praxigento_LoginAs_Model_Package */
                         $authPack = Mage::getSingleton('prxgt_lgas_model/package');
                         $authPack->setAdminName($operator);
                         $authPack->setCustomerId($customerId);
                         $authPack->setCustomerName($customerName);
                         $authPack->setRedirectUrl($url);
                         $validatorData = $session->getValidatorData();
                         $ip = $validatorData['remote_addr'];
                         $authPack->setIp($ip);
                         /** save login data to file */
                         $authPack->saveAsFile();
                         /** log event */
                         $log = Praxigento_LoginAs_Model_Logger::getLogger($this);
                         $log->trace("Operator '{$operator}' is redirected to front from ip '{$ip}' to login" . " as customer '{$customerName}' ({$customerId}).");
                     }
                     $bu = var_export($this->getLayout()->getUpdate()->getHandles(), true);
                     /** load layout and render blocks */
                     $this->loadLayout()->renderLayout();
                 }
             }
         }
     }
 }
示例#2
0
 public function testCfg()
 {
     // System / Configuration
     // general
     $this->assertTrue(is_bool(Praxigento_LoginAs_Config::cfgGeneralEnabled()));
     $this->assertTrue(is_bool(Praxigento_LoginAs_Config::cfgGeneralLogEvents()));
     // UI
     $this->assertTrue(is_bool(Praxigento_LoginAs_Config::cfgUiCustomersGridActionEnabled()));
     $this->assertTrue(is_bool(Praxigento_LoginAs_Config::cfgUiOrdersGridColumnEnabled()));
 }
示例#3
0
 /**
  * Add 'created by' data to order.
  *
  * @param Varien_Event_Observer $observer
  */
 public function onSalesConvertQuoteAddressToOrder(Varien_Event_Observer $observer)
 {
     if (Praxigento_LoginAs_Config::cfgGeneralEnabled()) {
         $order = $observer->getEvent()->getOrder();
         /** @var $session Mage_Customer_Model_Session */
         $session = Mage::getSingleton('customer/session');
         $operator = $session->getData(Praxigento_LoginAs_Config::SESS_LOGGED_AS_OPERATOR);
         if (!is_null($operator)) {
             $order->setData(Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY, $operator);
         } else {
             $order->setData(Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY, '[Customer]');
         }
     }
 }
 /**
  * Add 'created by' data to order.
  *
  * @param Varien_Event_Observer $observer
  */
 public function onSalesConvertQuoteAddressToOrder(\Magento\Framework\Event\Observer $observer)
 {
     if (Praxigento_LoginAs_Config::cfgGeneralEnabled()) {
         $order = $observer->getEvent()->getOrder();
         /** @var $session Mage_Customer_Model_Session */
         $session = $this->customerSession;
         $operator = $session->getData(Praxigento_LoginAs_Config::SESS_LOGGED_AS_OPERATOR);
         if (!is_null($operator)) {
             $order->setData(Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY, $operator);
         } else {
             $order->setData(Praxigento_LoginAs_Config::ATTR_ORDER_CREATED_BY, '[Customer]');
         }
     }
 }