1
        $product = Mage::getModel('catalog/product')->loadByAttribute('sku', 'tlb1');
        $invStatus = $product->getResource()->getAttribute('product_inventory_status')->getFrontend()->getValue($product);

I quick log of the $invStatus says that the value is always set to 'No'. Why is this?

2

According to your code,product_inventory_status is not a product attribute.It is not a inventory field.

For getting inventory,please try this.

$product->getStockItem()->getData();

$product->getStockItem()->getData('status');

If loadByAttribute() do not provide data then then you need load product model by id

1
  • Ah, found a solution I'll post later -- thanks anyway Amit! (ps. I had to call load on the model before I could get it's inventory status) :D Mar 17 '15 at 20:00
2

This attribute seems to be unaccessible without first loading the product itself, so below achieves optimal product inventory status accentuation.

- edited for logical and efficient loading

$productSku = 'tlb1';

$product = Mage::registry('product_' . $productSku);
if (!$product) {
    // Load product by sku
    $product = Mage::getModel('catalog/product');
    $product->load($product->getIdBySku($productSku));

    // Put in registry for next load
    Mage::register('product_' . $productSku, $product);

    // Load the attribute and set its data once
    $product->setData('product_inventory_status_value', $product->getResource()
        ->getAttribute('product_inventory_status')
        ->getFrontend()
        ->getValue($product));
}

// Here is the data for re-use
$invStatus = $product->getData('product_inventory_status_value');
1
  • 1
    This is a slow load, you load the product fist(but not fully) and do the same again by your load() (which is also incorrect because you need to give the id to load. catalog/product has a extra method ->getIdBySky('tlb1)` which is a lot faster. Also if you need the data more than once, be sure to put the product in Mage::registry
    – Jeroen
    Mar 19 '15 at 20:06

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.