Skip to content

Instantly share code, notes, and snippets.

@yireo
Created April 9, 2016 07:29
Show Gist options
  • Save yireo/b41ce88e51eb33e36a7b2c30a266823c to your computer and use it in GitHub Desktop.
Save yireo/b41ce88e51eb33e36a7b2c30a266823c to your computer and use it in GitHub Desktop.
Magento function to fetch Magento product SKU by ID
<?php
function getSkuById($productId)
{
$productResourceModel = Mage::getResourceModel('catalog/product');
$adapter = Mage::getSingleton('core/resource')->getConnection('core_read');
$select = $adapter->select()
->from($productResourceModel->getEntityTable(), 'sku')
->where('entity_id = :entity_id');
$bind = array(':entity_id' => (string)$productId);
$productSku = $adapter->fetchOne($select, $bind);
return $productSku;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment