diff --git a/app/Events/ProductWasCreated.php b/app/Events/ProductWasCreated.php new file mode 100644 index 0000000000..9098942c95 --- /dev/null +++ b/app/Events/ProductWasCreated.php @@ -0,0 +1,32 @@ +product = $product; + $this->input = $input; + } +} diff --git a/app/Events/ProductWasDeleted.php b/app/Events/ProductWasDeleted.php new file mode 100644 index 0000000000..1fcf5ac0c5 --- /dev/null +++ b/app/Events/ProductWasDeleted.php @@ -0,0 +1,26 @@ +product = $product; + } +} diff --git a/app/Events/ProductWasUpdated.php b/app/Events/ProductWasUpdated.php new file mode 100644 index 0000000000..21631f5b6a --- /dev/null +++ b/app/Events/ProductWasUpdated.php @@ -0,0 +1,32 @@ +product = $product; + $this->input = $input; + } +} diff --git a/app/Models/EntityModel.php b/app/Models/EntityModel.php index 7a37b2c195..d4df431d07 100644 --- a/app/Models/EntityModel.php +++ b/app/Models/EntityModel.php @@ -449,4 +449,20 @@ class EntityModel extends Eloquent 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); + } } diff --git a/app/Ninja/Repositories/ProductRepository.php b/app/Ninja/Repositories/ProductRepository.php index 86f9cfed59..87da50d6e4 100644 --- a/app/Ninja/Repositories/ProductRepository.php +++ b/app/Ninja/Repositories/ProductRepository.php @@ -3,6 +3,8 @@ namespace App\Ninja\Repositories; use App\Models\Product; +use App\Events\ProductWasCreated; +use App\Events\ProductWasUpdated; use Utils; use DB; @@ -72,6 +74,11 @@ class ProductRepository extends BaseRepository $product->qty = isset($data['qty']) ? Utils::parseFloat($data['qty']) : 1; $product->save(); + if ($publicId) { + event(new ProductWasUpdated($product, $data)); + } else { + event(new ProductWasCreated($product, $data)); + } return $product; } diff --git a/config/modules.php b/config/modules.php index 62c2d823bc..c9bebc84bd 100644 --- a/config/modules.php +++ b/config/modules.php @@ -173,4 +173,7 @@ return [ 'register' => [ 'translations' => true, ], + 'relations' => [ + // all dynamic relations registered from modules are added here + ], ]; diff --git a/resources/views/accounts/product.blade.php b/resources/views/accounts/product.blade.php index 279540070e..7b8ac86e4f 100644 --- a/resources/views/accounts/product.blade.php +++ b/resources/views/accounts/product.blade.php @@ -41,6 +41,25 @@ + @foreach(Module::getOrdered() as $module) + @if(View::exists($module->alias . '::accounts.product')) +