Magento 2

Magento command for site with different version of PHP on aaPanel

Magento command for site with different version of PHP on aaPanel If default php version is 7.3 on aaPanel and your website is running on 7.2 use the following way to run commands /www/server/php/72/bin/php bin/magento setup:upgrade /www/server/php/72/bin/php bin/magento setup:di:compile /www/server/php/72/bin/php bin/magento setup:static-content:deploy

Magento admin password reset

Use the following command to perform Magento admin password reset php bin/magento admin:user:create –admin-user=”admin” –admin-password=”123123q” –admin-email=”admin@example.com” –admin-firstname=”Admin” –admin-lastname=”Admin” After creating new admin, you can login and change the original user password with it. Magento – Magento admin password reset using md5 We can access to admin backend resetting admin user password with md5. UPDATE admin_user […]

Delete unused images from my media folder ?

Use the Hackathon EAV cleaner module for this. After installation you can use the command eav:media:remove-unused Also you can do it by installing the module below and running these commands. composer require ekouk/imagecleaner “dev-master” bin/magento setup:upgrade bin/magento setup:di:compile bin/magento cache:flush Run in check only mode which will report the number and size in Mb of […]

Turn Magento 2 Maintenance Mode ON or OFF?

To Turn Magento 2 Maintenance Mode ON bin/magento maintenance:enable To Turn Magento 2 Maintenance Mode OFF bin/magento maintenance:disable  If you need to whitelist your IPs bin/magento maintenance:enable –ip=X1.X1.X1.X1 –ip=X2.X2.X2.X2 To enable maintenance mode for all clients except 192.0.2.10 and 192.0.2.11: bin/magento maintenance:enable –ip=192.0.2.10 –ip=192.0.2.11

How to Get Magento 2 base URL

Get Magento 2 base URL Using Object Manager Base Url: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeManager = $objectManager->get(‘\Magento\Store\Model\StoreManagerInterface’); $storeManager->getStore()->getBaseUrl(); Base Url without index.php $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $storeManager = $objectManager->get(‘\Magento\Store\Model\StoreManagerInterface’); $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_WEB); For getting media base url: $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); for getting link url: $this->_storeManager->getStore() ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_LINK);

js merge carousels sliders are breaking when js merge in Magento 2

Carousels slider breaks when js merge in Magento 2 You should move slider script to the head tag of the page. To debug Disable JS merge. Add the js script you got from carousels sliders into the head tag, Script where you are calling the function has to come after the script where function jQueryowlCarousel […]

Enable template-hints directly from the terminal using a command in Magento 2

Enable template-hints with command in Magento 2 php bin/magento dev:template-hints:enable php bin/magento dev:template-hints:disable  Remove Cache chmod -R 777 var/ pub/ generated/ php bin/magento cache:clean php bin/magento cache:flush rm -rf var/generation/ var/view_preprocessed/ pub/static/frontend/ pub/static/_requirejs/ var/cache var/di var/page_cache pub/static/_cache  

Find exception or error logs in Magento 2 ?

Error logs in Magento 2 Set the developer mode php bin/magento deploy:mode:set developer //You can check the errors for var/log and var/reports folder //You can enable display error reporting from index.php in magento from index.php. Add below code after the starting of <?php ini_set(‘display_errors’, 1); error_reporting(E_ALL); magento.stackexchange.com/questions/282350/where-i-can-find-exception-or-error-logs-in-magento-2

What is my magento admin login url

Run the following command to see Magento admin login url php bin/magento info:adminuri You can also view the Admin URI in <your Magento install dir>/app/etc/env.php. You can find something like below  – ‘backend’ => array ( ‘frontName’ => ‘admin’, ),    

How to get date of tomorrow in magento2

Object Manager Method to get date of tomorrow in magento2 : $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $objDate = $objectManager->create(‘\Magento\Framework\Stdlib\DateTime\DateTime’); $date = $objDate->date(‘Y-m-d’); $nextdate = $objDate->date(‘Y-m-d’, strtotime($date.” +1 days”)); echo $date.”<br/>”; echo $nextdate.”<br/>”;

Magento 2 log : Replacement for Mage::log method

Magento 2 log : Replacement for Mage::log method protected $logger; public function __construct(\Psr\Log\LoggerInterface $logger) { $this->logger = $logger; } //Show $this->logger->info($message); $this->logger->debug($message);   In magento2 You can write to the logs using the Zend library like below : $writer = new \Zend\Log\Writer\Stream(BP . ‘/var/log/test.log’); $logger = new \Zend\Log\Logger(); $logger->addWriter($writer); $logger->info(‘Your text message’);

Adding a jQuery Library to Magento 2

Add jQuery Library to Magento 2 <script type=”text/javascript”> var config = { map: { ‘*’: { bannerslider: ‘Companyname_Modulename/js/flexslider’, } } }; <script type=”text/javascript”> require([‘jquery’,’bannerslider’],function($){ $(window).load(function() { $(‘.flexslider-8’).flexslider({ animation: “fade”, controlNav: “thumbnails”, slideshowSpeed: 2000, minItems: 2, maxItems: 4 }); }); }); </script>