'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}} <= ?"
Category: Magento
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:
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:
user_pass
column will have this kind data from Magento2dcbdc524f215fd054502dcad5a23a702ec029c02ff8d7051d049f76e29927f8b:C8yVqeuPfkHWvkmipx0iKLPtOUGETpLL:1
usermeta
table must have ameta_key
“migrated_cs” for this user,meta_value
can be anything positive- 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.
Convert dropdown attribute to text swatch in Magento2 Admin Panel
Run the following code in console:
$=new jQuery.noConflict();
$("#swatch-text-options-panel tr td:nth-child(4) input").each(function (e,el) {
$(this).parent().parent().find("td:nth-child(3) input").val($(this).val());});
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:
How to wipe all the tables and data in MySQL? Clean whole database
SET FOREIGN_KEY_CHECKS = 0;
SET GROUP_CONCAT_MAX_LEN=32768;
SET @tables = NULL;
SELECT GROUP_CONCAT('`', table_name, '`') INTO @tables
FROM information_schema.tables
WHERE table_schema = (SELECT DATABASE());
SELECT IFNULL(@tables,'dummy') INTO @tables;
SET @tables = CONCAT('DROP TABLE IF EXISTS ', @tables);
PREPARE stmt FROM @tables;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
SET FOREIGN_KEY_CHECKS = 1;
Will not work via phpmyadmin or any script. this has to be run in cmd/terminal
Quick Command
wget https://gist.githubusercontent.com/harshvardhanmalpani/e670a8de7aa81673364dd48f125cb9ac/raw/ce04b319bf1594d148d3346e1474119fe1cd1b3f/flushdb.sql
mysql -hYOUR_DATABASE_HOSTNAME -uYOUR_DATABASE_USER -p YOUR_DATABASE_NAME < flushdb.sql
Source:
https://gist.github.com/harshvardhanmalpani/e670a8de7aa81673364dd48f125cb9ac