Magento – Get all products that has special price and special price < price

collection;magento-2.0magento2priceproduct-collection

I want to get all products that has special price and special price < price.

Can anyone show me how can i achieve that ?

enter image description here

Best Answer

The best way I can think of doing this is via an SQL statement

SELECT cpeid1.entity_id, cpeid1.value as price, cpeid2.value as special_price FROM catalog_product_entity_decimal cpeid1 LEFT JOIN catalog_product_entity_decimal cpeid2 ON (cpeid1.entity_id = cpeid2.entity_id AND cpeid2.attribute_id = 76) WHERE cpeid1.attribute_id = 75 AND cpeid2.value IS NOT NULL ;

Where 75 = price attribute id and 76 = special_price attribute id (from the eav_attribute table)

Related Topic