tags:

views:

21

answers:

1

We have a custom attribute that our previous developer (recently disappeared) has created in the magento admin area. This is a getIn_stock attribute which is reading from the point of sale system to check stock levels. It is returning either a 1 (in stock) or a 0 (out of stock). I have been digging around to see how I can display different content based on the output of this attribute. I found a thread that was based on the product price equaling 0 and tried to use it on the getIn_stock attribute but no luck. The following displays 'In Stock' even if the attribute returns a value of 0.

<?php if($_product->getIn_stock==0): ?>
                <?php echo 'Out of stock'; ?>
<?php else: ?>
<p>In Stock</p>
<?php endif; ?>

Any advice would be a great help. Thank you in advance :)

+1  A: 

put var_dump($_product->getIn_stock); right before your if() clause and see what actual value is in the property.

zerkms
<?php var_dump($_product->getIn_stock); ?> outputs NULL on all products BUT <?php echo $_product->getIn_stock(); ?> displays a 0 on out of stock items and 1 on in stock items.
Jackson
`$_product->getIn_stock` or `$_product->getIn_stock()`?? Btw, just change to `if (!$_product->getIn_stock()):`
zerkms
Shouldn't it be in camel case? `$_product->getInStock()`
clockworkgeek
@clockworkgeek: to be honest - i've no idea ;-) thanks god i never worked with magento ;-)
zerkms
Thank you very much. Could you point me in a good direction of a php resource that can help me learn in this context. Most of the sites I have found are extremely difficult to follow.
Jackson
In what context? `!` operator and `var_dump()` are the basic instructions in php and well described in documentation.
zerkms