mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-08 05:24:29 -04:00
Add ability to hook into Product view
Adds ability to define dynamic relations on entities
This commit is contained in:
parent
44ee4e61c5
commit
1b2de482d0
32
app/Events/ProductWasCreated.php
Normal file
32
app/Events/ProductWasCreated.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Models\Product;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class ProductWasCreated extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Product
|
||||||
|
*/
|
||||||
|
public $product;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
**/
|
||||||
|
public $input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Product $product, $input = null)
|
||||||
|
{
|
||||||
|
$this->product = $product;
|
||||||
|
$this->input = $input;
|
||||||
|
}
|
||||||
|
}
|
26
app/Events/ProductWasDeleted.php
Normal file
26
app/Events/ProductWasDeleted.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Models\Product;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class ProductWasDeleted extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Product
|
||||||
|
*/
|
||||||
|
public $product;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Product $product)
|
||||||
|
{
|
||||||
|
$this->product = $product;
|
||||||
|
}
|
||||||
|
}
|
32
app/Events/ProductWasUpdated.php
Normal file
32
app/Events/ProductWasUpdated.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Events;
|
||||||
|
|
||||||
|
use App\Models\Product;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class ProductWasUpdated extends Event
|
||||||
|
{
|
||||||
|
use SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Product
|
||||||
|
*/
|
||||||
|
public $product;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var array
|
||||||
|
**/
|
||||||
|
public $input;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new event instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct(Product $product, $input = null)
|
||||||
|
{
|
||||||
|
$this->product = $product;
|
||||||
|
$this->input = $input;
|
||||||
|
}
|
||||||
|
}
|
@ -449,4 +449,20 @@ class EntityModel extends Eloquent
|
|||||||
|
|
||||||
return $this->id == $obj->id && $this->getEntityType() == $obj->entityType;
|
return $this->id == $obj->id && $this->getEntityType() == $obj->entityType;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @param $method
|
||||||
|
* @param $params
|
||||||
|
*/
|
||||||
|
public function __call($method, $params)
|
||||||
|
{
|
||||||
|
$entityType = $this->getEntityType();
|
||||||
|
if ($entityType) {
|
||||||
|
$config = implode('.', ['modules.relations.' . $entityType, $method]);
|
||||||
|
if (config()->has($config)) {
|
||||||
|
$function = config()->get($config);
|
||||||
|
return $function($this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return parent::__call($method, $params);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Ninja\Repositories;
|
namespace App\Ninja\Repositories;
|
||||||
|
|
||||||
use App\Models\Product;
|
use App\Models\Product;
|
||||||
|
use App\Events\ProductWasCreated;
|
||||||
|
use App\Events\ProductWasUpdated;
|
||||||
use Utils;
|
use Utils;
|
||||||
use DB;
|
use DB;
|
||||||
|
|
||||||
@ -72,6 +74,11 @@ class ProductRepository extends BaseRepository
|
|||||||
$product->qty = isset($data['qty']) ? Utils::parseFloat($data['qty']) : 1;
|
$product->qty = isset($data['qty']) ? Utils::parseFloat($data['qty']) : 1;
|
||||||
$product->save();
|
$product->save();
|
||||||
|
|
||||||
|
if ($publicId) {
|
||||||
|
event(new ProductWasUpdated($product, $data));
|
||||||
|
} else {
|
||||||
|
event(new ProductWasCreated($product, $data));
|
||||||
|
}
|
||||||
return $product;
|
return $product;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,4 +173,7 @@ return [
|
|||||||
'register' => [
|
'register' => [
|
||||||
'translations' => true,
|
'translations' => true,
|
||||||
],
|
],
|
||||||
|
'relations' => [
|
||||||
|
// all dynamic relations registered from modules are added here
|
||||||
|
],
|
||||||
];
|
];
|
||||||
|
@ -41,6 +41,25 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@foreach(Module::getOrdered() as $module)
|
||||||
|
@if(View::exists($module->alias . '::accounts.product'))
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-lg-10 col-lg-offset-1">
|
||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title in-white">
|
||||||
|
<i class="fa fa-{{ $module->icon }}"></i>
|
||||||
|
{{ $module->name }}
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body form-padding-right">
|
||||||
|
@includeIf($module->alias . '::accounts.product')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
<center class="buttons">
|
<center class="buttons">
|
||||||
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(HTMLUtils::previousUrl('/products'))->appendIcon(Icon::create('remove-circle')) !!}
|
{!! Button::normal(trans('texts.cancel'))->large()->asLinkTo(HTMLUtils::previousUrl('/products'))->appendIcon(Icon::create('remove-circle')) !!}
|
||||||
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
|
{!! Button::success(trans('texts.save'))->submit()->large()->appendIcon(Icon::create('floppy-disk')) !!}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user