ccondrup
ccondrup

Reputation: 549

Magento Bundles: Options' displayed price calculated from default choice price, not from zero

The product myBundle has myColorOption with these items:

Magento 1.4.2.0 per default will present the customer with a select dropdown with options like this:

The change I am looking for is when a default item has been selected by admin. When it is, each displayed price should be relative to that of the default option. If admin sets Blue (price $100) as the default item for the option, the dropdown should now read:

To clarify: I only want the displayed price in the dropdown to change, the actual price added to cart and used for other calculations remains the same.


Update: Here's the code I have so far, the problem is in the commented lines. I need help getting the correct models etc.

<?php
// From file app/code/core/Mage/Bundle/Block/Catalog/Product/View/Type/Bundle/Option.php
// copied to app/code/local/Mage/...
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();
    $defaultPrice = $_product->getPriceModel()->getSelectionPreFinalPrice($_product, $_default, 1);
    */
    $price = $_product->getPriceModel()->getSelectionPreFinalPrice($_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>':'');
    }
}

Upvotes: 1

Views: 3988

Answers (2)

Adam B
Adam B

Reputation: 554

Just to add something to this answer - I was finding that the code would fail if it tried to call getDefaultSelection()->getPrice() against an option that had no default value. Was able to fix this by adding the following code:

$_mbmo = new Mage_Bundle_Model_Option();
$_mbmo->load($_selection->getProductId());
$_default = $_mbmo->getDefaultSelection();

if (gettype($this->getOption()->getDefaultSelection())==object){
$defaultPrice=$this->getOption()->getDefaultSelection()->getPrice();
}

Basically just does a check that something is returned from calling getDefaultSelection() on $this and then proceeds with setting default price, otherwise it just carries on with the rest of the code.

Upvotes: 1

Rams
Rams

Reputation: 36

Use this code

$defaultPrice = $_product->getPriceModel()->getSelectionPreFinalPrice($_product, $_default,1);

Replace above line with below

$defaultPrice=$this->getOption()->getDefaultSelection()->getSelectionPriceValue();

Upvotes: 2

Related Questions