Get list of simple products which don't belong to a configurable
-
15-04-2021 - |
Question
What is the best way to get a list of simple products which don't belong to a configurable?
I have a shop with mostly simple products which belong to a parent/configurable product. But some of the products (eg. jewellery) don't have options so they've been set up as lone simple products.
Ps this is for my own usage only so any solution that provides the right results will do :) thanks
Solution
Thomas,Magento did not provide this type on function,So without any coding or MySQL Query,you can not get the solution.
Mysql: Magento save the relation between configurable product and it child products
at catalog_product_super_link
and save it product basic data at catalog_product_entity
Table.
Write select query with select type_id=simple
simple product and check that product id exit
at catalog_product_super_link
table product_id.
columns.
For getting Simple products that are not associated with a configurable
SELECT * FROM `jsw_catalog_product_entity` where entity_id
not in (SELECT product_id FROM `jsw_catalog_product_super_link`) and type_id='simple'
OTHER TIPS
Tested in Magento Commerce 2.4.1
This will give you a list of simple products that don't have any parent/child mapping with a configurable product, using a simple left join.
select * from catalog_product_entity e
left join catalog_product_super_link sl on sl.product_id = e.row_id
where sl.product_id is null
and e.type_id = 'simple';
Similarly...
This will give the configurable products with no child assigned.
select *, count(sl.parent_id)
from catalog_product_entity e
left join catalog_product_super_link sl on sl.parent_id = e.row_id
where e.type_id = 'configurable'
group by sl.parent_id
having count(sl.parent_id) = 0;
Note: catalog_product_super_link
table keeps the relationship of the parent to child for configurable products and it uses the row_id
field to map, NOT the entity_id
.