Skip to content

Argument 1 passed to yii2mod\cart\Cart::add() must be an instance of yii2mod\cart\models\CartItemInterface #33

Open
@gabriele-carbonai

Description

@gabriele-carbonai

Hello,
I have this error:
Argument 1 passed to yii2mod\cart\Cart::add() must be an instance of yii2mod\cart\models\CartItemInterface

is in this method:
public function add(CartItemInterface $element, $save = true): self

I follow the doc and configured the extension in correct way:

'cart' => [
            'class' => 'yii2mod\cart\Cart',
            // you can change default storage class as following:
            'storageClass' => [
                'class' => 'yii2mod\cart\storage\DatabaseStorage',
                // you can also override some properties
                'deleteIfEmpty' => true
            ]
        ],

Then in my controller, just this simple code:

public function actionCart()
{
        $cart = \Yii::$app->cart;
        $cart->add(2); 
}

I tried to:

  1. Remove configuration in main.php and is not working because configuration are missing, so mean is correctly configurate
  2. implement CartItemInterface in controller
  3. implement add() method in model and call from controller
  4. I try to pass in method integer, array and string

Where I am wrong?
Thank you

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions