Skip to content

Commit

Permalink
Inform user if product was not stored into distribution center
Browse files Browse the repository at this point in the history
Added catching of `ProductSaveEventDistributionException`
into `ProductsFormFactory` to inform user that product was
not stored into distribution center.

This exception has to be thrown from inside `ProductSaveEvent` handler
when your module is creating / updating product in distribution center.

KikaModule now throws this exception if creation/update was not
successful.

remp/crm#1804
  • Loading branch information
markoph committed Mar 17, 2021
1 parent e78b658 commit 8efbc4d
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/forms/ProductsFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Crm\ApplicationModule\DataProvider\DataProviderManager;
use Crm\ProductsModule\Builder\ProductBuilder;
use Crm\ProductsModule\DataProvider\ProductsFormDataProviderInterface;
use Crm\ProductsModule\Distribution\ProductSaveEventDistributionException;
use Crm\ProductsModule\Events\ProductSaveEvent;
use Crm\ProductsModule\ProductsCache;
use Crm\ProductsModule\Repository\DistributionCentersRepository;
Expand All @@ -22,6 +23,7 @@
use Nette\Database\Table\ActiveRow;
use Nette\Utils\Html;
use Tomaj\Form\Renderer\BootstrapRenderer;
use Tracy\Debugger;

class ProductsFormFactory
{
Expand Down Expand Up @@ -342,7 +344,14 @@ public function formSucceeded($form, $values)
$this->productPropertiesRepository->setProductProperties($product, $productProperties);
$this->productTagsRepository->setProductTags($product, $tags);

$this->emitter->emit(new ProductSaveEvent($product->id));
try {
$this->emitter->emit(new ProductSaveEvent($product->id));
} catch (ProductSaveEventDistributionException $e) {
Debugger::log($e, Debugger::EXCEPTION);
$form->addError($this->translator->translate('products.data.products.errors.not_stored_to_distribution_center'));
return;
}

$this->onUpdate->__invoke($product);

return;
Expand Down
1 change: 1 addition & 0 deletions src/lang/products.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ data:
ean13: EAN kód musí mít 13 znaků
template_property: Položka '%s' je povinná
vat: DPH je povinná
not_stored_to_distribution_center: 'Produkt se nepodařilo uložit do distribučního centra.'
tags:
fields:
name: Název
Expand Down
1 change: 1 addition & 0 deletions src/lang/products.en_US.neon
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ data:
ean13: EAN code must be 13 characters
template_property: Field '%s' is required
vat: VAT is required
not_stored_to_distribution_center: 'Unable to save product to distribution center.'
tags:
fields:
name: Name
Expand Down
1 change: 1 addition & 0 deletions src/lang/products.sk_SK.neon
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ data:
ean13: EAN kód musí mať 13 znakov
template_property: Položka '%s' je povinná
vat: DPH je povinná
not_stored_to_distribution_center: 'Produkt sa nepodarilo uložiť do distribučného centra.'
tags:
fields:
name: Názov
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace Crm\ProductsModule\Distribution;

class ProductSaveEventDistributionException extends \Exception
{

}

0 comments on commit 8efbc4d

Please sign in to comment.