0

How to load only a specific attribute instead of loading all attributes in magento 1.9? I'm using the code below, but it loads all the information and I just need the product ID.

Mage::getModel('catalog/product')->loadByAttribute('sku', $_customOptions['simple_sku']);
1
  • Did you try with addAttributeToSelect("*")?
    – S.P
    Apr 22 at 16:59

2 Answers 2

0

Try below code,

$sku = 'some-sku';
$productId = Mage::getModel('catalog/product')->getIdBySku($sku);

Thanks & Regards,

0

If you want to return entity id from sku then magento have already function

getIdBySku($sku) for it.

Ex.

$sku = 'some-sku';
$productId = Mage::getModel('catalog/product')->getIdBySku($sku);
if($productId){
echo "your product id" . $productId;   
}

You can also get single column value with getColumnvalues. may be it would return with array format.

Ex.

$productCollection->getColumnValues('entity_id');

Magento also provide reset for select only specific field.

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->getSelect()->reset(Zend_Db_Select::COLUMNS)->columns(array('entity_id'));

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.