How to ignore address validation error in Magento 2?

You can ignore address validation for shipping and billing address when you create address programmatically or sometimes you don’t need to worry about validation for billing or shipping address.

Make sure addresses will be saved without validation errors, You need to use setShouldIgnoreValidation(true) function on quote object. Continue reading “How to ignore address validation error in Magento 2?”

Customer Logged in Programmatically using Magento 2.

You can do customer logged in Programmatically using Magento 2.

You required only Customer id to logged-in customer programmatically without going to the login page.

You need to first get Customer object using CustomerRepositoryInterface interface. Use Customer Object to customer session with setCustomerDataAsLoggedIn function. Continue reading “Customer Logged in Programmatically using Magento 2.”

How to use insertOnDuplicate query in Magento 2.

Use of insertOnDuplicate query using Magento 2,  You need to create a Connection object first to run the query using ResourceConnection class.

When you insert any new row into a table if the row causes a duplicate in the Primary key or UNIQUE index, throw an error in MySQL.

Base Definition of function:

/**
 * Inserts a table row with specified data.
 *
 * @param mixed $table The table to insert data into.
 * @param array $data Column-value pairs or array of column-value pairs.
 * @param array $fields update fields pairs or values
 * @return int The number of affected rows.
 */
public function insertOnDuplicate($table, array $data, array $fields = []);

Example,
Continue reading “How to use insertOnDuplicate query in Magento 2.”