How can we check Bulk SKUs(in custom DB table) against existing Product SKUs , and if SKU from custom table is not present in product collection than need to create a product with that SKU.

What currently I am doing is looping and checking, but this seems is'nt a good approach.

Any other way of doing this more efficiently ?

$feed_products = Mage::getModel('custom_module/customproduct')->getCollection();

$existing_products = Mage::getModel('catalog/product')->getCollection();

foreach ($feed_products as $part) {

    $id = Mage::getModel('catalog/product')->getIdBySku($part['sku']);

    if ($id) {
        //echo 'Exists'.$part['sku'].'<br>';
        //no Action
    } else {
        echo 'Doesnot Exists'.$part['sku'].'<br>';

1 Answer 1


You can go like this.

$feed_products = Mage::getModel('custom_module/customproduct')->getCollection();
$skuArray = array();
foreach ($feed_products as $part) {
    $skuArray[] = $part['sku'];

Now you have your SKUs from feed in an array. On the basis of that array, Existing products can be obtained with :

$existing_products = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('sku', ('in' => $skuArray));

And, non-existing products can be obtained via :

$not_existing_products = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToFilter('sku', ('nin' => $skuArray));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.