Magento – How to get tier price in products category

magento-1.7tierprice

In my shop I have tier prices for some products. And what I am trying to do is if the customer is logged in I want to display them tier price in products category instead of regular price.

In catalog/product/price.phtml currently I am having this:

<?php if(Mage::getSingleton('customer/session')->isLoggedIn()):
    $groupId = Mage::getSingleton('customer/session')->getCustomerGroupId();

    $prod = $this->getProduct();
    $tierPrice = $prod->getPriceModel()->getFinalPrice($groupId, $prod);
    var_dump($tierPrice);
    die();
?>

But the tier price is wrong (I am getting 60). So I dump (var_dump($prod)) the product object to see what's wrong. And this is what I get (here the tier price is correct):

object(Mage_Catalog_Model_Product)#1158 (32) { ["_cacheTag":protected]=> string(15) "catalog_product" ["_eventPrefix":protected]=> string(15) "catalog_product" ["_eventObject":protected]=> string(7) "product" ["_canAffectOptions":protected]=> bool(false) ["_typeInstance":protected]=> NULL ["_typeInstanceSingleton":protected]=> object(Mage_Catalog_Model_Product_Type_Simple)#435 (9) { ["_product":protected]=> NULL ["_typeId":protected]=> NULL ["_setAttributes":protected]=> NULL ["_editableAttributes":protected]=> NULL ["_isComposite":protected]=> bool(false) ["_canConfigure":protected]=> bool(false) ["_canUseQtyDecimals":protected]=> bool(true) ["_storeFilter":protected]=> NULL ["_fileQueue":protected]=> array(0) { } } ["_linkInstance":protected]=> NULL ["_customOptions":protected]=> array(0) { } ["_urlModel":protected]=> object(Mage_Catalog_Model_Product_Url)#672 (7) { ["_data":protected]=> array(0) { } ["_hasDataChanges":protected]=> bool(false) ["_origData":protected]=> NULL ["_idFieldName":protected]=> NULL ["_isDeleted":protected]=> bool(false) ["_oldFieldsMap":protected]=> array(0) { } ["_syncFieldsMap":protected]=> array(0) { } } ["_errors":protected]=> array(0) { } ["_optionInstance":protected]=> NULL ["_options":protected]=> array(0) { } ["_reservedAttributes":protected]=> NULL ["_isDuplicable":protected]=> bool(true) ["_calculatePrice":protected]=> bool(true) ["_defaultValues":protected]=> array(0) { } ["_storeValuesFlags":protected]=> array(0) { } ["_lockedAttributes":protected]=> array(0) { } ["_isDeleteable":protected]=> bool(true) ["_isReadonly":protected]=> bool(false) ["_resourceName":protected]=> string(15) "catalog/product" ["_resource":protected]=> NULL ["_resourceCollectionName":protected]=> string(26) "catalog/product_collection" ["_dataSaveAllowed":protected]=> bool(true) ["_isObjectNew":protected]=> NULL ["_data":protected]=> array(40) { ["entity_id"]=> string(5) "16214" ["entity_type_id"]=> string(2) "10" ["attribute_set_id"]=> string(1) "9" ["type_id"]=> string(6) "simple" ["sku"]=> string(4) "A155" ["created_at"]=> string(19) "2013-10-14 22:28:27" ["updated_at"]=> string(19) "2014-05-02 13:48:22" ["has_options"]=> string(1) "0" ["required_options"]=> string(1) "0" ["relevance"]=> string(6) "1.0000" ["price"]=> string(7) "60.0000" ["tax_class_id"]=> string(1) "0" ["final_price"]=> float(60) ["minimal_price"]=> string(7) "39.0000" ["min_price"]=> string(7) "60.0000" ["max_price"]=> string(7) "60.0000" **["tier_price"]=> string(7) "39.0000"** ["cat_index_position"]=> string(6) "850001" ["name"]=> string(60) " ISO lizdas 36 pin-4RCA lizdai,CD grot. jungtis -ISO 21051 " ["small_image"]=> string(18) "/i/m/image_508.jpg" ["url_key"]=> string(55) "iso-lizdas-36-pin-4rca-lizdai-cd-grot-jungtis-iso-21051" ["thumbnail"]=> string(18) "/i/m/image_508.jpg" ["image_label"]=> string(4) "A155" ["small_image_label"]=> string(4) "A155" ["thumbnail_label"]=> string(4) "A155" ["msrp_enabled"]=> string(1) "2" ["msrp_display_actual_price_type"]=> string(1) "4" ["special_price"]=> NULL ["msrp"]=> NULL ["status"]=> string(1) "1" ["short_description"]=> string(60) " ISO lizdas 36 pin-4RCA lizdai,CD grot. jungtis -ISO 21051 " ["special_from_date"]=> NULL ["news_from_date"]=> NULL ["news_to_date"]=> NULL ["special_to_date"]=> NULL ["request_path"]=> string(60) "iso-lizdas-36-pin-4rca-lizdai-cd-grot-jungtis-iso-21063.html" ["is_salable"]=> string(1) "1" ["stock_item"]=> object(Varien_Object)#1155 (7) { ["_data":protected]=> array(1) { ["is_in_stock"]=> string(1) "1" } ["_hasDataChanges":protected]=> bool(false) ["_origData":protected]=> NULL ["_idFieldName":protected]=> NULL ["_isDeleted":protected]=> bool(false) ["_oldFieldsMap":protected]=> array(0) { } ["_syncFieldsMap":protected]=> array(0) { } } ["group_price"]=> array(0) { } ["group_price_changed"]=> int(0) } ["_hasDataChanges":protected]=> bool(true) ["_origData":protected]=> NULL ["_idFieldName":protected]=> string(9) "entity_id" ["_isDeleted":protected]=> bool(false) ["_oldFieldsMap":protected]=> array(0) { } ["_syncFieldsMap":protected]=> array(0) { } }

So how should I get tier price value 39 instead of 60 ?

Thanks in advance.

Best Answer

Maybe you try to get a group price. If you want to get the tier price (http://www.magentocommerce.com/knowledge-base/entry/tier-pricing)

you should call

$prod->getTierPrice($qty);

$qty is null will return the FinalPrice instead.

reference Model -> Product

public function getTierPrice($qty=null)