fixes for updating products

This commit is contained in:
David Bomba 2020-11-04 00:57:48 +11:00
parent d762c5e842
commit f98e7d15da
2 changed files with 12 additions and 6 deletions

View File

@ -18,7 +18,6 @@ use App\Models\Product;
use App\Repositories\InvoiceRepository;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Database\Capsule\Eloquent;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
@ -27,11 +26,11 @@ class UpdateOrCreateProduct implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $products;
public $products;
private $invoice;
public $invoice;
private $company;
public $company;
/**
* Create a new job instance.
@ -59,7 +58,14 @@ class UpdateOrCreateProduct implements ShouldQueue
{
MultiDB::setDB($this->company->db);
foreach ($this->products as $item) {
//only update / create products - not tasks or gateway fees
$updateable_products = collect($this->products)->filter(function ($item) {
return $item->type_id == 1;
});
foreach ($updateable_products as $item) {
if (empty($item->product_key)) {
continue;
}

View File

@ -270,7 +270,7 @@ class BaseRepository
$model = $model->service()->applyNumber()->save();
if ($model->company->update_products !== false) {
UpdateOrCreateProduct::dispatch($model->line_items, $model, $model->company);
UpdateOrCreateProduct::dispatchNow($model->line_items, $model, $model->company);
}
if ($class->name == Invoice::class) {