6

I have a product Bundle with a few dropdown options. In the dropdown I have a number of options the customer can choose from (simple products) and only one of them adds to the price of the bundle. Yet Magento includes "+$0.00" next to every single option in the dropdown. It looks too confusing to have so many options which all have +$0.00 next to them, yet I don’t want to hide that field entirely since one of the options does add $10.00 to the price.

How do I get Magento to only display the +$x.xx if there is an increase/decrease and hide this text if it’s $0.00?

If that isn't possible (or advisable to hack the core) I'm thinking I could hide the field entirely with CSS and just rename any sub-products that have a price change like "Product Name +$5.00" so it mimics the behavior. BUT, I can't figure out how to hide that particular field with CSS.

Trying to launch my site soon and this issue is bugging me - any ideas for either solution? Thanks in advance!

Magento CE 1.9.0.1

Thanks!

1

4 Answers 4

11

Go to the file: app/design/frontend/base/default/template/bundle/catalog/product/view/type/bundle/option/

Choose your selection method:

I am writing the below code for select.phtml

The simple process is to change (see the code in bold):

<?php if ($this->_showSingle()): ?>
        <?php echo $this->getSelectionTitlePrice($_selections[0]) ?>
        <input type="hidden" name="bundle_option[<?php echo $_option->getId() ?>]" value="<?php echo $_selections[0]->getSelectionId() ?>"/>
    <?php else:?>
        <select onchange="bundle.changeSelection(this)" id="bundle-option-<?php echo $_option->getId() ?>" name="bundle_option[<?php echo $_option->getId() ?>]" class="bundle-option-<?php echo $_option->getId() ?><?php if ($_option->getRequired()) echo ' required-entry' ?> bundle-option-select change-container-classname">
            <option value=""><?php echo $this->__('Choose a selection...') ?></option>
        <?php foreach ($_selections as $_selection): ?>
            <option value="<?php echo $_selection->getSelectionId() ?>"<?php if ($this->_isSelected($_selection)) echo ' selected="selected"' ?><?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>><?php echo $this->getSelectionTitlePrice($_selection, false) ?></option>
        <?php endforeach; ?>
        </select>
    <?php endif; ?>

TO

<?php if ($this->_showSingle()): ?>
        **<?php echo $_selections[0]->getName()?>**
        <input type="hidden" name="bundle_option[<?php echo $_option->getId() ?>]" value="<?php echo $_selections[0]->getSelectionId() ?>"/>
    <?php else:?>
        <select onchange="bundle.changeSelection(this)" id="bundle-option-<?php echo $_option->getId() ?>" name="bundle_option[<?php echo $_option->getId() ?>]" class="bundle-option-<?php echo $_option->getId() ?><?php if ($_option->getRequired()) echo ' required-entry' ?> bundle-option-select change-container-classname">
            <option value=""><?php echo $this->__('Choose a selection...') ?></option>
        <?php foreach ($_selections as $_selection): ?>
            <option value="<?php echo $_selection->getSelectionId() ?>"<?php if ($this->_isSelected($_selection)) echo ' selected="selected"' ?><?php if (!$_selection->isSaleable()) echo ' disabled="disabled"' ?>><?php echo $_selection->getName() ?></option>
        <?php endforeach; ?>
        </select>
    <?php endif; ?>
2
  • Great, worked for..!
    – Elavarasan
    Sep 23, 2016 at 10:37
  • Not working for input type drop down option ..
    – Gem
    Jan 5, 2017 at 11:59
1

you have to change in block's function as per your requirement when price is 0 then set only title

here is some hint of function which you can alter

<?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)
{

}

And for more detail you can see here

hope this will sure help you.

0

As liyakat pointed out, the responsible code is in Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option::getSelectionTitlePrice().

Note that this is an abstract class, that's why the suggestion was to copy it to app/code/local instead of properly rewriting it. But if you only use dropdowns, you should better rewrite Mage_Bundle_Block_Catalog_Product_View_Type_Bundle_Option_Select and then only override this method:

public function getSelectionTitlePrice($_selection, $includeContainer = true)
{
    $selectionPrice = $this->getProduct()
        ->getPriceModel()
        ->getSelectionPreFinalPrice($this->getProduct(), $_selection);
    if ($selectionPrice == 0) {
         return '';
    }
    return parent::getSelectionTitlePrice($_selection, $includeContainer);
}

For how to rewrite the class, refer to this wiki article: http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/customize_part_of_configuration

0

The answer @fabian-schmengler posted is almost correct. While providing the correct method that needs to change, there is a problem with returning an empty string as the parent method returns the full option text. This means that you would end up having an empty option field. By tweaking the complete parent method locally you could achieve your desired result. I've did a price check where the parent method appends the price.

Original:

public function getSelectionTitlePrice($_selection, $includeContainer = true)
    {
        $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection, 1);
        $this->setFormatProduct($_selection);
        $priceTitle = $this->escapeHtml($_selection->getName());
        $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '')
            . '+' . $this->formatPriceString($price, $includeContainer)
            . ($includeContainer ? '</span>' : '');
        return $priceTitle;
    }

My tweak:

$priceTitle .= $price != 0 ? '+' . $this->formatPriceString($price, $includeContainer) : '';

Final:

public function getSelectionTitlePrice($_selection, $includeContainer = true)
{
    $price = $this->getProduct()->getPriceModel()->getSelectionPreFinalPrice($this->getProduct(), $_selection, 1);
    $this->setFormatProduct($_selection);
    $priceTitle = $this->escapeHtml($_selection->getName());
    $priceTitle .= ' &nbsp; ' . ($includeContainer ? '<span class="price-notice">' : '');
    $priceTitle .= $price != 0 ? '+' . $this->formatPriceString($price, $includeContainer) : '';
    $priceTitle .= ($includeContainer ? '</span>' : '');

    return $priceTitle;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.