Lookup product details when importing invoice CSV

This commit is contained in:
Hillel Coren 2017-07-07 13:25:51 +03:00
parent 3151fb9085
commit 6e89fcd0cb
3 changed files with 28 additions and 2 deletions

View File

@ -108,6 +108,30 @@ class BaseTransformer extends TransformerAbstract
return isset($this->maps[ENTITY_PRODUCT][$name]) ? $this->maps[ENTITY_PRODUCT][$name] : null;
}
/**
* @param $name
*
* @return null
*/
public function getProductNotes($name)
{
$name = strtolower(trim($name));
return isset($this->maps['product_notes'][$name]) ? $this->maps['product_notes'][$name] : null;
}
/**
* @param $name
*
* @return null
*/
public function getProductCost($name)
{
$name = strtolower(trim($name));
return isset($this->maps['product_cost'][$name]) ? $this->maps['product_cost'][$name] : null;
}
/**
* @param $name
*

View File

@ -38,8 +38,8 @@ class InvoiceTransformer extends BaseTransformer
'invoice_items' => [
[
'product_key' => $this->getString($data, 'product'),
'notes' => $this->getString($data, 'notes'),
'cost' => $this->getFloat($data, 'amount'),
'notes' => $this->getString($data, 'notes') ?: $this->getProductNotes($this->getString($data, 'product')),
'cost' => $this->getFloat($data, 'amount') ?: $this->getProductCost($this->getString($data, 'product')),
'qty' => $this->getFloat($data, 'quantity') ?: 1,
],
],

View File

@ -911,6 +911,8 @@ class ImportService
{
if ($key = strtolower(trim($product->product_key))) {
$this->maps['product'][$key] = $product->id;
$this->maps['product_notes'][$key] = $product->notes;
$this->maps['product_cost'][$key] = $product->cost;
}
}