2017-01-30 20:40:43 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Ninja\Transformers;
|
2015-11-19 12:50:35 +01:00
|
|
|
|
|
|
|
use App\Models\Product;
|
|
|
|
|
2016-12-29 17:17:17 +01:00
|
|
|
/**
|
|
|
|
* @SWG\Definition(definition="Product", @SWG\Xml(name="Product"))
|
|
|
|
*/
|
2015-11-19 12:50:35 +01:00
|
|
|
class ProductTransformer extends EntityTransformer
|
|
|
|
{
|
2016-12-29 17:17:17 +01:00
|
|
|
/**
|
2017-01-30 20:40:43 +01:00
|
|
|
* @SWG\Property(property="id", type="integer", example=1, readOnly=true)
|
|
|
|
* @SWG\Property(property="product_key", type="string", example="Item")
|
|
|
|
* @SWG\Property(property="notes", type="string", example="Notes...")
|
2017-03-08 17:03:35 +01:00
|
|
|
* @SWG\Property(property="cost", type="number", format="float", example=10.00)
|
|
|
|
* @SWG\Property(property="qty", type="number", format="float", example=1)
|
2017-03-09 11:11:45 +01:00
|
|
|
* @SWG\Property(property="updated_at", type="integer", example=1451160233, readOnly=true)
|
|
|
|
* @SWG\Property(property="archived_at", type="integer", example=1451160233, readOnly=true)
|
2017-01-30 20:40:43 +01:00
|
|
|
*/
|
2015-11-19 12:50:35 +01:00
|
|
|
public function transform(Product $product)
|
|
|
|
{
|
2016-05-04 08:53:43 +02:00
|
|
|
return array_merge($this->getDefaults($product), [
|
2015-11-19 12:50:35 +01:00
|
|
|
'id' => (int) $product->public_id,
|
|
|
|
'product_key' => $product->product_key,
|
|
|
|
'notes' => $product->notes,
|
|
|
|
'cost' => $product->cost,
|
|
|
|
'qty' => $product->qty,
|
2017-05-17 11:18:48 +02:00
|
|
|
'tax_name1' => $product->tax_name1 ?: '',
|
|
|
|
'tax_rate1' => (float) $product->tax_rate1,
|
|
|
|
'tax_name2' => $product->tax_name2 ?: '',
|
|
|
|
'tax_rate2' => (float) $product->tax_rate2,
|
2017-01-30 20:40:43 +01:00
|
|
|
'updated_at' => $this->getTimestamp($product->updated_at),
|
2016-02-01 03:32:12 +01:00
|
|
|
'archived_at' => $this->getTimestamp($product->deleted_at),
|
2017-09-11 04:41:27 +02:00
|
|
|
'custom_value1' => $product->custom_value1,
|
|
|
|
'custom_value2' => $product->custom_value2,
|
2016-05-03 22:02:29 +02:00
|
|
|
]);
|
2015-11-19 12:50:35 +01:00
|
|
|
}
|
2016-12-29 17:17:17 +01:00
|
|
|
}
|