Exemple #1
0
 public function construct(Mage_Core_Controller_Request_Http $request)
 {
     $this->request = $request;
     if ($request->getPost('message')) {
         $this->msg = unserialize($this->AC_decode_base64($request->getPost('message')));
     }
 }
 public function testSetPost()
 {
     $post = $_POST;
     $this->_model->setPost(array('test' => 'test'));
     $post['test'] = 'test';
     $this->assertEquals($post, $this->_model->getPost());
     $this->_model->setPost('key', 'value');
     $post['key'] = 'value';
     $this->assertEquals($post, $this->_model->getPost());
 }
 /**
  * Check that request uses https protocol if it should.
  * Function redirects user to correct URL if needed.
  *
  * @param Mage_Core_Controller_Request_Http $request
  * @param string $path
  * @return void
  */
 protected function _checkShouldBeSecure($request, $path = '')
 {
     if (!Mage::isInstalled() || $request->getPost()) {
         return;
     }
     if ($this->_shouldBeSecure($path) && !$request->isSecure()) {
         $url = $this->_getCurrentSecureUrl($request);
         if ($request->getRouteName() != 'adminhtml' && Mage::app()->getUseSessionInUrl()) {
             $url = Mage::getSingleton('core/url')->getRedirectUrl($url);
         }
         Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
         exit;
     }
 }
Exemple #4
0
 /**
  * Check whether SKU file was uploaded
  *
  * @param Mage_Core_Controller_Request_Http $request
  * @return bool
  */
 public function isSkuFileUploaded(Mage_Core_Controller_Request_Http $request)
 {
     return (bool) $request->getPost(self::REQUEST_PARAMETER_SKU_FILE_IMPORTED_FLAG);
 }
Exemple #5
0
 /**
  * Handle subscription on customer account
  *
  * @param Mage_Core_Controller_Request_Http $request
  * @param string $guestEmail
  * @return void
  */
 public function handlePost($request, $guestEmail)
 {
     //<state> param is an html serialized field containing the default form state
     //before submission, we need to parse it as a request in order to save it to $odata and process it
     //        parse_str($request->getPost('state'), $odata);
     $m = explode('&', $request->getPost('state'));
     $odata = array();
     $list = array();
     foreach ($m as $v) {
         $g = explode('=', $v);
         $u = explode('%5B', $v);
         if ($u[0] == 'list') {
             $suffixListId = $u[1];
             $listId = substr($u[1], 0, strlen($suffixListId) - 3);
             $list[$listId] = array();
             $listIdArray = $list[$listId];
             $tail = explode('%5D', $u[2]);
             $subscribed = $tail[0];
             $listIdArray[$subscribed] = $g[1];
             $list[$listId] = $listIdArray;
             $odata['list'] = $list;
         } else {
             $odata[$g[0]] = $g[1];
         }
     }
     $curlists = TRUE === array_key_exists('list', $odata) ? $odata['list'] : array();
     $lists = $request->getPost('list', array());
     $defaultList = $this->getDefaultList(Mage::app()->getStore());
     $api = Mage::getSingleton('monkey/api');
     $loggedIn = Mage::helper('customer')->isLoggedIn();
     if ($loggedIn) {
         $customer = Mage::helper('customer')->getCustomer();
     } else {
         $customer = Mage::registry('mc_guest_customer');
     }
     $email = $guestEmail ? $guestEmail : $customer->getEmail();
     if (!empty($curlists)) {
         //Handle Unsubscribe and groups update actions
         foreach ($curlists as $listId => $list) {
             if (FALSE === array_key_exists($listId, $lists)) {
                 //Unsubscribe Email
                 $item = Mage::getModel('monkey/monkey')->loadByEmail($email);
                 if (!$item->getId()) {
                     $item = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
                 }
                 if ($item->getSubscriberEmail()) {
                     $item->unsubscribe();
                 }
                 //Unsubscribe Email
                 $alreadyOnDb = Mage::getSingleton('monkey/asyncsubscribers')->getCollection()->addFieldToFilter('lists', $listId)->addFieldToFilter('email', $email)->addFieldToFilter('processed', 0);
                 if (count($alreadyOnDb) > 0) {
                     foreach ($alreadyOnDb as $listToDelete) {
                         $toDelete = Mage::getModel('monkey/asyncsubscribers')->load($listToDelete->getId());
                         $toDelete->delete();
                     }
                     Mage::getSingleton('core/session')->addSuccess($this->__('You have been removed from Newsletter.'));
                 } else {
                     $api->listUnsubscribe($listId, $email);
                     Mage::getSingleton('core/session')->addSuccess($this->__('You have been removed from Newsletter.'));
                 }
             } else {
                 $groupings = $lists[$listId];
                 unset($groupings['subscribed']);
                 $customerLists = $api->listMemberInfo($listId, $email);
                 $customerLists = isset($customerLists['data'][0]['merges']['GROUPINGS']) ? $customerLists['data'][0]['merges']['GROUPINGS'] : array();
                 foreach ($customerLists as $clkey => $cl) {
                     if (!isset($groupings[$cl['id']])) {
                         $groupings[$cl['id']][] = '';
                     }
                 }
                 $customer->setMcListId($listId);
                 $customer->setListGroups($groupings);
                 $mergeVars = Mage::helper('monkey')->getMergeVars($customer);
                 //Handle groups update
                 $api->listUpdateMember($listId, $email, $mergeVars);
                 Mage::getSingleton('core/session')->addSuccess($this->__('Your profile has been updated!'));
             }
         }
     }
     //Subscribe to new lists
     if (is_array($lists) && is_array($curlists)) {
         $subscribe = array_diff_key($lists, $curlists);
         if (!empty($subscribe)) {
             foreach ($subscribe as $listId => $slist) {
                 if (!isset($slist['subscribed'])) {
                     continue;
                 }
                 $groupings = $lists[$listId];
                 unset($groupings['subscribed']);
                 if ($defaultList == $listId) {
                     $subscriber = Mage::getModel('newsletter/subscriber');
                     $subscriber->setListGroups($groupings);
                     $subscriber->setMcListId($listId);
                     $subscriber->setMcStoreId(Mage::app()->getStore()->getId());
                     $subscriber->subscribe($email);
                 } else {
                     $customer->setListGroups($groupings);
                     $customer->setMcListId($listId);
                     $subscriber = Mage::getModel('newsletter/subscriber')->setSubscriberEmail($email);
                     $this->subscribeToList($subscriber, 0, $listId);
                 }
             }
         }
     }
 }
