Is there any way to show the group price instead of regular price all time?
-
28-02-2021 - |
Question
I am using Magento 1.9.3
For your convenience I am explaining with example:
Lets imagine two products.
Product1
Regular Price : 50
Group Price : 55
Product2
Regular Price : 60
Group Price : 55
When Regular Price is lower than Group Price it showing Regular Price.
Again when Regular Price is higher than Group Price it showing Group Price.
Always showing lower price.
For product1: 50 < 55 getting 50
For product2: 55 > 60 getting 55
But in both case I need to show the price: 55 (Group Price)
Can I do that?
Solution
You need to modify _applyGroupPrice and getBasePrice method.
app/code/core/Mage/Catalog/Model/Product/Type/Price.php
Overwrite this class and remove min function from there.
[Update]
Overwrite config:
<global>
<models>
<catalog>
<rewrite>
<product_type_price>SR_MagentoCommunity_Model_Product_Type_Price</product_type_price>
</rewrite>
</catalog>
</models>
</global>
app/code/local/SR/MagentoCommunity/Model/Product/Type/Price.php
<?php
class SR_MagentoCommunity_Model_Product_Type_Price extends Mage_Catalog_Model_Product_Type_Price
{
public function getBasePrice($product, $qty = null)
{
$price = (float)$product->getPrice();
$groupPrice = $product->getGroupPrice();
if (is_numeric($groupPrice) && $groupPrice && ($groupPrice != $price)) {
return $groupPrice;
}
return parent::getBasePrice($product, $qty);
}
/**
* Get product group price
*
* @param Mage_Catalog_Model_Product $product
* @return float
*/
public function getGroupPrice($product)
{
$groupPrices = $product->getData('group_price');
if (is_null($groupPrices)) {
$attribute = $product->getResource()->getAttribute('group_price');
if ($attribute) {
$attribute->getBackend()->afterLoad($product);
$groupPrices = $product->getData('group_price');
}
}
if (is_null($groupPrices) || !is_array($groupPrices)) {
return $product->getPrice();
}
$customerGroup = $this->_getCustomerGroupId($product);
$matchedPrice = 0;
foreach ($groupPrices as $groupPrice) {
if ($groupPrice['cust_group'] == $customerGroup) {
$matchedPrice = $groupPrice['website_price'];
break;
}
}
return $matchedPrice;
}
}