Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gopeter opened this issue Sep 19, 2024 · 2 comments
Open

Comments

@gopeter
Copy link

gopeter commented Sep 19, 2024

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
Copy link
Member

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
Copy link
Author

gopeter commented Sep 20, 2024

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! :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants