Some of our products have special prices for different groups, i have set up these prices in magento front end. I just need to know how to get a group price or check if a product has one.
I have this line which checks if a customer is logged in:
<?php
//Check if User is Logged In
$login = Mage::getSingleton('customer/session')->isLoggedIn();
if ($login) {
}
So i assume it will be similar but i just do not what to change or what to change it to. if i havnt explained this very well please let me know.
Added code
<?php
//Check if User is Logged In
$login = Mage::getSingleton('customer/session')->isLoggedIn();
if ($login) {
//Get Customers Group ID
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();
if ($groupId == 5) {
$group_price = Mage::getModel('catalog/product')->getGroupPrice();
if ($group_price) {
?>
<span class="price-label"><?php echo "Special Group Price " ?></span><?php
}
}
} else { ?>
<span class="price-label"><?php echo "Now" ?></span>
<?php } ?>
Best Answer
You can check group price by
getGroupPrice()
function of product object. It is not null that means group price exits in product.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:Modified code is:
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:or when you fetch product Collection and get each product by looped by product object id.