// Check if a supplier id is passed and load the supplier model or set the supplier parameter to null.
if (!
empty($data['supplierId'
])) { $data['supplier'
] =
$this->
getManager()->
find(Supplier::
class,
$data['supplierId'
]);
if (empty($data['supplier'
])) { throw new CustomValidationException(sprintf('Supplier by id "%s" not found',
$data['supplierId'
]));
} } elseif (!
empty($data['supplier'
])) { $supplier =
$this->
getManager()->
getRepository(Supplier::
class)->
findOneBy(['name' =>
$data['supplier'
]]);
if (!
$supplier) { $supplier =
new Supplier();
$supplier->
setName($data['supplier'
]);
} $data['supplier'
] =
$supplier;
} else { unset($data['supplier'
]);
} // Check if a priceGroup id is passed and load the priceGroup model or set the priceGroup parameter to null.
if (isset($data['priceGroupId'
])) { if (empty($data['priceGroupId'
])) { $data['priceGroupId'
] = null;
}