2017-01-30 21:40:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Ninja\Import\CSV;
|
2016-05-31 23:16:05 +03:00
|
|
|
|
|
|
|
|
use App\Ninja\Import\BaseTransformer;
|
|
|
|
|
use League\Fractal\Resource\Item;
|
|
|
|
|
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
2017-01-30 21:40:43 +02:00
|
|
|
* Class ProductTransformer.
|
2016-07-03 18:11:58 +02:00
|
|
|
*/
|
2016-05-31 23:16:05 +03:00
|
|
|
class ProductTransformer extends BaseTransformer
|
|
|
|
|
{
|
2016-07-03 18:11:58 +02:00
|
|
|
/**
|
|
|
|
|
* @param $data
|
2017-01-30 21:40:43 +02:00
|
|
|
*
|
2016-07-03 18:11:58 +02:00
|
|
|
* @return bool|Item
|
|
|
|
|
*/
|
2016-05-31 23:16:05 +03:00
|
|
|
public function transform($data)
|
|
|
|
|
{
|
2016-12-22 17:28:42 +02:00
|
|
|
if (empty($data->product_key)) {
|
2016-05-31 23:16:05 +03:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new Item($data, function ($data) {
|
|
|
|
|
return [
|
|
|
|
|
'product_key' => $this->getString($data, 'product_key'),
|
|
|
|
|
'notes' => $this->getString($data, 'notes'),
|
2016-12-22 19:17:45 +02:00
|
|
|
'cost' => $this->getFloat($data, 'cost'),
|
2016-05-31 23:16:05 +03:00
|
|
|
];
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|