Migrating Complex B2B Tiered Pricing from Script Editor to Shopify Functions (Rust)

Category: Shopify Functions & APIs
Published: Nov 2026
Reading time: 10–12 minutes
Tags: Shopify Functions, Rust, WebAssembly, B2B Ecommerce, Discount Engineering

Introduction

Complex B2B ecommerce stores often operate with pricing rules that are significantly different from standard retail stores.

A retail customer might purchase one product at its listed price.

A wholesale customer, however, may qualify for different pricing based on:

  • Purchase quantity.
  • Customer classification.
  • Company account.
  • Product category.
  • Order value.
  • Contractual pricing agreements.
  • Shipping requirements.

Historically, Shopify merchants used Shopify Scripts and Script Editor to implement some advanced checkout customizations.

However, Shopify Scripts reached the end of their lifecycle in 2026, making migration to supported Shopify extensibility solutions an important consideration.

Shopify Functions provide a more modern approach to implementing custom business logic.

This article explores how a complex B2B pricing architecture can be approached using Shopify Functions, Rust, and WebAssembly.

1. Understanding the Limitations of Legacy Shopify Scripts

Legacy Shopify Scripts allowed merchants to customize specific checkout and cart behaviors.

For businesses with sophisticated pricing requirements, these scripts became an important part of their ecommerce infrastructure.

Common use cases included:

  • Quantity-based discounts.
  • Wholesale pricing.
  • Product-specific promotions.
  • Shipping adjustments.
  • Custom discount eligibility.
  • Order-level pricing rules.

The challenge was that business logic became closely tied to the legacy scripting environment.

As stores grew, maintaining these rules became increasingly difficult.

A migration should not simply reproduce old code in a new language.

It should reassess the pricing architecture and identify opportunities to simplify the implementation.

2. Introducing Shopify Functions

Shopify Functions allow developers to customize specific parts of Shopify’s commerce logic.

Depending on the available Function API and merchant plan, developers can implement functionality such as:

  • Product and order discounts.
  • Delivery customizations.
  • Cart and checkout validations.
  • Other supported commerce customizations.

Unlike traditional server-side applications, Functions execute within Shopify’s managed infrastructure.

They are designed for predictable execution and are compiled to WebAssembly.

Rust is a popular choice for Shopify Functions because it provides:

  • Strong type safety.
  • Memory safety.
  • Predictable performance.
  • Efficient compilation to WebAssembly.
  • Excellent tooling for structured business logic.

Shopify also supports other development approaches for supported Function targets, so Rust is an architectural choice rather than a universal requirement.

3. Designing a B2B Tiered Pricing Engine

Consider a wholesale store selling products in bulk.

The pricing structure is:

QuantityDiscount
1–9 units0%
10–24 units5%
25–49 units10%
50–99 units15%
100+ units20%

The business requirement is straightforward:

As the customer purchases more units, the applicable discount increases.

However, implementing this correctly requires several considerations.

First, the system must identify which products qualify.

Second, it must determine the eligible quantity.

Third, it must evaluate whether the customer qualifies for the offer.

Finally, it must apply the correct discount without conflicting with other promotions.

A simplified Rust function for determining the discount tier could look like this:

fn discount_for_quantity(quantity: u32) -> u32 {
    match quantity {
        100.. => 20,
        50..=99 => 15,
        25..=49 => 10,
        10..=24 => 5,
        _ => 0,
    }
}

This example demonstrates the tier calculation only. A real Shopify Function must use the generated input and output types for its specific API target.

4. Separating Business Rules from Execution Logic

One of the most important architectural improvements is separating business configuration from the Function’s execution logic.

For example, pricing thresholds may change over time.

Hardcoding every threshold directly into the Rust implementation creates unnecessary maintenance work.

Instead, merchants can manage supported configuration data through Shopify metafields or other suitable Shopify data structures.

A configuration might conceptually contain:

{
  "tiers": [
    {
      "minimum_quantity": 10,
      "discount_percentage": 5
    },
    {
      "minimum_quantity": 25,
      "discount_percentage": 10
    },
    {
      "minimum_quantity": 50,
      "discount_percentage": 15
    },
    {
      "minimum_quantity": 100,
      "discount_percentage": 20
    }
  ]
}

The Function can then evaluate the configuration supplied through its input.

This creates a cleaner separation between:

  • Business configuration.
  • Pricing evaluation.
  • Function execution.
  • Merchant administration.

The exact configuration mechanism depends on the Function API and its supported input fields.

