private function prepareItem($item)
{
$fields = ['cost' => 0, 'product_key' => '', 'notes' => '', 'qty' => 1];
foreach ($fields as $key => $val) {
if (!isset($item[$key])) {
$item[$key] = $val;
}
}
// if only the product key is set we'll load the cost and notes
if ($item['product_key'] && (!$item['cost'] || !$item['notes'])) {
$product = Product::findProductByKey($item['product_key']);
if ($product) {
if (!$item['cost']) {
$item['cost'] = $product->cost;
}
if (!$item['notes']) {
$item['notes'] = $product->notes;
}
}
}
return $item;
}