not sure if anyone can help with this?
We need to add a percentage on top of a calculated price and not the base price.
e.g.
Base Price = £10
Selection 1 Option 1 + £10 Option 2 + £20
Selection 2 Option 1 + 10% Option 2 + 20%
We need to calculate baseprice + (option 1 from selection 1) and then on top of that subtotal we need to add (option 1 from selection 2开发者_开发百科) to that subtotal price and NOT the baseprice.
Is this at all possible as from what we’ve seen so far all percentages are worked out on the baseprice and not subtotal.
Roughly speaking you should create a custom product type so that you may provide this custom calculation without changing the "Simple" product type which might still be used for other products in the store. The real work will be done in it's price model.
Defining a new type is easy:
<config>
<global>
<catalog>
<product>
<type>
<CUSTOM>
<label>CUSTOM PRODUCT TYPE</label>
<model>catalog/product_type_abstract</model>
<priceModel>YOURMODULE/product_type_CUSTOM<priceModel>
</CUSTOM>
</type>
</product>
</catalog>
</global>
</config>
The module needs an install script which assigns the various price related attributes to custom type, otherwise they won't show up on the product's edit page.
This now expects a class YOURMODULE_Model_Product_Type_CUSTOM_Price
which should descend from Mage_Catalog_Model_Product_Type_Price
. The new class should override the following method:
protected function _applyOptionsPrice($product, $qty, $finalPrice)
See the parent's method for how it works, then make it work how you want.
I imagine you would probably loop through all the product options and keep two totals, one of fixed prices and one of percentages. Add the fixed value to the base price then multiply by the percentages value.
Then all that remains is to add new products in the admin using your new type.
精彩评论