5. Handling Wholesale Customer Eligibility

Not every customer should necessarily receive wholesale pricing.

A B2B pricing engine may need to evaluate:

  • Customer tags.
  • Company accounts.
  • Company locations.
  • Catalog eligibility.
  • Specific product classifications.
  • Other supported customer and cart attributes.

For example, a wholesale discount should not automatically apply to every retail customer purchasing 50 units.

The Function must evaluate the appropriate eligibility information supplied in its input.

This is particularly important when a store serves both retail and wholesale customers from the same storefront.

A poorly designed discount system can unintentionally expose wholesale pricing to retail buyers.

6. Migrating Complex Shipping and Freight Rules

B2B shipping introduces another layer of complexity.

Unlike standard retail orders, wholesale orders may involve:

  • Bulk shipment requirements.
  • Freight thresholds.
  • Regional shipping restrictions.
  • Heavy or oversized products.
  • Different delivery eligibility rules.
  • Special shipping arrangements.

Shopify delivery customizations can support certain delivery-option modifications, such as hiding, renaming, or reordering eligible options.

However, they are not a universal replacement for every legacy shipping-rate calculation.

The actual architecture depends on whether the business requires rate calculation, delivery-option customization, or an external carrier integration.

A practical migration should identify each legacy rule and map it to the correct Shopify capability.

7. Understanding WebAssembly Execution

One of the technical advantages of Shopify Functions is their WebAssembly execution model.

WebAssembly provides a portable binary format designed for efficient execution.

A typical development workflow involves:

  1. Writing business logic in Rust.
  2. Compiling the implementation to WebAssembly.
  3. Defining the required Function input.
  4. Processing the supplied Shopify data.
  5. Returning the expected Function output.
  6. Testing different business scenarios.
  7. Deploying through the Shopify app infrastructure.

Unlike a traditional Node.js application, a Shopify Function is not a continuously running server.

It receives structured input, executes its designated operation, and returns a result.

Developers must therefore design around the specific Function API rather than expecting unrestricted server functionality.

For example, Functions should not depend on arbitrary external network requests during execution. Required configuration and data must be available through supported inputs and Shopify infrastructure.

8. Testing Before Migration

A pricing migration can have direct financial consequences.

A small calculation error can result in incorrect wholesale pricing or unintended discounts.

We recommend building a test matrix before replacing legacy logic.

Test scenarioExpected behavior
Retail customerNo wholesale discount
Wholesale customerEligible pricing
9 unitsNo quantity discount
10 units5% discount
25 units10% discount
50 units15% discount
100 units20% discount
Mixed eligible productsCorrect product-level evaluation
Ineligible productsNo unintended discount
Multiple promotionsCorrect combination or exclusion

Testing should also cover:

  • Empty carts.
  • Quantity changes.
  • Customer eligibility changes.
  • Decimal and currency handling.
  • Discount stacking rules.
  • Checkout behavior.
  • Different company locations where applicable.

9. A Practical Migration Strategy

A reliable migration can be divided into five phases.

Phase 1: Audit

Document every existing Script Editor rule and identify its business purpose.

Phase 2: Architecture

Map each rule to the appropriate Shopify Function, native Shopify feature, or external integration.

Phase 3: Development

Implement the required logic using Rust or another supported language for the selected Function API.

Phase 4: Validation

Compare legacy and new behavior using identical test scenarios.

Phase 5: Deployment and Monitoring

Deploy the new implementation, monitor pricing behavior, and establish a process for maintaining business configurations.

Conclusion

Migrating complex B2B pricing from legacy Shopify Scripts to Shopify Functions is an opportunity to modernize ecommerce architecture.

The biggest challenge is not converting Ruby code into Rust.

It is preserving business rules, ensuring pricing accuracy, simplifying configuration, and mapping each requirement to the correct Shopify extensibility capability.

With a properly designed Function architecture, merchants can maintain sophisticated discount and checkout workflows while taking advantage of Shopify’s managed execution environment.

Final takeaway: A successful migration preserves business logic while improving the maintainability, reliability, and extensibility of the underlying commerce architecture.


About Enigma Systems

Enigma Systems focuses on enterprise software engineering, Shopify development, custom ecommerce solutions, and intelligent automation.

Our engineering approach combines practical implementation with performance measurement, experimentation, and scalable architecture.

Explore our work: https://enigmasystems.io

Engineering Insights & Dispatches brings together technical breakdowns, implementation lessons, performance research, and ecommerce engineering experiments from real-world development workflows.

Leave a Comment