Question

I have a very simple piece of code :

$dropOrder = new DropOrder($dropOrderId);
$dropOrder->is_supplier_paid = $payValue;
$dropOrder->save();

It works and saves a 'is_supplier_paid' field value into the database. But it also does unexpected actions and fills all null valued fields with 0 values.

I try to save it like this :

$dropOrder->save(true);

But I still have the same strange behavior. I want to change one field only and don't touch the other ones.

Was it helpful?

Solution

Values are formated by ObjectModel::formatValue() before they are inserted / updated, based on the type of the field declared in your $definition.

You have to use TYPE_NOTHING to allow NULL values, it's the only way.

Take a look in Configuration class, with id_shop and id_group_shop fields.

OTHER TIPS

PrestaShop 1.7:

I ran into the same problem in PS 1.7 and set TYPE_NOTHING is not sufficient to resolve this issue. In my case i also needed to add allow_null to true in the field's definition:

'my_field' => ['type' => self::TYPE_NOTHING, 'allow_null' => true, 'value' => null]

('value' => null is probably not necessary but suggested)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top