Adam B
Adam B

Reputation: 554

Getting Special Price on default selection for bundle in Magento

So I've been trying for a little bit to get this working but no luck and nothing I could find online seemed to solve the issue. Right now I have code that changes the pricing in bundle products dropdown selection to show the differential price rather than the absolute price so you can see the price difference between the default selection and the other options:

File: app/code/local/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php

public function getSelectionTitlePrice($_selection, $includeContainer = true)
{
$defaultPrice = 0.00;
$_product = $this->getProduct();


$_mbmo = new Mage_Bundle_Model_Option();
$_mbmo->load($_selection->getProductId());
$_default = $_mbmo->getDefaultSelection();
if (gettype($this->getOption()->getDefaultSelection())==object){
$defaultPrice=$this->getOption()->getDefaultSelection()->getFinalPrice();

}

$price = $_product->getPriceModel()->getSelectionFinalPrice($_product, $_selection, 1);

if ($price == $defaultPrice)
{
    return $_selection->getName();
}
else
{
    $sign = ($price < $defaultPrice) ?  '-' : '+';
    $diff = ($price < $defaultPrice) ? $defaultPrice - $price : $price - $defaultPrice;
    return $_selection->getName() . ' &nbsp; ' .
        ($includeContainer ? '<span class="price-notice">':'') . $sign .
        $this->formatPriceString($diff, $includeContainer) . ($includeContainer ? '</span>':'');
}
}

The code successfully gets the FinalPrice via getSelectionFinalPrice() for the other options in the dropdown menu but for the default selection getFinalPrice() doesn't work (it just gives me the normal price). How do I change it to give me the price after the special price discount is applied? I've tried a few other functions like getSpecialPrice() but nothing seems to work!

Thanks!

Upvotes: 0

Views: 1927

Answers (1)

Adam B
Adam B

Reputation: 554

Was able to solve this myself after a lot of tinkering.

Basically I check to see if there is a special price percentage and then if there is I apply it to the default price. This is a workaround because it looks like because all the price information in the product model (final price etc.) is not accurate if there is a special percentage.

public function getSelectionTitlePrice($_selection, $includeContainer = true)
{
$defaultPrice = 0.00;
$_product = $this->getProduct();
$_specialpricepercent = ($this->getProduct()->getSpecialPrice()) / 100;

if (gettype($this->getOption()->getDefaultSelection())==object){

if (isset($_specialpricepercent) && $_specialpricepercent > 0){

$defaultPricePreSpecial=$this->getOption()->getDefaultSelection()->getPrice();
$defaultPrice=$defaultPricePreSpecial * $_specialpricepercent;

}
else {

$defaultPrice=$this->getOption()->getDefaultSelection()->getPrice();
}
}

$price = $_product->getPriceModel()->getSelectionFinalPrice($_product, $_selection, 1);

if ($price == $defaultPrice)
{
    return $_selection->getName();
}
else
{
    $sign = ($price < $defaultPrice) ?  '-' : '+';
    $diff = ($price < $defaultPrice) ? $defaultPrice - $price : $price - $defaultPrice;
    return $_selection->getName() . ' &nbsp; ' .
        ($includeContainer ? '<span class="price-notice">':'') . $sign .
        $this->formatPriceString($diff, $includeContainer) . ($includeContainer ? '</span>':'');
}
}

Hopefully this helps someone struggling with the same issue!

Upvotes: 1

Related Questions