diff --git a/src/Controller/UserController.php b/src/Controller/UserController.php index 1a4887c3..ec61210b 100644 --- a/src/Controller/UserController.php +++ b/src/Controller/UserController.php @@ -173,7 +173,7 @@ class UserController extends AdminPages\BaseAdminController $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { - $em->persist($user); + //$em->persist($user); $em->flush(); $this->addFlash('success', 'user.settings.saved_flash'); } diff --git a/src/Entity/UserSystem/User.php b/src/Entity/UserSystem/User.php index 25b8d942..1505c0ea 100644 --- a/src/Entity/UserSystem/User.php +++ b/src/Entity/UserSystem/User.php @@ -62,6 +62,7 @@ declare(strict_types=1); namespace App\Entity\UserSystem; use App\Entity\Base\NamedDBElement; +use App\Entity\PriceInformations\Currency; use App\Security\Interfaces\HasPermissionsInterface; use App\Validator\Constraints\Selectable; use App\Validator\Constraints\ValidPermission; @@ -172,18 +173,23 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf */ protected $settings = []; + /** + * @var Currency|null The currency the user wants to see prices in. + * Dont use fetch=EAGER here, this will cause problems with setting the currency setting. + * TODO: This is most likely a bug in doctrine/symfony related to the UniqueEntity constraint (it makes a db call). + * TODO: Find a way to use fetch EAGER (this improves performance a bit) + * @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency") + * @ORM\JoinColumn(name="currency_id", referencedColumnName="id") + * @Selectable() + */ + protected $currency = null; + /** @var PermissionsEmbed * @ORM\Embedded(class="PermissionsEmbed", columnPrefix="perms_") * @ValidPermission() */ protected $permissions; - /** - * @ORM\ManyToOne(targetEntity="App\Entity\PriceInformations\Currency", fetch="EAGER") - * @ORM\JoinColumn(name="currency_id", referencedColumnName="id") - */ - protected $currency = ''; - /** * @ORM\Column(type="text", name="config_image_path") */ @@ -284,6 +290,28 @@ class User extends NamedDBElement implements UserInterface, HasPermissionsInterf // $this->plainPassword = null; } + /** + * Gets the currency the user prefers when showing him prices. + * @return Currency|null The currency the user prefers, or null if the global currency should be used. + */ + public function getCurrency(): ?Currency + { + return $this->currency; + } + + /** + * Sets the currency the users prefers to see prices in. + * @param Currency|null $currency + * @return User + */ + public function setCurrency(?Currency $currency): User + { + $this->currency = $currency; + return $this; + } + + + /** * Returns the ID as an string, defined by the element class. * This should have a form like P000014, for a part with ID 14. diff --git a/src/Form/UserSettingsType.php b/src/Form/UserSettingsType.php index 9424e4bf..f559b22b 100644 --- a/src/Form/UserSettingsType.php +++ b/src/Form/UserSettingsType.php @@ -2,7 +2,10 @@ namespace App\Form; +use App\Entity\PriceInformations\Currency; use App\Entity\UserSystem\User; +use App\Form\Type\CurrencyEntityType; +use App\Form\Type\StructuralEntityType; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\EmailType; @@ -75,6 +78,10 @@ class UserSettingsType extends AbstractType 'placeholder' => $this->trans->trans('user_settings.theme.placeholder'), 'label' => $this->trans->trans('user.theme.label'), ]) + ->add('currency', CurrencyEntityType::class, [ + 'required' => false, + 'label' => $this->trans->trans('user.currency.label') + ]) //Buttons ->add('save', SubmitType::class, ['label' => 'save']) diff --git a/templates/Parts/info/_main_infos.html.twig b/templates/Parts/info/_main_infos.html.twig index 994bc659..7045f292 100644 --- a/templates/Parts/info/_main_infos.html.twig +++ b/templates/Parts/info/_main_infos.html.twig @@ -53,13 +53,13 @@ {% set min_order_amount = pricedetail_helper.minOrderAmount(part) %} {% set max_order_amount = pricedetail_helper.maxDiscountAmount(part) %} - {% set max_order_price = pricedetail_helper.calculateAvgPrice(part, max_order_amount) %} + {% set max_order_price = pricedetail_helper.calculateAvgPrice(part, max_order_amount, app.user.currency ?? null) %} {% if max_order_price is not null %} - {{ max_order_price | moneyFormat }} + {{ max_order_price | moneyFormat(app.user.currency ?? null) }} {% if min_order_amount < max_order_amount %} - - {{pricedetail_helper.calculateAvgPrice(part, min_order_amount) | moneyFormat }} + {{pricedetail_helper.calculateAvgPrice(part, min_order_amount, app.user.currency ?? null ) | moneyFormat(app.user.currency ?? null) }} {% endif %} {% endif %} diff --git a/templates/Parts/info/_order_infos.html.twig b/templates/Parts/info/_order_infos.html.twig index 657a4db1..40069346 100644 --- a/templates/Parts/info/_order_infos.html.twig +++ b/templates/Parts/info/_order_infos.html.twig @@ -43,14 +43,14 @@