Magento2
Power your online business with the most flexible and scalable ecommerce platform
Magento2 Unable to unserialize value
do you have this error always after each upgrade and you are not able to figure out which value cause this issue?
the best way is to debug the issue and find which one by going to this file
\vendor\magento\framework\Serialize\Serializer\Json.php
go to this function
Change Magento search engine using CLI
You can use the Magento 2 CLI to do it, you can check your current search engine using:
php -f bin/magento config:show catalog/search/engine
if you want to change the engine to Elasticseach version 6 then use this command
php -f bin/magento config:set catalog/search/engine 'elasticsearch6'
How to redirect a customer to another URL from Observer
In order to redirect a customer from observer you need to use another way than the Controller
protected $_response;
protected $_objectManager;
public function __construct( \Magento\Framework\App\ResponseInterface $response, \Magento\Framework\ObjectManagerInterface $objectManager,
) { $this->_response = $response; $this->_objectManager = $objectManager;
}
then in your function you can use this
Magento2- How Magento cache clearing works with Varnish
According to Varnish documentation, “A purge is what happens when you pick out an object from the cache and discard it along with its variants.” A Varnish purge is very similar to a Magento cache clean command (or clicking Flush Magento Cache in the Magento Admin).
In fact, as discussed in this section, when you clean, flush, or refresh the Magento cache, Varnish purges as well.
Configure Magento to purge Varnish
execute this code
bin/magento setup:config:set --http-cache-hosts=192.0.2.100,192.0.2.155:6081
Showing the total of the loaded time of the page
If you want to see the total loaded time for any page to compare the time between the first and second time you can use this command
curl -L --output /dev/null --silent --show-error --write-out 'lookup: %{time_namelookup}\nconnect: %{time_connect}\nappconnect: %{time_appconnect}\npretransfer: %{time_pretransfer}\nredirect: %{time_redirect}\nstarttransfer: %{time_starttransfer}\ntotal: %{time_total}\n' 'https://www.example.com/'
Magento 2 Allowed Memory exhausted error when compile code
you need to increase the memory_limit in php.ini
and as a quick solution you can use these commands directly in the command line
php -dmemory_limit=5G bin/magento setup:di:compile
and
php -dmemory_limit=5G bin/magento setup:static-content:deploy
another code for the composer update
php -dmemory_limit=5G composer.phar update
php -d memory_limit=-1 /usr/local/bin/composer update
Disable Smile-SA / Elasticsuite
We can disable Disable Smile-SA / Elasticsuite in Magento by executing this command
php bin/magento modeul:disable Smile_ElasticsuiteCore Smile_ElasticsuiteCatalog Smile_ElasticsuiteCatalogGraphQl Smile_ElasticsuiteCatalogRule Smile_ElasticsuiteCatalogOptimizer Smile_ElasticsuiteTracker Smile_ElasticsuiteThesaurus Smile_ElasticsuiteSwatches Smile_ElasticsuiteIndices Smile_ElasticsuiteVirtualCategory
to install the needed plugins you need to execute this command
Change the display time of exception message magento 2
To change the time please copy this file
vendor\magento\module-ui\view\frontend\web\js\view\messages.js
to your them to be in this path
app\design\frontend\{vendor}\{theme}\Magento_Ui\web\js\view\messages.js
then modify this function
Magento: Reindex everyday on specific time
You can add this to your code in order to reindex in UTC -5
0 5 * * * cd /home/{your-full-path}/public_html/ && php -f bin/magento indexer:reindex
How to fix Autocomplete template broken Porto Theme with Smile-SA elasticsuite
Create this file "default.xml" in your theme directory in this folder "{vendor}/{theme}Magento_Search/layout"
add this code in the file