Skip to content

Instantly share code, notes, and snippets.

@odahcam
Last active October 5, 2018 22:32
Show Gist options
  • Save odahcam/bd77f3f4321f1d377bce2544689eec11 to your computer and use it in GitHub Desktop.
Save odahcam/bd77f3f4321f1d377bce2544689eec11 to your computer and use it in GitHub Desktop.
Function to retrieve a product SKU based on it's ID on Magento (1.8) platform.
<?php
include_once '../app/Mage.php';
/**
* @author odahcam
*
* @version 1.0.0
*
* @param {string|int} $product_id
*
* @return {string}
**/
function getSkuById($product_id)
{
$adapter = Mage::getSingleton('core/resource')->getConnection('core_read');
$select = $adapter
->select()
->from(Mage::getResourceModel('catalog/product')->getEntityTable(), 'sku')
->where('entity_id = :entity_id');
return $adapter->fetchOne($select, [':entity_id' => (string) $product_id]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment