4

Is there a way of removing the price change (e.g. the string '+£80.00' or '-£60.00') from after the option name in a custom option dropdown list?

Example with '+£80.00' and '+£90.00'

I do not want to remove it from any other location, i.e. it should still add on to the total price as it currently does, it just shouldn't be visible in the dropdown.

Ideally I don't want to hack the code anywhere but I realise this is probably not a built in option.

4

For configurable products, prices are added to label from js module Product.Config. To remove them, we have to rewrite module’s function getOptionLabel. We need a new javascript file, inside js folder, with following code:

Product.Config.prototype.getOptionLabel = function(option, price) {
    return option.label;
};

Of course, to make it work, we need to add newly created script to single product view page. This can be done by adding following line to the catalog.xml, after varien/configurable.js has been added.

<action method="addJs"><script>path/to/our/file.js</script></action>

To remove the price from single product’s custom options, we need to (due to lack of better solution), rewrite core block responsible for rendering product options input elements.

After rewriting Mage_Catalog_Block_Product_View_Options_Type_Select block, we have to change the way options are rendered. Around line 65, there is a loop similar to the following code:

foreach ($_option->getValues() as $_value) {
    $priceStr = $this->_formatPrice(array(
        'is_percent'    => ($_value->getPriceType() == 'percent'),
        'pricing_value' => $_value->getPrice(($_value->getPriceType() == 'percent'))
    ), false);
    $select->addOption(
        $_value->getOptionTypeId(),
        $_value->getTitle() . ' ' . $priceStr . '',
        array('price' => $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false))
    );
}

In our own file which we used for rewriting Magento’s default code, we should use the following version:

foreach ($_option->getValues() as $_value) {
    $select->addOption(
        $_value->getOptionTypeId(),
        $_value->getTitle(),
        array('price' => $this->helper('core')->currencyByStore($_value->getPrice(true), $store, false))
    );
}

With these simple changes we will be able to remove ugly formatted pricing in dropdown in our Magento’s single product view pages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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