Allow amount to be zero

Created on 16 November 2023, over 1 year ago
Updated 30 November 2023, over 1 year ago

Problem/Motivation

I have a donation form in a circumstance where a donation is encouraged but optional. To handle this, I allow the amount on the form to be entered as zero.

But commerce_webform_order replaces a zero amount on the order item with the amount from the product variation.

protected function prepareData() {
   ...
    if (empty($data['order_item']['amount'])) {
      $data['order_item']['amount'] = $prepared_data['product_variation']->getPrice()->getNumber();
    }
    ...
}

Proposed resolution

Could this be

protected function prepareData() {
   ...
    $amount = $data['order_item']['amount'];
    if (empty($amount) && !is_numeric($amount)) {
      $data['order_item']['amount'] = $prepared_data['product_variation']->getPrice()->getNumber();
    }
    ...
}

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Fixed

Version

3.0

Component

Code

Created by

🇬🇧United Kingdom jonathanshaw Stroud, UK

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024