If the category is an anchor category, it is not enough to check if the id (10) is assigned to the product, you also have to check if a child category is assigned to the product.
But we do not need to do this manually, we can use the product collection which will determine which products belong to the category based on anchor settings:
$shoeCategory = Mage::getModel('catalog/category')->load(10);
$productCollection = $shoeCategory->getProductCollection()
->addIdFilter($_product->getId());
if ($productCollection->getSize() === 1) {
?> Please call for best price <?php
}
By using getSize()
the collection is not loaded but only a single SELECT COUNT
query is executed.
On an unrelated note: the following line is unnecessarily complicated and error-prone:
<?php if($_product->getAttributeText('priceless') == $this->__('Yes')): ?>
Compare the internal value instead:
<?php if($_product->getData('priceless')): ?>
I assume that "priceless" has the source model eav/entity_attribute_source_boolean
, which has the values 0 and 1 for "yes" and "no". If not, I recommend to change it, it's not too late as long as all values are "yes".