You can check group price by getGroupPrice()
function of product object. It is not null that means group price exits in product.
$product = Mage::getModel('catalog/product')->load($productId);
if (!is_null($product->getGroupPrice())) {
//group price h
}
Magento have apply group price as price when Product price is greater then product group price
You cannot easy got group price. You need load product attribute resource value using getResource()->getAttribute('group_price')
:
Edit: if you have $product
object of product then you can get Group price using below code:
$groupPrices = $ProductObject->getData('group_price');
if (is_null($groupPrices)) {
$attribute = $ProductObject->getResource()->getAttribute('group_price');
if ($attribute) {
$attribute->getBackend()->afterLoad($ProductObject);
$groupPrices = $ProductObject->getData('group_price');
}
}
if (!is_null($groupPrices) || is_array($groupPrices)) {
foreach ($groupPrices as $groupPrice) {
echo "<br/>";
echo $Groupprice = $groupPrice['website_price'];
echo "<br/>";
echo $Groupprice = $groupPrice['cust_group'];
}
}
Modified code is:
<?php
//Check if User is Logged In
$login = Mage::getSingleton('customer/session')->isLoggedIn();
if ($login && Mage::getSingleton('customer/session')->getCustomerGroupId() == 5) {
$groupPrices = $ProductObject->getData('group_price');
$Groupprice = $groupPrices;
if (is_null($groupPrices)) {
$attribute = $ProductObject->getResource()->getAttribute('group_price');
if ($attribute) {
$attribute->getBackend()->afterLoad($ProductObject);
$groupPrices = $ProductObject->getData('group_price');
}
}
/* check group price exit nor not */
if (!is_null($groupPrices) || is_array($groupPrices)) {
foreach ($groupPrices as $groupPrice) {
if ($groupPrice['cust_group'] == Mage::getSingleton('customer/session')->getCustomerGroupId()) {
echo $Groupprice = $groupPrice['website_price'];
echo "<br/>";
echo $GroupIds = $groupPrice['cust_group'];
break;
}
}
}
/* $Groupprice is null mean group price is not exit*/
if (!is_null($Groupprice)) {
//group price eixts
?>
<span class="price-label"><?php echo "Special Group Price " ?></span>
<?php
} else {
//Group price is exits.
?>
<span class="price-label"><?php echo "Now" ?></span>
<?php }
?>
<?php } else { ?>
<span class="price-label"><?php echo "Now" ?></span>
<?php } ?>
Issue: $group_price = Mage::getModel('catalog/product')->getGroupPrice();
is wrong code, It don't give group price.
You can product group price if you load Mage::getModel('catalog/product')
by product is $group_price = Mage::getModel('catalog/product')->load($product)->getGroupPrice();
Mage::getModel('catalog/product')->getGroupPrice()
did not give product object. You can get product object by:
Mage::getModel('catalog/product')->load($productId);
or when you fetch product Collection and get each product by looped by product object id.