/** * Perform an export according to the given request. * * @param Mage_Core_Controller_Request_Http $request * @param Mage_Core_Controller_Response_Http $response * @throws Exception */ public function process(Mage_Core_Controller_Request_Http $request, Mage_Core_Controller_Response_Http $response) { // In case store is part of URL path use it to choose config. $store = $request->get('store'); if ($store) { $store = Mage::app()->getStore($store); } $apiConfigCharset = Mage::getStoreConfig("api/config/charset", $store); $start_date = strtotime($request->getParam('start_date')); $end_date = strtotime($request->getParam('end_date')); if (!$start_date || !$end_date) { throw new Exception('Start and end dates are required', 400); } $page = (int) $request->getParam('page'); /* @var $orders Mage_Sales_Model_Mysql4_Order_Collection */ $orders = Mage::getResourceModel('sales/order_collection'); // might use 'created_at' attribute instead $orders->addAttributeToFilter('updated_at', array('from' => date('Y-m-d H:i:s', $start_date), 'to' => date('Y-m-d H:i:s', $end_date))); if ($store) { $orders->addAttributeToFilter('store_id', $store->getId()); } if ($page > 0) { $orders->setPage($page, $this->_getExportPageSize()); } $xml = new XMLWriter(); $xml->openMemory(); $xml->startDocument('1.0', $apiConfigCharset); $this->_writeOrders($orders, $xml, $store ? $store->getId() : 0); $xml->endDocument(); $response->clearHeaders()->setHeader('Content-Type', 'text/xml; charset=' . $apiConfigCharset)->setBody($xml->outputMemory(true)); }
/** * Try to login user in admin * * @param string $username * @param string $password * @param Mage_Core_Controller_Request_Http $request * @return Mage_Admin_Model_User|null */ public function login($username, $password, $request = null) { if (empty($username) || empty($password)) { return; } $user = Mage::getModel('admin/user')->login($username, $password); if ($user->getId() && $user->getIsActive() != '1') { if ($request && !$request->getParam('messageSent')) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Your Account has been deactivated.')); $request->setParam('messageSent', true); } } elseif (!Mage::getModel('admin/user')->hasAssigned2Role($user->getId())) { if ($request && !$request->getParam('messageSent')) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Access Denied.')); $request->setParam('messageSent', true); } } else { if ($user->getId()) { $session = Mage::getSingleton('admin/session'); $session->setIsFirstVisit(true); $session->setUser($user); $session->setAcl(Mage::getResourceModel('admin/acl')->loadAcl()); if ($request) { header('Location: ' . $request->getRequestUri()); exit; } } else { if ($request && !$request->getParam('messageSent')) { Mage::getSingleton('adminhtml/session')->addError(Mage::helper('adminhtml')->__('Invalid Username or Password.')); $request->setParam('messageSent', true); } } } return $user; }
/** * Read settings * * @param Mage_Core_Controller_Request_Http $request * @return $this */ public function setPageFromRequest(Mage_Core_Controller_Request_Http $request) { $this->_currentPage = max(1, $request->getParam('page')); $limit = $request->getParam('limit', null); if ($limit !== null) { $this->_pageSize = (int) $limit; } return $this; }
/** * @param Mage_Core_Controller_Request_Http $request * * @return bool */ public function isApiKeyValid(Mage_Core_Controller_Request_Http $request) { $apiKeyName = $this->getApiKeyName(); $postApiKey = $request->getParam($apiKeyName, NULL); $key = $this->getApiKey(); return !empty($key) && $key === $postApiKey; }
/** * @param Mage_Core_Controller_Request_Http $request * @return string * @throws Mage_Core_Exception */ public function initFromRequest(Mage_Core_Controller_Request_Http $request) { if ($request->getParam('expert_mode') == 'on') { $cronExpression = $request->getParam('cron_expr'); return $cronExpression; } try { // easy mapping $params = $request->getParams(); $data = new Noovias_Cron_Data_CronExpression($params); // $cronExpression = $this->getGenerationService()->generateCronExprFromDataObject($data); return $cronExpression; } catch (Exception $e) { throw new Mage_Core_Exception($e->getMessage()); } }
/** * Perform a notify using POSTed data. * * See Auctane API specification. * * @param Mage_Core_Controller_Request_Http $request * @throws Exception */ public function process(Mage_Core_Controller_Request_Http $request) { // Raw XML is POSTed to this stream $xml = simplexml_load_file('php://input'); // load some objects $order = $this->_getOrder($xml->OrderNumber); $qtys = $this->_getOrderItemQtys(@$xml->Items, $order); $shipment = $this->_getOrderShipment($order, $qtys); // this is where tracking is actually added $track = Mage::getModel('sales/order_shipment_track')->setNumber($xml->TrackingNumber)->setCarrierCode($xml->Carrier)->setTitle($xml->Service); $shipment->addTrack($track); // 'NotifyCustomer' must be "true" or "yes" to trigger an email $notify = filter_var(@$xml->NotifyCustomer, FILTER_VALIDATE_BOOLEAN); $capture = filter_var($request->getParam('capture'), FILTER_VALIDATE_BOOLEAN); if ($capture && $order->canInvoice()) { $invoice = $order->prepareInvoice($qtys); $invoice->setRequestedCaptureCase($invoice->canCapture() ? 'online' : 'offline')->register()->addComment($this->_getInvoiceComment(), $notify)->sendEmail($notify); // always send to store manager, and optionally notify customer too $order->setIsInProcess(true); // updates status on save } // Internal notes are only visible to admin if (@$xml->InternalNotes) { $shipment->addComment($xml->InternalNotes); } // Customer notes have 'Visible On Frontend' set if ($notify) { // if no NotesToCustomer then comment is empty string $shipment->sendEmail(true, (string) @$xml->NotesToCustomer)->setEmailSent(true); } if (@$xml->NotesToCustomer) { $shipment->addComment($xml->NotesToCustomer, $notify, true); } $transaction = Mage::getModel('core/resource_transaction'); $transaction->addObject($shipment)->addObject($track); if (isset($invoice)) { // order has been captured, therefore has been modified $transaction->addObject($invoice)->addObject($order); } $transaction->save(); if ($order->canInvoice() && !$order->canShip()) { // then silently invoice if order is shipped to move status to "Complete") $invoice = $order->prepareInvoice(); $invoice->setRequestedCaptureCase($invoice->canCapture() ? 'online' : 'offline')->register()->addComment($this->_getInvoiceComment(), false)->sendEmail(false); // always send to store manager, and optionally notify customer too $order->setIsInProcess(true); // updates status on save $transaction = Mage::getModel('core/resource_transaction'); if (isset($invoice)) { // order has been captured, therefore has been modified $transaction->addObject($invoice)->addObject($order); } $transaction->save(); } }
/** * Parse $_inRoleUsersFilter value from request * * @param Mage_Core_Controller_Request_Http $request * @param Mage_Backend_Helper_Data $backendHelper * @return int */ protected function _parseInRoleUsersFilter(Mage_Core_Controller_Request_Http $request, Mage_Backend_Helper_Data $backendHelper) { $result = self::IN_ROLE_USERS_ANY; $filter = $backendHelper->prepareFilterString($request->getParam('filter', '')); if (isset($filter[self::IN_ROLE_USERS_PARAMETER])) { $result = $filter[self::IN_ROLE_USERS_PARAMETER] ? self::IN_ROLE_USERS_YES : self::IN_ROLE_USERS_NO; } elseif (!$request->isAjax()) { $result = self::IN_ROLE_USERS_YES; } return $result; }
/** * Validate customer attribute actions * * @param Mage_Adminhtml_Controller_Action $controller * @return bool */ public function validateCustomerAttributeActions($controller) { $actionName = strtolower($this->_request->getActionName()); $attributeId = $this->_request->getParam('attribute_id'); $websiteId = $this->_request->getParam('website'); if (in_array($actionName, array('new', 'delete')) || in_array($actionName, array('edit', 'save')) && !$attributeId || $websiteId && !$this->_role->hasWebsiteAccess($websiteId, true)) { $this->_forward(); return false; } return true; }
/** * Hide price elements on Price Tab of Product Edit Page if needed * * @param Mage_Core_Block_Abstract $block * @return void */ protected function _hidePriceElements($block) { /** @var $product Mage_Catalog_Model_Product */ $product = Mage::registry('product'); $form = $block->getForm(); $group = $block->getGroup(); $fieldset = null; if (!is_null($form) && !is_null($group)) { $fieldset = $form->getElement('group_fields' . $group->getId()); } if (!is_null($product) && !is_null($form) && !is_null($group) && !is_null($fieldset)) { $priceElementIds = array('special_price', 'tier_price', 'group_price', 'special_from_date', 'special_to_date', 'cost', 'open_amount_max', 'open_amount_min', 'allow_open_amount', 'giftcard_amounts', 'msrp_enabled', 'msrp_display_actual_price_type', 'msrp'); // Leave price element for bundle product active in order to change/view price type when product is created if (Mage::registry('product')->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) { array_push($priceElementIds, 'price'); } // Remove price elements or disable them if needed foreach ($priceElementIds as &$priceId) { if (!$this->_canReadProductPrice) { $fieldset->removeField($priceId); } elseif (!$this->_canEditProductPrice) { $priceElement = $form->getElement($priceId); if (!is_null($priceElement)) { $priceElement->setReadonly(true, true); } } } if (!$this->_canEditProductPrice) { // Handle Recurring Profile tab if ($form->getElement('recurring_profile')) { $form->getElement('recurring_profile')->setReadonly(true, true)->getForm()->setReadonly(true, true); } } if ($product->isObjectNew()) { if (!$this->_canEditProductPrice) { // For each type of products accept except Bundle products, set default value for price if allowed $priceElement = $form->getElement('price'); if (!is_null($priceElement) && $this->_canReadProductPrice && Mage::registry('product')->getTypeId() != Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) { $priceElement->setValue($this->_defaultProductPriceString); } // For giftcard products set default amount $amountsElement = $form->getElement('giftcard_amounts'); if (!is_null($amountsElement)) { $storeId = (int) $this->_request->getParam('store', 0); $websiteId = Mage::app()->getStore($storeId)->getWebsiteId(); $amountsElement->setValue(array(array('website_id' => $websiteId, 'value' => $this->_defaultProductPriceString, 'website_value' => (double) $this->_defaultProductPriceString))); } } } } }
/** * Block editing of Hierarchy if GWS permissions are applicable * * @param Mage_Adminhtml_Controller_Action $controller * @return bool|void */ public function validateCmsHierarchyAction($controller) { if (!$this->_role->getIsAll()) { $requestAction = $this->_request->getActionName(); if ($requestAction == 'delete' || $requestAction == 'copy') { $scopesParam = $this->_request->getParam('scopes'); $scopesParamIsArray = true; if (!is_array($scopesParam)) { $scopesParam = array($scopesParam); $scopesParamIsArray = false; } $validatedScopes = array(); foreach (array_unique($scopesParam) as $value) { if (0 === strpos($value, Enterprise_Cms_Helper_Hierarchy::SCOPE_PREFIX_WEBSITE)) { $scopeId = (int) str_replace(Enterprise_Cms_Helper_Hierarchy::SCOPE_PREFIX_WEBSITE, '', $value); if ($this->_role->hasExclusiveAccess((array) $scopeId)) { $validatedScopes[] = $value; } } elseif (0 === strpos($value, Enterprise_Cms_Helper_Hierarchy::SCOPE_PREFIX_STORE)) { $scopeId = (int) str_replace(Enterprise_Cms_Helper_Hierarchy::SCOPE_PREFIX_STORE, '', $value); if ($this->_role->hasExclusiveStoreAccess((array) $scopeId)) { $validatedScopes[] = $value; } } } if (count($validatedScopes) > 0) { if ($requestAction == 'delete' && !$scopesParamIsArray && count($validatedScopes) == 1 && isset($validatedScopes[0])) { $validatedScopes = $validatedScopes[0]; } $this->_request->setParam('scopes', $validatedScopes); } else { $this->_forward(); return false; } } else { $websiteCode = $controller->getRequest()->getParam('website'); $website = Mage::app()->getWebsite($websiteCode); $websiteId = $website->getId(); if (!$this->_role->hasExclusiveAccess((array) $websiteId)) { $storeCode = $controller->getRequest()->getParam('store'); $store = Mage::app()->getStore($storeCode); $storeId = $store->getId(); if (!$this->_role->hasExclusiveStoreAccess((array) $storeId)) { $this->_forward(); return false; } } } } return true; }
public function buildAndSendResponse(Mage_Core_Controller_Request_Http $httpRequest, Mage_Core_Controller_Response_Http $httpResponse) { try { $categoryId = $httpRequest->getParam('category_id'); $allMode = $httpRequest->getParam('all_categories_mode'); if (!$allMode && !$categoryId) { throw new Creatuity_MegaMenu_Model_Ajax_UserException("'category_id' parameter is missing"); } $cacheKey = $allMode ? $categoryId : 0; $this->_jsonResponse = $this->_cache()->loadCache($cacheKey); if ($this->_jsonResponse === false) { $this->_jsonResponse = $this->_process($categoryId, $allMode); $this->_cache()->saveCache($cacheKey, $this->_jsonResponse); } $this->_renderResponse($httpResponse, $this->_jsonResponse, 200); $this->_cache()->setNeverExpireBrowserCacheHeader($httpRequest, $httpResponse); } catch (Creatuity_MegaMenu_Model_Ajax_UserException $e) { $this->_renderResponse($httpResponse, $this->_errorResponse($e->getMessage()), 500); } catch (Exception $e) { Mage::logException($e); $this->_renderResponse($httpResponse, $this->_errorResponse(Mage::getIsDeveloperMode() ? $e->getMessage() : ''), 500); } return $this; }
/** * Retrieve default currency for selected store, website or website group * * @param Mage_Core_Controller_Request_Http $request * @return string */ public function getDefaultCurrency(Mage_Core_Controller_Request_Http $request) { if ($request->getParam('store')) { $store = $request->getParam('store'); $currencyCode = $this->_app->getStore($store)->getBaseCurrencyCode(); } else { if ($request->getParam('website')) { $website = $request->getParam('website'); $currencyCode = $this->_app->getWebsite($website)->getBaseCurrencyCode(); } else { if ($request->getParam('group')) { $group = $request->getParam('group'); $currencyCode = $this->_app->getGroup($group)->getWebsite()->getBaseCurrencyCode(); } else { $currencyCode = $this->_app->getStore()->getBaseCurrencyCode(); } } } return $currencyCode; }
/** * Get New Customer Address from form * * @param Mage_Core_Controller_Request_Http $request * * @return Mage_Customer_Model_Address */ protected function _getFormNewCustomerAddress(Mage_Core_Controller_Request_Http $request) { $customerAddressId = $request->getParam('id'); $customerAddress = Mage::getModel('checkout/type_multishipping')->getCustomer()->getAddressById($customerAddressId); /* @var Mage_Customer_Model_Form $addressForm*/ $addressForm = Mage::getModel('customer/form'); $addressForm->setFormCode('customer_address_edit')->setEntity($customerAddress); $addressData = $addressForm->extractData($request); $customerAddress->setData(array_merge($customerAddress->getData(), $addressData)); $customerAddress->setIsDefaultBilling($request->getParam('default_billing', false))->setIsDefaultShipping($request->getParam('default_shipping', false)); return $customerAddress; }
/** * @param Mage_Core_Controller_Request_Http $request * @return array */ protected function getCatalogCategoryViewCacheTags(Mage_Core_Controller_Request_Http $request) { $cacheTags = array(); $cacheTags[] = sha1('category'); $categoryId = (int) $request->getParam('id', false); if ($categoryId) { $cacheTags[] = sha1('category_' . $categoryId); } return $cacheTags; }
/** * Extract edit values from given request * * @param string $type Grid block type * @param array $config Edited value config * @param Mage_Core_Controller_Request_Http $request Request object * @return array */ protected function _extractRequestEditValues($type, $config, $request) { $idsKey = $config['config']['ids_key']; $additionalKey = $config['config']['additional_key']; $valuesKey = $config['config']['values_key']; $params = array('ids' => $request->getParam($idsKey, array()), 'additional' => $request->getParam($additionalKey, array()), 'values' => $request->getParam($valuesKey, array()), 'global' => array_diff_key($request->getParams(), array_flip(array($idsKey, $additionalKey, $valuesKey)))); return array_map(create_function('$a', 'return (is_array($a) ? $a : array());'), $params); }
private function getDataFromRequest(Mage_Core_Controller_Request_Http $source, array $params = array()) { $id = $source->getParam('id'); $nick = $source->getParam('nick'); $mode = $source->getParam('mode', Ess_M2ePro_Model_Ebay_Template_Manager::MODE_CUSTOM); $attributeSets = $source->getParam('attribute_sets', ''); $attributeSets = explode(',', $attributeSets); return array('account_id' => $source->getParam('account_id'), 'marketplace_id' => $source->getParam('marketplace_id'), 'store_id' => Mage_Core_Model_App::ADMIN_STORE_ID, 'attribute_sets' => $attributeSets, 'display_use_default_option' => (bool) $source->getParam('display_use_default_option'), 'templates' => array($nick => array('id' => $id, 'mode' => $mode, 'force_parent' => false))); }
public function getScopeId(Mage_Core_Controller_Request_Http $request) { if ($request->getParam('store')) { return Mage::app()->getStore($request->getParam('store'))->getId(); } else { if ($request->getParam('website')) { return Mage::app()->getWebsite($request->getParam('website'))->getId(); } else { return 0; } } }
/** * Constructor. * * @param Mage_Core_Controller_Request_Http $request * @param Mage_Webapi_Model_Acl_User_Factory $userFactory */ public function __construct(Mage_Core_Controller_Request_Http $request, Mage_Webapi_Model_Acl_User_Factory $userFactory) { $this->_userId = (int) $request->getParam('user_id'); $this->_userFactory = $userFactory; }
/** * Retrieve current config scope * * @return string */ public function getScope() { return $this->_request->getParam('store') ? self::SCOPE_STORE : ($this->_request->getParam('website') ? self::SCOPE_WEBSITE : self::SCOPE_DEFAULT); }
/** * Constructor. * * @param Mage_Core_Controller_Request_Http $request * @param Mage_Webapi_Model_Resource_Acl_User $userResource */ public function __construct(Mage_Core_Controller_Request_Http $request, Mage_Webapi_Model_Resource_Acl_User $userResource) { $this->_roleId = (int) $request->getParam('role_id'); $this->_userResource = $userResource; }
/** * Clear out user and session data when validation fails. Dispatch an event, * set session messages and unset user data before returning the empty * user object. * @param Mage_Admin_Model_User $user * @param Mage_Core_Controller_Request_Http $request * @param Mage_Core_Exception $authException * @return null * @codeCoverageIgnore All side-effects taken from Magento auth/login process */ protected function _failValidation(Mage_Admin_Model_User $user, Mage_Core_Controller_Request_Http $request = null, Mage_Core_Exception $authException) { $logMessage = 'Failed to authenticate using token.'; $this->logger->info($logMessage, $this->context->getMetaData(__CLASS__)); // This may be problematic due to the missing user password. It is never // given while doing the token auth so we don't have one to pass. So far // it doesn't seem to be causing any issues but may have some impact on the // Mage_Enterprise_Pci_Model_Observer::adminAuthenticate method. Mage::dispatchEvent('admin_user_authenticate_after', array('username' => $user->getUsername(), 'password' => '', 'user' => $user, 'result' => false)); Mage::dispatchEvent('admin_session_user_login_failed', array('user_name' => $user->getUsername(), 'exception' => $authException)); if ($request && !$request->getParam('messageSent')) { Mage::getSingleton('adminhtml/session')->addError($authException->getMessage()); $request->setParam('messageSent', true); } $user->unsetData(); $this->_postAuthCheckRedirect(Mage::helper('adminhtml')->getUrl('*')); }
/** * Calls the diehard/load controller without spawning a new request * * @param array $params * @return string */ public function getDynamicBlockReplacement($params) { // Append dynamic block content to end of page to be replaced by javascript, but not Ajax if ($params['blocks'] || !empty($params['all_blocks'])) { // Init store if it has not been yet (page served from cache) if (!$this->helper()->isAppInited()) { $this->helper()->initApp(); } else { // Reset layout Mage::unregister('_singleton/core/layout'); Mage::getSingleton('core/layout'); // TODO Mage::app()->getLayout() is not reset using the method above! // TODO Consider resetting Magento entirely using Mage::reset(); } // Create a sub-request to get JSON response $uri = $this->getBaseUrl() . '/_diehard/load/ajax'; $request = new Mage_Core_Controller_Request_Http($uri); $request->setRouteName('diehard'); $request->setModuleName('_diehard'); $request->setControllerName('load'); $request->setActionName('ajax'); $request->setControllerModule('Cm_Diehard'); $request->setParam('full_action_name', $params['full_action_name']); if (!empty($params['all_blocks'])) { $request->setParam('all_blocks', 1); } else { $request->setParam('blocks', $params['blocks']); } $request->setParam('params', $params['params']); $request->setDispatched(true); // Override parameters in request singleton (for Mage_Core_Block_Abstract#getRequest()) Mage::app()->getRequest()->clearParams(); Mage::app()->getRequest()->setParams($request->getParams()); Mage::app()->getRequest()->setParams($request->getParam('params')); // Render sub-request into sub-response object $response = new Mage_Core_Controller_Response_Http(); require_once Mage::getModuleDir('controllers', 'Cm_Diehard') . '/LoadController.php'; $controller = new Cm_Diehard_LoadController($request, $response); $controller->dispatch('json'); $replacement = ''; if ($this->helper()->isDebug()) { $replacement .= '<!-- Dynamic blocks rendered: ' . (empty($params['all_blocks']) ? implode(',', $params['blocks']) : 'ALL') . ' -->' . "\n"; } $replacement .= "<script type=\"text/javascript\">/* <![CDATA[ */Diehard.replaceBlocks({$response->getBody()});/* ]]> */</script>"; return $replacement; } else { if ($this->helper()->isDebug()) { return '<!-- No dynamic blocks -->'; } else { return ''; } } }
/** * 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); } } } }
/** * Update system data for current VDE environment * * @param string $areaCode * @param Mage_Core_Controller_Request_Http $request * @param Mage_Core_Controller_Varien_ActionAbstract $controller */ public function update($areaCode, Mage_Core_Controller_Request_Http $request, Mage_Core_Controller_Varien_ActionAbstract $controller) { $handle = $request->getParam('handle', ''); if (empty($handle)) { $mode = self::MODE_NAVIGATION; if (!$request->isAjax()) { $this->_backendSession->setData(self::CURRENT_HANDLE_SESSION_KEY, $controller->getFullActionName()); $this->_backendSession->setData(self::CURRENT_URL_SESSION_KEY, $request->getPathInfo()); } } else { $mode = self::MODE_DESIGN; } $this->_backendSession->setData(self::CURRENT_MODE_SESSION_KEY, $mode); $this->_injectUrlModel($mode); $this->_injectLayout($mode, $areaCode); $this->_injectLayoutUpdateResourceModel(); $this->_setTheme(); $this->_disableCache(); }
/** * @param null $key * * @return Mage_Core_Controller_Request_Http | mixed */ public function getRequest($key = null) { if (is_null($key)) { return $this->_request; } else { if (is_null($this->_getData('request_' . $key))) { $this->setData('request_' . $key, $this->_request->getParam($key)); } return $this->_getData('request_' . $key); } }
/** * @param Mage_Core_Controller_Request_Http $request * @return $this */ protected function _initializeRequest(Mage_Core_Controller_Request_Http $request) { $filters = array(); if ($layeredPathInfo = $request->getParam('layered_navigation_path')) { $this->_inPathEnabled = true; $filters = $this->_extractAttributeFilterInformation($layeredPathInfo); $categories = $this->_extractCategoryFilterInformation($layeredPathInfo); $filters = array_merge($filters, $categories); $anonymousAttributes = $this->_extractAnonymousFilterInformation($layeredPathInfo); foreach ($anonymousAttributes as $key) { $filterData = $this->getFilterIdByKey(null, $key); if (is_array($filterData)) { $attribute = $this->getAttributeByCode($filterData[0]); if ($attribute) { $attributeCode = $attribute->getAttributeCode(); $this->_enabledFilters[$attributeCode][] = $filterData[1]; } } else { if (is_numeric($key)) { $attribute = $this->getAttributeByOption($key); if ($attribute) { $attributeCode = $attribute->getAttributeCode(); $this->_enabledFilters[$attributeCode][] = $key; } } } } } if ($categoryFilter = $this->getParam('cat')) { if (is_array($categoryFilter)) { $categories = array('cat' => $categoryFilter); } else { $categories = $this->_extractCategoryFilterInformation($categoryFilter); } if (!empty($categories)) { if (isset($filters['cat'])) { $filters['cat'] = array_merge($filters['cat'], $categories['cat']); } else { $filters['cat'] = $categories['cat']; } } } // Initialize attributes foreach ($this->getFilterableAttributes() as $attribute) { $attributeCode = $attribute->getAttributeCode(); if (isset($filters[$attributeCode])) { $this->_enabledFilters[$attributeCode] = $filters[$attributeCode]; } else { if ($value = $this->_request->getParam($attributeCode)) { if (is_array($value)) { if ('decimal' == $attribute->getBackendType()) { $this->_enabledFilters[$attributeCode] = $value; } else { foreach ($value as $_value) { if ($optionId = $this->getFilterIdByKey($attributeCode, $_value)) { $this->_enabledFilters[$attributeCode][] = $optionId; } else { if (is_numeric($_value)) { $this->_enabledFilters[$attributeCode][] = $_value; } } } } } else { if ('decimal' == $attribute->getBackendType()) { $matches = array(); if (preg_match_all('/\\d+\\-\\d+/', $value, $matches)) { $this->_enabledFilters[$attributeCode] = $matches[0]; } } else { foreach (explode('-', $value) as $_value) { if ($optionId = $this->getFilterIdByKey($attributeCode, $_value)) { $this->_enabledFilters[$attributeCode][] = $optionId; } else { if (is_numeric($_value)) { $this->_enabledFilters[$attributeCode][] = $_value; } } } } } } } } // Initialize categories if (isset($filters['cat']) && !empty($filters['cat'])) { foreach ($filters['cat'] as $value) { if ($_value = $this->getFilterIdByKey('cat', $value)) { $this->_enabledFilters['cat'][] = $_value; } else { if (is_numeric($value)) { $this->_enabledFilters['cat'][] = $_value; } } } } return $this; }
/** * Generate params to post to eWAY gateway to create new token. * * @param Mage_Core_Controller_Request_Http $request * @return array */ protected function _generateApiParams($request) { $billingAddress = Mage::getModel('customer/address'); $billingAddress->addData($request->getParam('address')); $errors = $billingAddress->validate(); if ($errors !== true && is_array($errors)) { Mage::throwException(implode('<br/>', $errors)); } $infoInstance = new Varien_Object($request->getParam('payment')); return array($billingAddress, $infoInstance); }
/** * Takes in an HTTP request and applies the code * * @param Mage_Core_Controller_Request_Http $request * @return boolean */ public function applyCodeFromRequest($request) { list($couponParam, $errorParam) = $this->getParams(); $session = Mage::getSingleton('core/session'); $errorCode = $request->getParam($errorParam, null); $couponCode = $request->getParam($couponParam, null); if ($errorCode || $couponCode) { if (!empty($couponCode)) { $force = $request->has(self::FORCE_PARAM); try { $coupon = $this->_validateCode($couponCode, $force); if (!$this->isCouponApplied($coupon->getRuleId(), $couponCode)) { $this->applyCode($coupon->getRuleId(), $couponCode); $session->addSuccess($this->getSuccessMessage($couponCode)); } return true; } catch (Exception $e) { $errorCode = $e->getMessage(); } } if (!$this->isValidErrorCode($errorCode)) { $errorCode = self::INVALID_CODE; } $session->addError($this->getErrorMessage($errorCode, $couponCode)); } return false; }