Load custom product values when creating invoices using the API

This commit is contained in:
Hillel Coren 2017-10-17 21:04:54 +03:00
parent bcda5ce0c7
commit cdfc1195d8

View File

@ -290,14 +290,19 @@ class InvoiceApiController extends BaseAPIController
private function prepareItem($item) private function prepareItem($item)
{ {
// if only the product key is set we'll load the cost and notes // if only the product key is set we'll load the cost and notes
if (! empty($item['product_key']) && empty($item['cost']) && empty($item['notes'])) { if (! empty($item['product_key'])) {
$product = Product::findProductByKey($item['product_key']); $product = Product::findProductByKey($item['product_key']);
if ($product) { if ($product) {
if (empty($item['cost'])) { $fields = [
$item['cost'] = $product->cost; 'cost',
} 'notes',
if (empty($item['notes'])) { 'custom_value1',
$item['notes'] = $product->notes; 'custom_value2',
];
foreach ($fields as $field) {
if (! isset($item[$field])) {
$item[$field] = $product->$field;
}
} }
} }
} }