How to use absolute pricing for custom options

Last modified by nspacex on Mon, September 26, 2011 16:58
Source|Old Revisions  

This is an old revision of the document!


Introduction

When giving a custom option a price, Magento adds that price to the product’s base-price. This entry will show you how to add an extra price type, that allows custom options to override the base price. So instead of having “+ 10 percent” or “+£10 fixed”, you would be able to have “£25 absolute”.

Step 1

Edit app/code/core/Mage/Adminhtml/Model/System/Config/Source/Product/Options/Price.php

Replace:

  1. array('value' => 'percent', 'label' => Mage::helper('adminhtml')->__('Percent'))

With:

  1. array('value' => 'percent', 'label' => Mage::helper('adminhtml')->__('Percent')),
  2. array('value' => 'absolute', 'label' => Mage::helper('adminhtml')->__('Absolute'))

Step 2

Edit app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Options/Options.php

Replace:

  1. } elseif ($type == 'fixed') {

With:

  1. } elseif ($type == 'fixed' || $type == 'absolute') {

Step 3

Edit app/code/core/Mage/Catalog/Model/Product/Type/Price.php.

Replace all occurrences of:

  1. $finalPrice += $this->_getPricingOptionValue(array(

With:

  1. $finalPrice = ($option->getValueById($optionValue)->getPriceType() != 'absolute' ? $finalPrice : 0) + $this->_getPricingOptionValue(array(

Notes

Hi

I’ve tried to modify the code for version 1.6.0.0. At Step 1 you have to change the value for “absolute” because, the DB-Field (Table:catalog_product_option_type_price, Field:price_type) is of the type varchar(7) (absolute → 8, i used “abs”).

Step 2 is ok

Step 3

Edit: app/code/core/Mage/Catalog/Model/Product/Type/Price.php

Replace (Line ~274, function _applyOptionsPrice):

  1. $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $basePrice);

With:

  1. $optionPriceResult = $group->getOptionPrice($confItemOption->getValue(), $basePrice);
  2. if (is_array($optionPriceResult)) {
  3.     $finalPrice = $optionPriceResult[1];
  4. }
  5. else {
  6.     $finalPrice += $group->getOptionPrice($confItemOption->getValue(), $basePrice);
  7. }

Step 4

Edit: app/code/core/Mage/Catalog/Model/Product/Option/Type/Default.php

Replace (Line ~331):

  1. public function getOptionPrice(...) {
  2.     ...
  3. }

With

  1. public function getOptionPrice($optionValue, $basePrice) {
  2.     $option = $this->getOption();
  3.     if ($option->getPriceType() == 'abs') {
  4.         return array('absolute', $option->getPrice());
  5.     }
  6.     else {
  7.         return $this->_getChargableOptionPrice(
  8.             $option->getPrice(),
  9.                     $option->getPriceType() == 'percent',
  10.                     $basePrice
  11.             );
  12.     }
  13. }

Step 5

Edit: app/code/core/Mage/Catalog/Model/Product/Option/Type/Select.php

Replace (Line ~236, function getOptionPrice):

  1. ...
  2. elseif ($this->_isSingleSelection()) {
  3.     if ($_result = $option->getValueById($optionValue)) {
  4.         $result = $this->_getChargableOptionPrice(
  5.                 $_result->getPrice(),
  6.                     $_result->getPriceType() == 'percent',
  7.                     $basePrice
  8.         );
  9.     }
  10.     ...

With:

  1. elseif ($this->_isSingleSelection()) {
  2.     if ($_result = $option->getValueById($optionValue)) {
  3.         if ($_result->getPriceType() == 'abs') {
  4.             $result = array('absolute', $_result->getPrice());
  5.         }
  6.         else {
  7.                 $result = $this->_getChargableOptionPrice(
  8.                         $_result->getPrice(),
  9.                         $_result->getPriceType() == 'percent',
  10.                         $basePrice
  11.             );
  12.     }
  13.     ...

As you can see (File: Select.php, function: getOptionPrice), this code works only with single selection options. At the moment i doesn’t modified the JS Code for the Frontend. i hope it helps and as always sorry for my bad english :)

WARNING

This code destroys the layered-nav price-filter function (min_price, max_price values in table catalog_product_index_price are wrong), i think the problem is in this file (_applyCustomOption()):

app/code/core/Mage/Catalog/Model/Resource/Product/Indexer/Price/Default.php

Erik

You may need to also edit your frontend design accordingly to signify these changes.

Problem: I can’t locate that exact line of code in step 3, are you sure that is the correct code to look for? The closest I find is $finalPrice += $group→getOptionPrice($quoteItemOption→getValue(), $basePrice);

Please be more exact on step 3 code replacement. Thanks!

Yeah, Please be more specific of the last step...this would be an awesome feature to have. Thanks,

Captive Design

I tried to work around it with the fixed price values hack posted here however, it appears like the price.php file has changed in how it handles calculating option prices as of version 1.3.2.1 (feel free to correct version as needed- its the first time I noticed it in my files though).

studio7

-

This would be the best and most useful Wiki EVER, if it actually worked....step 3 code does not exist. Hopefully someday, someone can figure this out, as it is an ABSOLUTE NECESSITY FOR ANY WEBSITE. CAN’T BELIEVE IT’S NOT ALREADY PART OF MAGENTO....ALL THE OTHER CARTS HAVE A ‘ONE TIME FEE’ OPTION...ZENCART...ETC.... WHAT’S UP MAGENTO?? CHRIS

I’ve been checking back to this post everyday hoping and praying that someone had updated that last piece of code to get this working! I think this is one of the most important modifications that has been left out to date! Magento, please take a look at this!! We need to be able to have absolute pricing for custom options since your Grouped products do not allow for custom options. Thanks! -Andrew

Hoping and praying that someone will respond - Kit - July 27th 2009

Hi,

look here http://www.magentocommerce.com/boards/viewthread/49155/ (alpha)

Eric

-gpcola 12/11/2009:

I got to step three of modifying my store only to realise that step 3 is not applicable to 1.3.2.4... Not a great state of affairs I have to say :(




 

Magento 2 GitHub Repository

Magento Job Board - Some sort of tag line goes here

Latest Posts| View all Jobs