2

I'm logging a bunch of stuff in our database. Is there a quick and easy way to check if a SKU exists or not? This way I can remove anything malformed from our import process.

13
$sku = 'sku here';
$id = Mage::getModel('catalog/product')->getIdBySku($sku);
if (false !== $id) {
   //sku exists
}
else {
   //sku does not exist
}
  • Really? Yoda conditions? – Giel Berkers Feb 24 '17 at 13:56
  • Wrong with it what is? In my defense it was just if($id) when I wrote it. – Marius Feb 24 '17 at 14:15
  • Well then, my apologies you have. Strange I find it. Hard for the eyes it is. Yes. – Giel Berkers Feb 24 '17 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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