WSOD on order completion page when order has items without purchased entites

Created on 7 March 2025, about 1 month ago

Problem/Motivation

commerce_giftcard_preprocess_commerce_checkout_completion_message() assumes that order items have purchased entities attached to them. This is optional for order items and will cause a WSOD on the checkout complete step of any stores creating basic order items on orders with no purchased entities attached (probably not common).

Additionally, the code wouldn't ever work anyways because it assumes that giftcard transactions have a reference to the order item id instead of the order id which is what is actually stored on transactions.

Steps to reproduce

Proposed resolution

The order item part of that preprocess function should be removed and redone to work with order ids.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

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

Merge Requests

Comments & Activities

  • Issue created by @rhovland
  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon
  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    Confirmed to fill the array with redeemed gift card codes. Needs a test to make sure the codes are output into the template variables. Since there is no template provided to display these values we probably can stop at making sure the template variables are populated in a test.

  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    Created a test which will pass once πŸ› Fix tests Active is merged into this issue branch.

    https://git.drupalcode.org/issue/commerce_giftcard-3481607/-/pipelines/4...

  • πŸ‡©πŸ‡ͺGermany Grevil

    This sounds like a major problem, I'll come back to you asap.

  • πŸ‡©πŸ‡ͺGermany Grevil

    I definitly agree with you here, in my opinion Giftcards should apply on the whole order and not handle single OrderItem- / Purchased-Entities in any way or form.

    As seen in "GiftcardOrderProcessor" the price adjustment is added on the whole order. But what I don't understand yet, is that in "OrderEventSubscriber" "giftcardPurchase()" we link order ITEMs per commerce_giftcard_transaction, so you're assumption in the issue summary:

    Additionally, the code wouldn't ever work anyways because it assumes that giftcard transactions have a reference to the order item id instead of the order id which is what is actually stored on transactions.

    is incorrect, because there are indeed order item IDs referenced to commerce giftcard transactions. Why that is the case, I am not sure yet. I haven't gotten in too deep yet.

    I think, we should dedicate this issue to resolve any order item related code and find out what it was used for and why.

    The original WSOD issue is circumvented by changes from πŸ› Fix tests Active . So we can lower the priority of this issue and rename it.

  • πŸ‡©πŸ‡ͺGermany Grevil
  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    Ok I think I figured out where the source of the confusion is here.

    I thought that the checkout completion message variables were intended to display the gift card codes redeemed to pay for the order (just like how payment methods are usable variables). This code was actually intended to allow to display the codes for purchased gift cards. It does this by querying gift card transactions that have a reference_id that matches the item id. However this is a very big problem as reference_id is shared by two different types of entity ids!

    OrderEventSubscriber::giftcardPurchase() generates gift card codes for gift cards that were purchased as an order item. It records the order item id in the reference_id field in commerce_giftcard_transaction.

    OrderEventSubscriber::registerUsage() generates a transaction whenever a gift card is used to pay for an order. It records the order id in the reference_id field in commerce_giftcard_transaction.

    We're storing two different ids in the same field with no way to differentiate the difference between transaction types other than the content of the comment field.

  • πŸ‡ΊπŸ‡ΈUnited States rhovland Oregon

    In light of this I think this issue should become
    "Create completion pane to display purchased gift cards"

    Because right now if a gift card is purchased the customer does not see the code. And shoving it into the variables for the completion message is wrong because now we'd have to override the template for that to fully implement the feature. It should be a separate pane that's added to the complete step of checkout.

    As part of this feature we can figure out a better way to handle the query to get the list of gift cards that were purchased.

  • πŸ‡©πŸ‡ͺGermany Grevil

    Thanks, @rhovland! Yea, that makes more sense.

Production build 0.71.5 2024