craftcms / commerce

Fully integrated ecommerce for Craft CMS.
https://craftcms.com/commerce
Other
225 stars 170 forks source link

[5.x]: Completing order with Custom Line item throws an error #3733

Open alex-brukhty opened 1 day ago

alex-brukhty commented 1 day ago

What happened?

Description

When requesting /actions/commerce/payments/complete-payment?commerceTransactionHash=<hash> to complete order that has Custom Line items, getting an error: Cannot get a purchasable for a custom line item

exception: "yii\\base\\InvalidConfigException"
file: "/var/www/html/vendor/craftcms/commerce/src/models/LineItem.php"
line: 821
message: "Cannot get a purchasable for a custom line item"
name: "Invalid Configuration"

Steps to reproduce

  1. Create custom line item and add to cart:
    $lineItem = Commerce::getInstance()->getLineItems()->create($cart, [
    'price' => (float)$this->request->getRequiredBodyParam('amount'),
    'taxCategoryId' => Commerce::getInstance()->getTaxCategories()->defaultTaxCategory->id,
    'isShippable' => true,
    'shippingCategoryId' => Commerce::getInstance()->getShippingCategories()->getShippingCategoryByHandle('general')->id,
    ], LineItemType::Custom);
    $cart->addLineItem($lineItem);
  2. Make a payment
  3. Request /actions/commerce/payments/complete-payment?commerceTransactionHash=<hash> to complete oreder

Expected behavior

Complete order without errors

Actual behavior

Order is marked as completed but throws an error

Craft CMS version

5.4.8

Craft Commerce version

5.2.0

PHP version

8.3

Operating system and version

ddev

Database type and version

mysql 8

Image driver and version

No response

Installed plugins and versions

-

linear[bot] commented 1 day ago

PT-2264 [5.x]: Completing order with Custom Line item throws an error