Exemple #6
0
 /**
  * Update quote when returned from PayPal
  * @param string $token
  */
 public function returnFromPaypal(Mage_Core_Controller_Request_Http $paypalData)
 {
     // import billing address (only if not already set in quote (incheckout paypal))
     $billingAddress = $this->_quote->getBillingAddress();
     $baddressValidation = $billingAddress->validate();
     if ($baddressValidation !== true) {
         foreach ($this->_billingAddressMap as $key => $value) {
             $arvalue = $paypalData->getPost($key);
             if ($value == 'street') {
                 $arvalue = $paypalData->getPost('DeliveryAddress1') . "\n" . $paypalData->getPost('DeliveryAddress2');
             }
             $billingAddress->setDataUsingMethod($value, mb_convert_encoding($arvalue, 'UTF-8', 'ISO-8859-15'));
         }
     }
     // import shipping address
     if (!$this->_quote->getIsVirtual() && $paypalData->getPost('AddressStatus') != 'NONE') {
         $shippingAddress = $this->_quote->getShippingAddress();
         if ($shippingAddress) {
             foreach ($this->_billingAddressMap as $key => $value) {
                 $arvalue = $paypalData->getPost($key);
                 if (empty($arvalue)) {
                     continue;
                 }
                 if ($value == 'street') {
                     $arvalue = $paypalData->getPost('DeliveryAddress1') . "\n" . $paypalData->getPost('DeliveryAddress2');
                 }
                 $shippingAddress->setDataUsingMethod($value, mb_convert_encoding($arvalue, 'UTF-8', 'ISO-8859-15'));
             }
             $this->_quote->getShippingAddress()->setCollectShippingRates(true);
         }
     }
     $this->_ignoreAddressValidation();
     // import payment info
     $payment = $this->_quote->getPayment();
     $payment->setMethod('sagepaydirectpro');
     $this->_quote->collectTotals()->save();
 }
