Merge pull request #677 from turbo124/master

Archive Product via API
This commit is contained in:
David Bomba 2016-02-01 13:33:27 +11:00
commit eef8ad22d0
2 changed files with 20 additions and 4 deletions

View File

@ -1,5 +1,6 @@
<?php namespace App\Http\Controllers;
use App\Ninja\Repositories\ProductRepository;
use App\Ninja\Transformers\ProductTransformer;
use Auth;
use Str;
@ -20,11 +21,14 @@ class ProductApiController extends BaseAPIController
{
protected $productService;
public function __construct(ProductService $productService)
protected $productRepo;
public function __construct(ProductService $productService, ProductRepository $productRepo)
{
parent::__construct();
$this->productService = $productService;
$this->productRepo = $productRepo;
}
public function index()
@ -52,8 +56,19 @@ class ProductApiController extends BaseAPIController
return $this->save();
}
public function update($publicId)
public function update(\Illuminate\Http\Request $request, $publicId)
{
if ($request->action == ACTION_ARCHIVE) {
$product = Product::scope($publicId)->withTrashed()->firstOrFail();
$this->productRepo->archive($product);
$transformer = new ProductTransformer(\Auth::user()->account, Input::get('serializer'));
$data = $this->createItem($product, $transformer, 'products');
return $this->response($data);
}
else
return $this->save($publicId);
}

View File

@ -16,6 +16,7 @@ class ProductTransformer extends EntityTransformer
'account_key' =>$this->account->account_key,
'default_tax_rate_id' =>$product->default_tax_rate_id,
'updated_at' =>$this->getTimestamp($product->updated_at),
'archived_at' => $this->getTimestamp($product->deleted_at),
];
}
}