Extending customer results SQLSTATE[23000]

Help for integrating the Laravel package
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Extending customer results SQLSTATE[23000]

Post by createanet » 21 Sep 2021, 09:41

Hello,

Ive extended the customer following the decorator method described in the docs.

I notice in my logs that I am seeing the following errors. Specifically when the user checks out as a guest and check the box to create an account - which is obviously failing.

Code: Select all

Unable to create an account: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'reward_points' cannot be null:
My implementation is simple, here is the attributes I am using in the decorator.

Code: Select all

[
    'reward_points' => [
        'code' => 'reward_points',
        'internalcode' => ' lvu."reward_points"',
        'label' => 'Reward Points',
        'type' => 'integer',
        'internaltype' => Base::PARAM_INT,
    ],
]
And here is my schemea

Code: Select all

[
    'table' => [
        'users' => function (Schema $schema) {
            $table = $schema->getTable('users');
            $table->addColumn('reward_points', 'integer', [
                'default' => 0,
            ]);
            return $schema;
        },
    ]
]
I know I can make the field nullable which solves the issue, perhaps that what I should do...but I would prefer to use an integer here. Reading the docs on the doctrine website the default is nullable so I shouldn't need to set the notnull flag

Does anyone have similar experiences?

Thanks

User avatar
aimeos
Administrator
Posts: 7884
Joined: 01 Jan 1970, 00:00

Re: Extending customer results SQLSTATE[23000]

Post by aimeos » 21 Sep 2021, 13:54

Doctrine default value settting is NOT NULL, thus the message.
You should add

Code: Select all

'notnull' => false
if your schema file. The other option is to overwrite the item and manager like described here:
https://aimeos.org/docs/latest/models/e ... custom-way
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Extending customer results SQLSTATE[23000]

Post by createanet » 21 Sep 2021, 13:59

Thanks for confirming. What is confusing me is the default value you assign in the schema?

If there is no value, then I would expect the default to have been used in this instance.

It seems like my options are

1. Make the the column nullable

2. Overwrite the manager and manually assign the default.

createanet
Posts: 72
Joined: 22 Mar 2021, 16:56

Re: Extending customer results SQLSTATE[23000]

Post by createanet » 05 Nov 2021, 12:21

A few months later and I have come across this thread I created after still having the issue :)

I managed to solve it and not have to go through the process of implementing new managers, items and queries by implementing the following method in my decorator which sets the default value.

Code: Select all

public function createItem(array $values = []): \Aimeos\MShop\Common\Item\Iface
{
    return parent::createItem(array_merge($values, [
        'reward_points' => 0
    ]));
}

Post Reply