Exemple #7
0
 /**
  * Handle subscription posts, (additional lists)
  *
  * @param Mage_Core_Controller_Request_Http $request
  * @param string $guestEmail
  * @return void
  */
 public function handlePost($request, $guestEmail)
 {
     //<state> param is an html serialized field containing the default form state
     //before submission, we need to parse it as a request in order to save it to $odata and process it
     parse_str($request->getPost('state'), $odata);
     $isConfirmNeed = FALSE;
     $curlists = TRUE === array_key_exists('list', $odata) ? $odata['list'] : array();
     $lists = $request->getPost('list', array());
     $defaultList = $this->getDefaultList(Mage::app()->getStore());
     $api = Mage::getSingleton('monkey/api');
     $loggedIn = Mage::helper('customer')->isLoggedIn();
     if ($loggedIn) {
         $customer = Mage::helper('customer')->getCustomer();
     } else {
         $customer = Mage::registry('mc_guest_customer');
     }
     $email = $guestEmail ? $guestEmail : $customer->getEmail();
     if (!empty($curlists)) {
         //Handle Unsubscribe and groups update actions
         foreach ($curlists as $listId => $list) {
             if (FALSE === array_key_exists($listId, $lists)) {
                 //Unsubscribe Email
                 if ($defaultList == $listId) {
                     $item = Mage::getModel('monkey/monkey')->loadByEmail($email);
                     if (!$item->getId()) {
                         $item = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
                     }
                     if ($item->getSubscriberEmail()) {
                         $item->unsubscribe();
                     }
                     //Unsubscribe Email
                     $api->listUnsubscribe($listId, $email);
                 }
             } else {
                 $groupings = $lists[$listId];
                 unset($groupings['subscribed']);
                 $customerLists = $api->listMemberInfo($listId, $email);
                 $customerLists = isset($customerLists['data'][0]['merges']['GROUPINGS']) ? $customerLists['data'][0]['merges']['GROUPINGS'] : array();
                 foreach ($customerLists as $clkey => $cl) {
                     if (!isset($groupings[$cl['id']])) {
                         $groupings[$cl['id']][] = '';
                     }
                 }
                 $customer->setMcListId($listId);
                 $customer->setListGroups($groupings);
                 $mergeVars = Mage::helper('monkey')->getMergeVars($customer);
                 //Handle groups update
                 $api->listUpdateMember($listId, $email, $mergeVars);
             }
         }
     }
     //Subscribe to new lists
     if (is_array($lists) && is_array($curlists)) {
         $subscribe = array_diff_key($lists, $curlists);
         if (!empty($subscribe)) {
             foreach ($subscribe as $listId => $slist) {
                 if (!isset($slist['subscribed'])) {
                     continue;
                 }
                 $groupings = $lists[$listId];
                 unset($groupings['subscribed']);
                 if (!Mage::helper('monkey')->isAdmin() && Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_CONFIRMATION_FLAG, Mage::app()->getStore()->getId()) == 1) {
                     $isConfirmNeed = TRUE;
                 }
                 if ($defaultList == $listId) {
                     $subscriber = Mage::getModel('newsletter/subscriber');
                     $subscriber->setListGroups($groupings);
                     $subscriber->setMcListId($listId);
                     $subscriber->setMcStoreId(Mage::app()->getStore()->getId());
                     $subscriber->setImportMode(TRUE);
                     $subscriber->subscribe($email);
                     //Just for registering the groups in the checkout page
                     $customer->setListGroups($groupings);
                     $mergeVars = Mage::helper('monkey')->getMergeVars($customer);
                     if (!is_null($request->getPost('magemonkey_subscribe'))) {
                         $isOnList = Mage::helper('monkey')->subscribedToList($email, $listId);
                         if (!$isOnList) {
                             $api->listSubscribe($listId, $email, $mergeVars, 'html', $isConfirmNeed);
                         } else {
                             $api->listUpdateMember($listId, $email, $mergeVars);
                         }
                     }
                 } else {
                     $customer->setListGroups($groupings);
                     $customer->setMcListId($listId);
                     $mergeVars = Mage::helper('monkey')->getMergeVars($customer);
                     $api->listSubscribe($listId, $email, $mergeVars, 'html', $isConfirmNeed);
                 }
             }
         }
     }
 }
 /**
  * @param Mage_Core_Controller_Request_Http $request
  * @param string $attributeCode
  * @return boolean
  */
 protected function _isUsingDefaultValue($request, $attributeCode)
 {
     if (is_null($this->_attributesUsingDefault)) {
         $this->_attributesUsingDefault = array();
         if ($useDefaults = $request->getPost('use_default')) {
             $this->_attributesUsingDefault = $useDefaults;
         }
     }
     return in_array($attributeCode, $this->_attributesUsingDefault);
 }
Exemple #9
0
 /**
  * Handle subscription posts, (additional lists)
  *
  * @param Mage_Core_Controller_Request_Http $request
  * @param string $guestEmail
  * @return void
  */
 public function handlePost($request, $guestEmail)
 {
     //<state> param is an html serialized field containing the default form state
     //before submission, we need to parse it as a request in order to save it to $odata and process it
     //parse_str($request->getPost('state'), $odata);
     $isConfirmNeed = FALSE;
     $loggedIn = Mage::helper('customer')->isLoggedIn();
     if ($loggedIn) {
         $customer = Mage::helper('customer')->getCustomer();
     } else {
         $customer = Mage::registry('mc_guest_customer');
     }
     $email = $guestEmail ? $guestEmail : $customer->getEmail();
     $api = Mage::getSingleton('monkey/api');
     $subscribedList = $api->listsForEmail($email);
     $postlists = $request->getPost('list', array());
     $generalList = $this->config('general_list');
     //get general id list from config
     $mcListIds = $this->config('list');
     //get Id Lists from config
     $mcLists = $api->lists(array('list_id' => $mcListIds));
     if ($mcLists['total'] > 0) {
         foreach ($mcLists['data'] as $mcl) {
             if (!in_array($mcl['id'], $postlists)) {
                 if ($generalList == $mcl['id']) {
                     //unsubscribe general list
                     //Unsubscribe Email newsletter magento
                     $item = Mage::getModel('monkey/monkey')->loadByEmail($email);
                     if (!$item->getId()) {
                         $item = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
                     }
                     if ($item->getSubscriberEmail()) {
                         $item->unsubscribe();
                     }
                 }
                 //Unsubscribe Email mailchimp
                 $api->listUnsubscribe($mcl['id'], $email);
             } else {
                 //Subscribe to new lists
                 //$groupings = $lists[$genlId];
                 //unset($groupings['subscribed']);
                 if (!Mage::helper('monkey')->isAdmin() && Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_CONFIRMATION_FLAG, Mage::app()->getStore()->getId()) == 1) {
                     $isConfirmNeed = TRUE;
                 }
                 if ($generalList == $mcl['id']) {
                     //Subscribe general list
                     //create new subscriber without send an confirmation email
                     $subscriber = Mage::getModel('newsletter/subscriber');
                     //$subscriber->setListGroups($groupings);
                     $subscriber->setMcListId($mcl['id']);
                     $subscriber->setMcStoreId(Mage::app()->getStore()->getId());
                     $subscriber->setImportMode(true);
                     $subscriber->subscribe($email);
                 }
                 //$customer->setListGroups($groupings);
                 //set to Groupings
                 $groupId = Mage::getStoreConfig('monkey/general/subscribe_simicart_groupid');
                 $groupName = Mage::getStoreConfig('monkey/general/subscribe_simicart_groupname');
                 $group_add = array($groupId => $groupName);
                 $customer->setListGroups($group_add);
                 $customer->setMcListId($mcl['id']);
                 $mergeVars = Mage::helper('monkey')->getMergeVars($customer);
                 //zend_debug::dump($mergeVars);die;
                 $api->listSubscribe($mcl['id'], $email, $mergeVars, 'html', $isConfirmNeed);
                 //Handle groups update
                 //$api->listUpdateMember($mcl['id'], $email, $mergeVars); //use if not need confirm
             }
         }
     }
 }
