Created
February 7, 2012 23:20
-
-
Save inspiran/1762927 to your computer and use it in GitHub Desktop.
Vespolina pricing declaration based on twig alike syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% pricingSet "packable_product" %} | |
{% element "packaging_cost" %} | |
{% element "net_value" %} | |
{% element "net_value_with_packaging_cost" %} | |
{% element "tax_amount" %} | |
{% element "unit_price_with_tax" %} | |
{% endpricingset %} | |
{% pricingSet "cart_item" %} | |
{% element "total_discount" %} | |
{% element "total_value" %} | |
{% element "total_tax_amount" %} | |
{% element "total_incl_tax" %} | |
{% endpricingset %} | |
{% pricingSet "cart" %} | |
{% element "total_discount" %} | |
{% element "total_value" %} | |
{% element "total_tax_amount" %} | |
{% element "total_incl_tax" %} | |
{% endpricingset %} | |
{% pricingExecution "calculateProduct" %} | |
{% step "calculate_packaging"|independent %} | |
{% set packaging_cost_factor = 5 %} | |
{% set packaging_cost = net_value / 100 * packaging_cost_factor %} | |
{% set net_value_with_packaging_cost = packaging_cost + net_value %} | |
{% endstep %} | |
{% step "calculate_customer_price"|dependent %} | |
{# Determine the current tax rate based on the customer (known in the global context) #} | |
{% determine_tax_rate into tax_rate %} | |
{% set tax_amount = net_value_with_packaging_cost / 100 * tax_rate %} | |
{% set unit_price_with_tax = net_value_with_packaging_cost + tax_amount %} | |
{% endstep %} | |
{% endpricingExecution %} | |
{% pricingExecution "calculateCartItem" %} | |
{% step|dependent %} | |
{# Load a specific price from a pricing set into the context #} | |
{% load_price cartItem.product net_value_with_packaging_cost into total_value %} | |
{% determine_discount with cartItem into total_discount %} | |
{# Determine the current tax rate based on the customer + cart item #} | |
{% determine_tax_rate with cartItem into item_tax_rate %} | |
{% set tax_amount = total_value / 100 * item_tax_rate %} | |
{% set total_tax_amount = ( total_value - total_discount ) / 100 * item_tax_rate %} | |
{% set total_incl_tax = (total_value - total_discount) + total_tax_amount %} | |
{% endstep %} | |
{% endpricingExecution %} | |
{% pricingExecution "calculateCart" %} | |
{% step|dependent %} | |
{% for cartItem in cartItems %} | |
{# Load the pricing set of cartItem into the context and prefix with "item_" #} | |
{% load_prices cartItem "item_" %} | |
{% set total_dicount += item_total_discount %} | |
{% set total_value += item_total_value %} | |
{% set total_tax_amount += item_total_tax_amount %} | |
{% set total_incl_tax += item_total_incl_tax %} | |
{% endfor %} | |
{% endstep %} | |
{% endpricingExecution %} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment