Magento addAttributeToFilter different Condition types.

In Magento There are many conditions to filter specific collection using addAttributeToFilter or addFieldToFilter function.

In Development time you have faced issue related to collection filter based on your requirement you can use below set of conditions in your coding for filter of a collection.  Syntax: addFieldToFilter($field, $condition = null)

Where $field is your table field name.
$condition is your below list of sql condition. Second parameter is string or array.

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

Example:

$product = $this->productFactory->create()->getCollection()
->addAttributeToFilter('sku', ['eq' => '24-MB01']);

You can use any field type from above to filter your query.

How to import tier pricing-advanced price using csv in Magento 2?

In Magento 2 Import tier pricing is such a simple way.
You need to Create CSV file for import advanced pricing in Magento 2 sometimes Tier price is called as Advanced Pricing.

Tier price is used when you want to give discount on bulk purchase of product whether based on customer group, based on Quantity you purchase.

Go To Admin panel in Magento 2,
Click On System from Left Menu,
System -> Import -> Import Settings -> Advanced Pricing
Select Import Behaviour as Add/Update for first time pricing import for a product,

Below is column name for tier price import CSV
sku Product SKU
tier_price_website Website Code (Default ALL Website)
tier_price_customer_group Customer Group
tier_price_qty No. of Quantity to purchase for getting discount on a price
tier_price_value_type tier price value fixed/discount of the actual price

Download  Tier price CSV for demo, Tier Price CSV

If you want to replace old value of tier price with New You have to select Replace field from Import behavior in Import Tier price section from Admin panel otherwise price value will be added again for product.

Check Default Behaviour of Product import for Add, Replace and Delete function for Product import behavior.

If you don’t know about Import simple product refer link,Import Simple Product Using CSV Magento 2

Direct SQL Query in Magento 2

There are many situations where executing direct raw SQL queries would be simple and much quicker leading to a more optimized Magento get collection query as a performance basis.

On a large data set of an entity, Saving each individual entity can take a long time with resource-hungry and therefore make the system unusable.

Overcome this issue it is possible to issue a direct SQL query that could update a large set of data of an entity in fewer seconds.

When you use Direct SQL Query you don’t need to worry about Model/Factory Pattern. Continue reading “Direct SQL Query in Magento 2”