Exemple #10
0
 /**
  * Process not logged in user data
  *
  * @param Mage_Core_Controller_Request_Http $request
  */
 protected function _processNotLoggedInUser(Mage_Core_Controller_Request_Http $request)
 {
     $isRedirectNeeded = false;
     if ($request->getPost('login') && $this->_performLogin()) {
         $isRedirectNeeded = $this->_redirectIfNeededAfterLogin();
     }
     if (!$isRedirectNeeded && !$request->getParam('forwarded')) {
         if ($request->getParam('isIframe')) {
             $request->setParam('forwarded', true)->setControllerName('auth')->setActionName('deniedIframe')->setDispatched(false);
         } else {
             if ($request->getParam('isAjax')) {
                 $request->setParam('forwarded', true)->setControllerName('auth')->setActionName('deniedJson')->setDispatched(false);
             } else {
                 $request->setParam('forwarded', true)->setRouteName('adminhtml')->setControllerName('auth')->setActionName('login')->setDispatched(false);
             }
         }
     }
 }
 public function testSaveActionProcessDifferentListings()
 {
     $productIds = array(1, 2, 3);
     $channel = new Varien_Object(array('id' => 'test_channel_id', 'channeltype_code' => 'test_ebay'));
     $this->_mockChannel($channel);
     $policyMock = $this->mockModel('xcom_ebay/policy');
     $policyMock->expects($this->any())->method('load')->will($this->returnValue($policyMock));
     $session = $this->mockModel('adminhtml/session');
     $session->expects($this->once())->method('addSuccess');
     $request = new Mage_Core_Controller_Request_Http();
     $request->setParam('channel_id', 111);
     $storeId = 12;
     $request->setParam('store', $storeId);
     $request->setParam('product_ids', $productIds);
     $request->setPost(array('channel_id' => $channel->getId(), 'policy_id' => 0));
     $objectMock = $this->getMock(get_class($this->_object), array('_redirect'), array($request, new Varien_Object()));
     $objectMock->expects($this->once())->method('_redirect')->with($this->equalTo('*/channel_product/'), $this->equalTo(array('type' => $channel->getChanneltypeCode(), 'store' => $storeId)));
     $channelProductMock = $this->mockModel('xcom_listing/channel_product', array('isProductsInChannel', 'addData', 'getPublishedListingIds', 'saveProducts'));
     $channelProductMock->expects($this->once())->method('isProductsInChannel')->with($this->equalTo($channel->getId()), $this->equalTo($productIds))->will($this->returnValue(true));
     $channelProductMock->expects($this->once())->method('getPublishedListingIds')->with($this->equalTo($productIds), $this->equalTo($channel->getId()))->will($this->returnValue(array(3 => array('product_ids' => array(1, 2), 'channel_id' => $channel->getId()))));
     $listingMock = $this->mockModel('xcom_listing/listing', array('load', 'addData', 'save', 'prepareProducts', 'send', 'saveProducts', '_isChanged'));
     $listingMock->expects($this->any())->method('_isChanged')->will($this->returnValue(true));
     $listingMock->expects($this->any())->method('addData')->with($this->equalTo($request->getPost()));
     $listingMock->expects($this->any())->method('prepareProducts')->with($this->equalTo(array(1, 2)));
     $listingMock->expects($this->any())->method('send')->with($this->equalTo(array('policy' => $policyMock, 'channel' => $channel)));
     $listingMock->expects($this->any())->method('saveProducts');
     $validatorMock = $this->mockHelper('xcom_listing/validator', array('validateOptionalFields', 'validateProducts', 'isPriceChanged', 'isQtyChanged'));
     $validatorMock->expects($this->once())->method('validateOptionalFields');
     $validatorMock->expects($this->once())->method('validateProducts');
     $validatorMock->expects($this->once())->method('isPriceChanged');
     $validatorMock->expects($this->once())->method('isQtyChanged');
     $validatorMock->setListing($listingMock);
     $this->assertNull($objectMock->saveAction());
 }
Exemple #12
0
 /**
  * Check if request URL should be secure
  *
  * Function redirects user to correct URL if needed
  *
  * @param Mage_Core_Controller_Request_Http $request
  * @param string $path
  * @return null
  */
 protected function _checkShouldBeSecure($request, $path = '')
 {
     if (!Mage::isInstalled() || $request->getPost()) {
         return;
     }
     if ($this->_shouldBeSecure($path) && !$request->isSecure()) {
         $url = $this->_getCurrentSecureUrl($request);
         Mage::app()->getFrontController()->getResponse()->setRedirect($url)->sendResponse();
         exit;
     }
 }