verbb / gift-voucher

A Craft Commerce plugin to provide Gift Certificate/Voucher functionality.
Other
14 stars 16 forks source link

Voucher does not redeem any amounts and custom line items doesn't work #136

Open gopeter opened 2 weeks ago

gopeter commented 2 weeks ago

Describe the bug

It seems that there are some incompatibilities between Craft Commerce 5.1 and the Gift Voucher plugin. Adding the voucher to a cart doesn't redeem an amount (it's always 0).

Additionally, I can't add a custom line item (added since Commerce 5.1) once a voucher is applied to the cart:

{
    "name": "Invalid Configuration",
    "message": "Cannot get a purchasable for a custom line item",
    "code": 0,
    "exception": "yii\\base\\InvalidConfigException",
    "file": "/var/www/html/vendor/craftcms/commerce/src/models/LineItem.php",
    "line": 820,
    "trace": [
        {
            "file": "/var/www/html/vendor/verbb/gift-voucher/src/services/Codes.php",
            "line": 245,
            "function": "getPurchasable",
            "class": "craft\\commerce\\models\\LineItem",
            "type": "->"
        },
        {
            "function": "handleValidateLineItem",
            "class": "verbb\\giftvoucher\\services\\Codes",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Event.php",
            "line": 312,
            "function": "call_user_func"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Component.php",
            "line": 650,
            "function": "trigger",
            "class": "yii\\base\\Event",
            "type": "::"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Model.php",
            "line": 386,
            "function": "trigger",
            "class": "yii\\base\\Component",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Model.php",
            "line": 351,
            "function": "beforeValidate",
            "class": "yii\\base\\Model",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/commerce/src/elements/traits/OrderValidatorsTrait.php",
            "line": 133,
            "function": "validate",
            "class": "yii\\base\\Model",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/validators/InlineValidator.php",
            "line": 77,
            "function": "validateLineItems",
            "class": "craft\\commerce\\elements\\Order",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/validators/Validator.php",
            "line": 260,
            "function": "validateAttribute",
            "class": "yii\\validators\\InlineValidator",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Model.php",
            "line": 368,
            "function": "validateAttributes",
            "class": "yii\\validators\\Validator",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/cms/src/base/Element.php",
            "line": 2666,
            "function": "validate",
            "class": "yii\\base\\Model",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/commerce/src/controllers/OrdersController.php",
            "line": 454,
            "function": "validate",
            "class": "craft\\base\\Element",
            "type": "->"
        },
        {
            "function": "actionRefresh",
            "class": "craft\\commerce\\controllers\\OrdersController",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/InlineAction.php",
            "line": 57,
            "function": "call_user_func_array"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Controller.php",
            "line": 178,
            "function": "runWithParams",
            "class": "yii\\base\\InlineAction",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Module.php",
            "line": 552,
            "function": "runAction",
            "class": "yii\\base\\Controller",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
            "line": 350,
            "function": "runAction",
            "class": "yii\\base\\Module",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
            "line": 649,
            "function": "runAction",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/craftcms/cms/src/web/Application.php",
            "line": 312,
            "function": "_processActionRequest",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/var/www/html/vendor/yiisoft/yii2/base/Application.php",
            "line": 384,
            "function": "handleRequest",
            "class": "craft\\web\\Application",
            "type": "->"
        },
        {
            "file": "/var/www/html/web/index.php",
            "line": 14,
            "function": "run",
            "class": "yii\\base\\Application",
            "type": "->"
        }
    ]
}

Steps to reproduce

  1. Add the voucher to the cart
  2. Add a product to the cart
  3. Go to the backend and open the cart
  4. Click on "add a custom line item"
  5. A network error occurs

Craft CMS version

Craft Pro 5.4.4

Plugin version

4.0.3

Multi-site?

Yes

Additional context

Craft Commerce 5.1.1

engram-design commented 2 weeks ago

Just to clarify - do you mean adding a Gift Voucher to your cart with a custom amount, or do you mean when applying a Gift Voucher Code to your cart? Both are working for me with Commerce 5.1.1.

I'm not surprised a custom line item causes issue though, looking into that.

gopeter commented 2 weeks ago

Sorry, nevermind the cart thing. Didn't worked because I'm hooking into some recalculation events and broke the gift voucher functionality.

But the custom line item issue still exists. Would be great if could have a look at it! :-)