We’re rewarding the question askers & reputations are being recalculated! Read more.
72

If you are trying this from a controller that extends Magento\Framework\App\Action\Action you can get the request with $this->getRequest()->getPost(). If you are in a custom class, you need to inject the request in the constructor. <?php namespace Namespace\Module\Something; class ClassName { protected $request; public function ...


30

Changing the unsecure base url to https will change all links and redirect non-https requests to https://example.com/ (the home page), because that's what Magento does when the base URL validation fails. So this is a good start but to also redirect http://example.com/foo/ to https://example.com/foo/ you need to do it via webserver redirect. For example, ...


16

Hi you can get it easily in models, blocks and controllers by using: $this->getRequest()->getPost() Or add Magento\Framework\App\RequestInterface to the constructor parameters in your own classes: <?php namespace MyModuleNameSpace\MyModule\Block use Magento\Framework\App\RequestInterface; class MyClass { /** * Request instance * ...


13

Magento is using secure key validation in admin aria. Simplest way to use secure key is use POST and add form_key to data. Example: jQuery.ajax( { url: 'http://mage.dev/admin/vendor/module/validateTest', data: {form_key: window.FORM_KEY}, type: 'POST' }).done(function(a) { console.log(a); // log: {a: "b"} });


12

Try this $current_url = $this->getUrl('*/*/*', array('_current' => true,'_use_rewrite' => true, '_query' => $your_query)); Where $your_query = array('new_query' => 123)


10

For completeness we also do a very similar thing to what fschmengler has suggested with some additions; RewriteCond %{HTTP:X-Forwarded-Proto} !=https RewriteCond %{HTTPS} !=on RewriteCond %{REQUEST_METHOD} !=POST RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] We place this inside the section of the .htaccess just below RewriteEngine On


9

First of all, to comply with action controller interface \Magento\Framework\App\ActionInterface::execute(), your action must return an instance of \Magento\Framework\Controller\ResultInterface (\Magento\Framework\App\ResponseInterface is also supported, but is legacy and will be removed in future releases of M2, when all core usages are refactored). So ...


9

Set your base url for secure and unsecure in the backend. Set yes on use secure url in frontend in the backend. Then edit your app/etc/local.xml and include this <?xml version="1.0"?> <config> <frontend> <secure_url> <all>/</all> </secure_url> </frontend> </config> Or at least ...


8

I used Magento\Framework\App\State::getAreaCode() to find if request is coming via SOAP / REST API. You can check the possible area codes in Magento\Framework\App\Area class.


6

Go to system->configuration->Developer->JavaScript Settings and set Merge JavaScript Files to Yes.


6

Magento 2 provides a Magento\Framework\App\ResponseInterface abstract type for you to instantiate via the dependency injection. Object manager used below for simplicity's sake. /** @var \Magento\Framework\App\ObjectManager $om */ $om = \Magento\Framework\App\ObjectManager::getInstance(); /** @var \Magento\Framework\App\ResponseInterface|\Magento\...


6

There is no problem with HTTP/2 "just working". But there is opportunity for further optimization. My understanding is it is worth looking into capabilities of your CDN provider if you want to take full advantage of the push support. E.g. when request for first CSS etc file comes in, server can start pushing other files it knows you are almost certainly ...


5

You can always return \Magento\Framework\Controller\Result\Raw with custom status header. Also you can send 404 by throwing \Magento\Framework\Exception\NotFoundException. It will be processed in lib/internal/Magento/Framework/App/FrontController.php:61 to 'noroute' path, which will resolve to \Magento\Cms\Controller\Noroute\Index (or more specific if ...


5

Try using Mage::helper('core/http')->getHttpReferer() Anyway, first try to return a string from your method since I think the issue you are experiencing is there and not in the $_SERVER["HTTP_REFERER"] part.


5

Yes, adding a rewrite that does pass true as the third parameter to the setHeader() method would fix this. Setting the third parameter $replace to true will make the setHeader() method to search the array of headers (already set before) and unset() any header with the same name, making the "Content-type" header that you are setting the only one. By the way,...


5

Make sure System > Configuration > Web > url_options > "Auto-redirect to Base URL = No". It was set to yes, and causing the problem. Put below code in .htaccess file. RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]


5

Well you use PHP native method parse_url() : http://php.net/manual/en/function.parse-url.php var_dump(parse_url(Mage::helper('core/http')->getHttpReferer())); It will give you the following result: array(3) { ["scheme"]=> string(4) "http" ["host"]=> string(9) "localhost" ["path"]=> string(28) "/index.php/customer/account/" } If ...


4

getPostValue() is written in lib\internal\Magento\Framework\HTTP\PhpEnvironment\Request.php /** * Retrieve POST parameters * * @param string $name * @param mixed $default * @return mixed|ParametersInterface */ public function getPostValue($name = null, $default = null) { $post = $this->getPost($name, $...


4

Everything you wrote is accurate. To clarify the singleton behavior: both, Mage::helper() and Mage::getSingleton() look up an entry in the Magento registry (which is a global data storage per request) in the form _helper/module/class or _singleton/module/class and if it does not exist, instantiate the helper or singleton and store it in the registry.


4

The helper will only live during the execution, so #2 is true, it will not persist after the request. #3, sure you can save any data you want from the Helper into core/session, customer/session, checkout/session etc. #4, #5, #6 should return the same result no matter what. Calling the helper from a Model, Controller, even a template file will return the ...


4

In Magento 2x the product image urls are all relative. It's possible some extension or usage of CDN could change the base path. You can call the the V1/store/StoreConfigs api and use the baseMediaUrl value to get the full path.


4

I think the easiest way would be to change the non-secure base url to https since magento then redirects all "non-secure" requests to this url and also generates the links with this url. you can change the base url under system -> configuration -> general -> web


4

You definitely can use Http/2 with any version of Magento. And yes, you need to enable https for all pages (it's recommended setup for M2, why do you not did it before). Also, bundling of js files don't make sense with http2, so better to disable it


3

Is it OK to assume that these methods are always going to be there for http requests? Don't think so. They're breaking their own class contract. As you can imagine, that's not OOP-ish at all. As per the usual recommendation, I would stay away from using anything that's not declared in Magento\Framework\App\RequestInterface because a) you'll make Liskov ...


3

Here is very good presentation "Magento 2 Request Flow" by Anton Kril form Meet Magento NL 2015 Here is also info about rounting in official documentation


3

You need to look into the try, catch section. There is where magic happens. try { $errors = $this->_getCustomerErrors($customer); if (empty($errors)) { $customer->cleanPasswordsValidationData(); $customer->save(); $this->_dispatchRegisterSuccess($customer); $this->...


3

Found the URL on server directory. Just add a prefix to the URL. Prefix: http://magento.com/pub/media/catalog/product/(url in API response)


3

In Magento 2.1 and above, easiest way is to use the result factory: public function execute() { $resultPage = $this->resultFactory ->create(ResultFactory::TYPE_JSON) ->setHeader("myheaderkey", "value") ->setHttpResponseCode(403); return $resultPage; } The ResultFactory is already injected into your controller ...


3

If you want to set all pages to HTTPS, you might also want to enable HSTS (More info: https://en.wikipedia.org/wiki/HTTP_Strict_Transport_Security). For the rest of it, I never had any trouble using a webshop on HTTPS/2, so like Alan and KAndy say, it should just work.


3

Some important points for speeding up Magento 2:: Production Mode Full Page Cache Minify JS and CSS Check TTFB and try to reduce it Enable Flat Categories and Products Enable GZIP compression Never Use JS bundling Upgrade to latest(stable) PHP version Use Varnish Cache instead of built in Magento cache. (optional) Image optimization ...


Only top voted, non community-wiki answers of a minimum length are eligible