Home : Digital Asset Management : Programming OpenEdit : ECommerce Setup : Custom Pricing
Custom Pricing
A product can be configured to have a custom price. This allows you to set the price dynamically then checkout based on the price given.
Configuration
You will need to manually add a flag to the product configuration files. For example /store/products/asprin.xconf can be edited to have this in it:
<page>
<product name="Aspirin" id="aspirin" ordering="-1" available="TRUE">
<custom-price>true</custom-price>
Adding Logic
If your rules are simple you can just edit the HTML to come up with pricing. Copy this file: /base/store/products/price.html to here: /store/products/price.html
#if( $product.isCustomPrice() )
#if( $user.hasPermission("oe.edit") )
#set( $newPrice = $product.getRetailPrice().multiply( ".5" ) )
Regularly $product.getRetailPrice()<br>
Your Member Price: <b>$newPrice</b>
<input name="price" type="hidden" value="$newPrice" />
#else
<b>Price:</b> $product.getYourPrice()
#end
#else
#if ( $product.isOnSale() )
Regularly $product.getRetailPrice()<br>
<div class="sale_price">On Sale! $product.getYourPrice()</div>
#else
<b>Price:</b> $product.getYourPrice()
#end
#end
<p>
#if( $product.isAvailable() )
<input type="hidden" name="productid" value="$product.getId()" /> <input type="submit" value="ADD TO CART" class="bu"/>
#else
<b>Product No Longer Available.</b> please select another product
#end
</p>
The statements we added are:
1. #if( $product.isCustomPrice() ) - This is read from the .xconf file as configured above. (Be aware that product pricing is cached so you may need to restart the web container or touch WEB-INF/web.xml
2. #if( $user.hasPermission("oe.edit") ) - Here we check that the user is logged in. Or to be fancy could also call $user.hasPermission("oe.edit") to see if the user is part of the editors group.
3. $product.getRetailPrice().multiply - You can pass in any number. We also support add, subtract, divide capability.
Live Example
Aspirin DemoThe price changes if you log in as admin/admin.
Best Practice
For simple logic and a small number of products custom price will work fine. If your needs become to complex then there are multiple other approaches you can take using OpenEdit:
1. Make copies of the products that can be found only by the correct visitors.
2. Use Sale vs Retail Pricing but change the name
3. Use handling-charge-level to add or subtract from the total price depending on the level of the product.
4. Offer coupons instead of multiple pricing.
5. Offer quantity discounts using the built in <price quantity="1">5.00</price> convention
6. Attach the price to the item and not the product. Then choose the item level price.
7. If all else fails, subclass PriceSupport object. This is the most complex option best done within the core OpenEdit code.
