mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Load custom product values when creating invoices using the API
This commit is contained in:
parent
bcda5ce0c7
commit
cdfc1195d8
@ -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',
|
||||||
|
'custom_value1',
|
||||||
|
'custom_value2',
|
||||||
|
];
|
||||||
|
foreach ($fields as $field) {
|
||||||
|
if (! isset($item[$field])) {
|
||||||
|
$item[$field] = $product->$field;
|
||||||
}
|
}
|
||||||
if (empty($item['notes'])) {
|
|
||||||
$item['notes'] = $product->notes;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user