Magento 2: Clean Fastly or Varnish Cache by Cache Tag Programmatically

This article shows how you can clean Fastly Cache or Varnish Cache by cache tags in Magento. Fastly has an observer that listens to the event clean_cache_by_tags. vendor/fastly/magento2/etc/events.xml (github) <event name="clean_cache_by_tags"> <observer name="flush_fastly_cdn" instance="Fastly\Cdn\Observer\InvalidateVarnishObserver"/> </event> The \Fastly\Cdn\Observer\InvalidateVarnishObserver class further calls the \Fastly\Cdn\Model\PurgeCache::sendPurgeRequest($pattern) method which finally cleans the Fastly Cache utilizing \Fastly\Cdn\Model\Api. Magento’s Cache_Invalidate module has … Read more

Magento 2: Enable/Disable Cache Programmatically

This article shows how you can enable or disable Magento Cache Programmatically. For this purpose, we will be using \Magento\Framework\App\Cache\Manager class. use Magento\Framework\App\Cache\Manager as CacheManager; class YourClassName { /** * @var CacheManager */ protected $cacheManager; /** … * @param CacheManager $cacheManager */ public function __construct( … CacheManager $cacheManager ) { … $this->cacheManager = $cacheManager; } … Read more

Magento 2: Get, Clean and Flush Cache Programmatically

This article shows how you can get the list of all Cache Types in Magento and how you can clean and flush those Cache Types in Magento. Cache Types in Magento Magento has the following cache types: Configuration (config) Commerce collects configuration from all modules, merges it, and saves the merged result to the cache. … Read more

Magento 2: Search Repository using SearchCriteriaBuilder, Filter & FilterGroup

This article shows how we can search Magento Repositories using SearchCriteriaBuilder that implements SearchCriteriaInterface. An example is provided of how we can perform search on Product repository in Magento. Similarly, we can search for other entities like Category, Customer, Order, Invoice, CMS Page, CMS Block, etc. We can add different conditions to build custom search … Read more

Magento 2 ElasticSearch: No alive nodes found in your cluster / Types cannot be provided in put mapping requests

Problem: There was the following error related to ElasticSearch / OpenSearch while reindexing the catalogsearch in Magento. bin/magento indexer:reindex catalogsearch_fulltext could not validate a connection to elasticsearch. no alive nodes found in your cluster Another similar error during catalogsearch reindex: bin/magento indexer:reindex catalogsearch_fulltext Catalog Search index process error during indexation process: {"error":{ "root_cause":[{ "type":"illegal_argument_exception", "reason":"Types … Read more

Set up Magento 2 Development Environment with Docker & Warden

Warden is a CLI utility for orchestrating Docker-based developer environments and enables multiple local environments to run simultaneously without port conflicts. docker-compose is used to control everything that Warden runs. Using Warden, a custom environment can be set up for each project. The environment can also be overridden or extended. Warden supports the following applications … Read more

Backup & Restore Magento2 Database using N98-magerun2

n98-magerun is a handy CLI tool to work on Magento from command line. Backup/Dump Database Backup Database in a plain SQL File n98-magerun2.phar db:dump var/projectName_date.sql Print only the MySQL command. Do not execute it. This can be done by using the –only-command option. n98-magerun2.phar db:dump –only-command var/projectName_date.sql You may also use the time command which … Read more

Magento2: Reset Admin 2FA (Two-Factor Authentication)

This article shows how you can reset your Magento 2 Admin User’s 2FA (Two-Factor Authentication). Get your admin user ID from admin_user table. SELECT user_id from admin_user WHERE username = 'YOUR_ADMIN_USERNAME'; OR, SELECT user_id from admin_user WHERE email = 'YOUR_ADMIN_EMAIL'; For e.g. My admin user id = 299 username: MukeshChapagain Check two-factor authentication related table … Read more

Magento 2: ERR_TOO_MANY_REDIRECTS After Importing Database

Problem: Getting 302 redirects (ERR_TOO_MANY_REDIRECTS error) after I imported the server’s database into the local Magento setup. I am getting the redirect error on both backend and frontend. Investigation: I checked for the values for the web/ page in core_config_data table. MariaDB [magento]> SELECT * FROM core_config_data WHERE path LIKE "web/%"; +———–+———+———-+———————————————+——————————+———————+ | config_id | … Read more