ccondrup ccondrup - 4 months ago 20
PHP Question

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

The product myBundle has myColorOption with these items:


  • Green $50

  • Blue $100

  • Red $100

  • Black $150



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


  • Green +$50

  • Blue +$100

  • Red +$100

  • Black +$150



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:


  • Green -$50

  • Blue

  • Red

  • Black +$50



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>':'');
}
}

Answer

Use this code

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

Replace above line with below

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