Jump to content

HannaCode Text Formatter on a template field


fruid
 Share

Recommended Posts

Hello all,

I'm familiar with HannaCode and use it on some projects already.

Now I wonder what it actually is good for to apply it as a text formatter on a template field.
Here's what I'm trying to accomplish and where I thought it would be a good solution to use custom code for.

For a shop "module" (not yet a PW module, but some php and javascript files) I'm working on, I need a way to allow for stacked prices, say a different unit price when buying 10 units.
So since these unit prices and stack price rules would differ from product to product, I thought a very simple, fast and flexible solution would be to allow for custom code injection. So for example the content manager could write:

if($itemAmount=10){$unitPrice=30}else{$unitPrice=35};

Does that make sense?

So long story short, I need custom code on specific pages. Is that possible with the HannaCode Text formatter?

Link to comment
Share on other sites

I'm not sure I'd go down that road, even though it's probably possible. For one, you can't take advantage of the logic already there for numeric field types. For two, what if there are additional price scales? To round it up, for three, it may speed up input, but there will likely be cases where you'll have to disassemble the unformatted value anyway to present the information. I'd go with a repeater that has fields for quantity and price (maybe a default price field on the item page and just add scale prices in the repeater). That way, your data is queryable through selectors, your code will be easier to understand years later when you have to come back and make changes, and you don't have to worry about multiple scales for one item.

Price calculation will be just a small piece of code:

$price = $item->price;
foreach($item->scaleprices->sort('-quantity') as $scale) {
  if($order->quantity >= $scale->quantity) {
    $price = $scale->price;
    break;
  }
}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...