How to speed up slow Magento indexer process? Maria DB 10.4

Category Products index taking too much time?

bin/magento index:reset

bin/magento index:reindex

Stuck at category products index …

Here is the solution if you are using MariaDB 10.4

You need to update options/parameters for your db. If using RDS, edit “DB instance parameter group” that you are using and update these 2 values:

optimizer_switch='rowid_filter=off'
optimizer_use_condition_selectivity = 1



After these changes, restart your database. In aws, RDS automatically updates these parameters without any downtime or requirement for restarting. You will see noticeable difference in indexer time.

Reference:

https://devdocs.magento.com/guides/v2.4/performance-best-practices/configuration.html

https://devdocs.magento.com/guides/v2.4/extension-dev-guide/indexer-batch.html

https://magento.stackexchange.com/a/336816/32283

Condition types for addAttributeToFilter in Magento2 Collections

'eq'            => "{{column}} = ?",
'finset'        => "FIND_IN_SET(?, {{column}})",
'from'          => "{{column}} >= ?",
'gt'            => "{{column}} > ?",
'gteq'          => "{{column}} >= ?",
'in'            => "{{column}} IN(?)",
'is'            => "{{column}} IS ?",
'like'          => "{{column}} LIKE ?",
'lt'            => "{{column}} < ?",
'lteq'          => "{{column}} <= ?",
'neq'           => "{{column}} != ?",
'nin'           => "{{column}} NOT IN(?)",
'nlike'         => "{{column}} NOT LIKE ?",
'notnull'       => "{{column}} IS NOT NULL",
'ntoa'          => "INET_NTOA({{column}}) LIKE ?",
'null'          => "{{column}} IS NULL",
'regexp'        => "{{column}} REGEXP ?",
'seq'           => null,
'sneq'          => null,
'to'            => "{{column}} <= ?"

How to fix Magento2 apis not working? fix coupon apis and other PUT OPTIONS APIs

The issue is actually related to your server’s configuration. By default all types of requests are not allowed. Please add the following to your .htaccess file

<Limit GET POST OPTIONS PUT DELETE PROPFIND>
    Order allow,deny
    Allow from all
    Require all granted
</Limit>

How to fix Invalid template file error in Magento2 after version upgrade?

This is a very common issue you will face if you using windows machine for development.

Usual error message is:

Invalid template file: '/vendor/magento/module-theme/view/frontend/templates/page/js/require_js.phtml' in module: '' block's name: 'require.js'

So whats the solution?

In case of windows, just replace this function isPathInDirectories in vendor/magento/framework/view/element/template/file/validator.php

protected function isPathInDirectories($path, $directories)
{
    $realPath = str_replace('\\', '/', $this->fileDriver->getRealPath($path));
    if (!is_array($directories)) {
        $directories = (array)$directories;
    }

    foreach ($directories as $directory) {
        if (0 === strpos($realPath, $directory)) {
            return true;
        }
    }
    return false;
}

Reference:

https://magento.stackexchange.com/a/255585/32283

How to update customer password in Magento 2 database?

UPDATE `customer_entity`
SET `password_hash` = CONCAT(SHA2('SaltPASSWORD', 256), ':SALT:1')
WHERE `entity_id` = 7615;

Please note that if SPJ9WIp7 is the salt and User’s password is 7qLzX33ETxYE, the following will be your query:

UPDATE `customer_entity`
SET `password_hash` = CONCAT(SHA2('SPJ9WIp77qLzX33ETxYE', 256), ':SPJ9WIp7:1')
WHERE `entity_id` = 7615;

7615 is the customer id

Installing a testing instance for Magento CLI only

Prerequisite:

  • Magento repo access keys
  • Mysql Database, username and password
  • a domain name pointing to a server

if you dont have access key, get a pair here :

https://marketplace.magento.com/customer/accessKeys/

php -d memory_limit=-1 /bin/composer create-project --repository-url=https://repo.magento.com/ magento/project-community-edition=2.2.11 ./

In the above command, you can change version/subversion of magento repo. You can also change the install directory

After the successful run of above command:

bin/magento setup:install \
--base-url=https://testmagento.domain.com \
--db-host=localhost \
--db-name=testmage_x1 \
--db-user=testmage_x1 \
--db-password=WEux3dxxxxw \
--admin-firstname=xxx \
--admin-lastname=yyy \
[email protected] \
--admin-user=admin \
--admin-password=WwKhxxxxxxEK \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1



YOu will see Magento Admin URI: /admin_10lf7y after successful run

Next is installing sample data: totally optional

php -d memory_limit=-1 bin/magento sampledata:deploy

OPtional: install or update composer version

composer self-update --2

https://blog.packagist.com/composer-2-0-is-now-available/
https://getcomposer.org/

How to migrate Customers from Magento2 to WordPress?

Lets break it into 2 parts:

a. Migrate Customer data
b. Migrate Customer Passwords

1) Migrate Customer Data from Magento2 to WordPress

This is rather easy to be honest, there are several plugins for importing data from CSV and then mapping the CSV fields.

My recommended plugin is Customer/Order/Coupon CSV Import Suite by SkyVerge

It basically does everything from customer email to customer address data. It also provides column mapping and custom attribute import for all users. Also comes with multiple configuration options.

Best Free Alternative is https://wordpress.org/plugins/import-users-from-csv-with-meta
But in this one, you can not import magento2 passwords as of v 1.15.0.1
I will update about the solution very soon. So as of now only paid option is there.

2) Migrate Customer Password from Magento2 to WordPress

This wordpress plugin checks and updates passwords of users migrated from Magento2 to WordPress
Plugin Link: https://github.com/harshvardhanmalpani/migrate-password-from-magento2-to-wordpress

Requirements:

  1. user_pass column will have this kind data from Magento2 dcbdc524f215fd054502dcad5a23a702ec029c02ff8d7051d049f76e29927f8b:C8yVqeuPfkHWvkmipx0iKLPtOUGETpLL:1
  2. usermeta table must have a meta_key “migrated_cs” for this user, meta_value can be anything positive
  3. This plugin file password-migrator.php should be in wp-content/plugins and must be an active plugin

What is does?

For new wordpress based users which dont have anything to do with magento2, it doesnt do anything

For all migrated users (those have the key “migrated_cs”), this plugin checks if input password matches old password from magento2 or not, if matched, it clears the key migrated_cs and updates the password using wordpress’ algorithm ; else results false.

How to change attribute dropdown type to multi-select in Magento 2?

Short Answer:

Not possible via Magento2 Admin Backend.

Solution:

You need to update eav_attribute table and edit information about backend_source, frontend_input etc.

Simple query for that is:

UPDATE `eav_attribute` SET `backend_model`="Magento\\\Eav\\\Model\\\Entity\\\Attribute\\\Backend\\\ArrayBackend", `backend_type`="varchar", `frontend_input`="multiselect", `source_model`=NULL WHERE `attribute_id`=YOUR_ATTRIBUTE_ID_INTEGER LIMIT 1

Replace YOUR_ATTRIBUTE_ID_INTEGER with your attribute_id like 355

Reference:

https://stackoverflow.com/a/57701845/2229148

How to disable products in Magento2 which dont have any gallery image?

UPDATE `catalog_product_entity_int` SET `value`=2 where `entity_id` in (SELECT a.`entity_id` FROM `catalog_product_entity` AS a LEFT JOIN `catalog_product_entity_media_gallery_value` AS b ON a.entity_id = b.entity_id LEFT JOIN `catalog_product_entity_media_gallery` AS c ON b.value_id = c.value_id WHERE c.value IS NULL) and `attribute_id` = 96

It is SQL query

Assumption:

value=2 means disable and value=1 means enable

attribute_id=96 means “status” attribute

References:

https://gist.github.com/tegansnyder/8464261#gistcomment-2910808

https://magento.stackexchange.com/a/83033/32283