Bind the Unique Field Code During Import
Key fields such as CODE must be trimmed before saving to prevent whitespace-related mismatches during lookups and duplicate checks. This page demonstrates the per-field code binding that runs alongside each entity field during import evaluation.
The example below uses the $value variable to retrieve the current column's value, trims whitespace, and saves the result to the model.
warning
This is a very important safety check for key fields. You should perform this trim every time you import a key field or a calculated key field.
/* $value contains the value of the current column in the import file, calling trim()
method (after casting as string type) to eliminate any space at the beginning or
at the end of the string */
$value = trim((string)$value);
/* after spaces were removed, the 'CODE' present in the import file is saved in the
cust_code field of the current model */
$model->setCustCode($value);