How many price types available in Magento 2.x.x
How it can be loaded on the checkout page?
What is the difference between group price and tier price in Magento 2
1 Answer
There are total of 6 types of prices available in Magento2 listed as below:
- Special Price
- Tier Price
- Grouped Price
- The minimum price of composite
- products Price range of composite products
- Manufacturer price (MSRP)
Magento represents these prices as price types (e.g. final price, minimum price, maximum price, regular price) and is separate from the actual price in the code. For example, Special Price is represented by the final price type in the code.
If you want this price values on checkout page then you need to write foreach loop code for each item added into the cart and then you can get its various kind prices for each individual item as below:
Get Simple Price values:
$finalPrice = $item->getProduct()->getFinalPrice();
$regularPrice = $item->getProduct()->getPrice();
$specialPrice = $item->getProduct()->getSpecialPrice();
Get Group/Tier Price values:
First create block file to define getTierPrice() function:
namespace Namespace\TierPrice\Block;
use Magento\Catalog\Api\Data\ProductTierPriceInterface;
use Magento\Catalog\Api\ScopedProductTierPriceManagementInterface;
class TierPrice extends \Magento\Framework\View\Element\Template
{
/**
* @var ScopedProductTierPriceManagementInterface
*/
private $tierPrice;
public function __construct(
ScopedProductTierPriceManagementInterface $tierPrice
) {
$this->tierPrice = $tierPrice;
}
/**
* Get Tier price by the customer group
*
* @return ProductTierPriceInterface[]
*/
public function getTierPrice($sku, $customerGroupId=1)
{
return $this->tierPrice->getList($sku, $customerGroupId);
}
}
Then you can get tier price value in its associated phtml file by calling block function as below:
$tierPrices = $block->getTierPrice($sku, $customerGroupId);
There is a very thin difference between the group prices and tier prices. Customer group prices are a component of tier pricing and are set up in a similar way. The only difference is that customer group prices have a quantity of 1.
I hope this helps you to understand the fundamentals of magento2 price types.
If you have any further query feel free to ask.
Happy to help!
Thanks.
-
1