Skip to content

Critical issues in warranty option examples for Cart Transform API (JavaScript and Rust) #598

Open
@shota-f

Description

@shota-f

Which template or example

https://github.com/Shopify/function-examples/blob/main/sample-apps/optional-add-ons-cart-transform/extensions/optional-add-ons-js/src/run.js

https://github.com/Shopify/function-examples/blob/main/sample-apps/optional-add-ons-cart-transform/extensions/optional-add-ons-rust/src/run.rs

Describe the bug

There are significant problems with the warranty option examples provided for the Cart Transform API in both JavaScript and Rust implementations. These issues could lead to severe pricing errors and misuse of the API.

  1. Incorrect use of presentmentCurrencyRate (Critical):

Both JavaScript and Rust examples incorrectly apply presentmentCurrencyRate to values that are already in the presentment currency. This results in drastically underpriced warranties.

JavaScript (line 76-86):

price: {
  adjustment: {
    fixedPricePerUnit: {
      amount: (
        cost.amountPerQuantity.amount *
        (warrantyCostPercentage / 100) *
        presentmentCurrencyRate
      ).toFixed(2),
    },
  },
},

Rust (line 59-69):

price: Some(ExpandedItemPriceAdjustment {
    adjustment: ExpandedItemPriceAdjustmentValue::FixedPricePerUnit(
        ExpandedItemFixedPricePerUnitAdjustment {
            amount: Decimal(
                line.cost.amount_per_quantity.amount.0
                    * (warranty_cost_percentage / 100.0)
                    * presentment_currency_rate,
            ),
        },
    ),
}),

For example, if the store currency is JPY and the presentment currency is USD, this would lead to prices being reduced by a factor of about 150, potentially causing significant financial losses.

The correct implementation should not use presentmentCurrencyRate at all, as the cost is already in the presentment currency.

  1. Incomplete implementation of the "expand" operation in JavaScript example:

The JavaScript example fails to include the original product in the expandedCartItems array, which is a fundamental misunderstanding of how the "expand" operation should work. This makes the example unsuitable as a reference in the documentation.

JavaScript (line 72-88):

expandedCartItems: [
  {
    merchandiseId: warrantyVariantID.value,
    quantity: 1,
    price: {
      adjustment: {
        fixedPricePerUnit: {
          amount: (
            cost.amountPerQuantity.amount *
            (warrantyCostPercentage / 100) *
            presentmentCurrencyRate
          ).toFixed(2),
        },
      },
    },
  },
],

The correct implementation should include both the original product and the warranty in the expandedCartItems array, as demonstrated in the Rust example.

These issues could lead to severe problems in real-world applications, including incorrect pricing and removal of original products from the cart. We kindly request that both examples be updated to correctly demonstrate the use of the Cart Transform API, ensuring they provide accurate guidance for developers implementing warranty options.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions