diff --git a/application/libraries/Ilch/Translations/de.php b/application/libraries/Ilch/Translations/de.php index 50d9cb526..1713213b1 100644 --- a/application/libraries/Ilch/Translations/de.php +++ b/application/libraries/Ilch/Translations/de.php @@ -33,6 +33,8 @@ 'validation.errors.max.string' => '%s darf höchstens %s Zeichen lang sein.', 'validation.errors.max.array' => '%s darf höchstens %s Einträge haben.', 'validation.errors.timezone.notAValidTimezone' => '%s ist keine gültige Zeitzone.', + 'validation.errors.exists.resourceNotFound' => '%s konnte nicht gefunden werden.', + 'validation.errors.exists.resourceFound' => '%s wurde gefunden.', // general 'saveSuccess' => 'Erfolgreich gespeichert', diff --git a/application/libraries/Ilch/Translations/en.php b/application/libraries/Ilch/Translations/en.php index ef71bcd31..22d1199f9 100644 --- a/application/libraries/Ilch/Translations/en.php +++ b/application/libraries/Ilch/Translations/en.php @@ -33,6 +33,8 @@ 'validation.errors.max.string' => '%s may not be greater than %s characters.', 'validation.errors.max.array' => '%s may not have more than %s items.', 'validation.errors.timezone.notAValidTimezone' => '%s is not a valid timezone.', + 'validation.errors.exists.resourceNotFound' => '%s was not found.', + 'validation.errors.exists.resourceFound' => '%s was found.', // general 'saveSuccess' => 'Saved successful', diff --git a/application/modules/shop/config/config.php b/application/modules/shop/config/config.php index 9a27d5fa8..85ff5b0c6 100644 --- a/application/modules/shop/config/config.php +++ b/application/modules/shop/config/config.php @@ -14,7 +14,7 @@ class Config extends Install { public $config = [ 'key' => 'shop', - 'version' => '1.3.2', + 'version' => '1.3.3', 'icon_small' => 'fa-solid fa-cart-shopping', 'author' => 'blackcoder & LordSchirmer', 'link' => 'https://ilch.de', diff --git a/application/modules/shop/controllers/Customerarea.php b/application/modules/shop/controllers/Customerarea.php index e2d7fa1b6..7cf675d2a 100644 --- a/application/modules/shop/controllers/Customerarea.php +++ b/application/modules/shop/controllers/Customerarea.php @@ -71,7 +71,7 @@ public function showAction() if (!empty($order)) { $order = $order[0]; // Get the currency from the order as you don't want a currency change for existing orders. - $currency = $currencyMapper->getCurrencyById($order->getCurrencyId())[0]; + $currency = $currencyMapper->getCurrencyById($order->getCurrencyId()); } else { $order = []; } diff --git a/application/modules/shop/controllers/Index.php b/application/modules/shop/controllers/Index.php index e8b375cf9..58ff8b08c 100644 --- a/application/modules/shop/controllers/Index.php +++ b/application/modules/shop/controllers/Index.php @@ -33,7 +33,7 @@ public function indexAction() $itemsMapper = new ItemsMapper(); $userMapper = new UserMapper(); - $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency'))[0]; + $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency')); $user = null; if ($this->getUser()) { @@ -129,7 +129,7 @@ public function cartAction() $currencyMapper = new CurrencyMapper(); $itemsMapper = new ItemsMapper(); $settingsMapper = new SettingsMapper(); - $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency'))[0]; + $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency')); $this->getLayout()->header()->css('static/css/style_front.css'); $this->getLayout()->getTitle() @@ -170,7 +170,7 @@ public function orderAction() $settingsMapper = new SettingsMapper(); $ilchDate = new Date(); $captchaNeeded = captchaNeeded(); - $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency'))[0]; + $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency')); $addresses = []; $customer = null; @@ -479,7 +479,7 @@ public function showAction() $this->redirect(['action' => 'index']); } - $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency'))[0]; + $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency')); $category = $categoryMapper->getCategoryById($shopItem->getCatId()); $user = null; diff --git a/application/modules/shop/controllers/Payment.php b/application/modules/shop/controllers/Payment.php index 71b031fc2..c517172f0 100644 --- a/application/modules/shop/controllers/Payment.php +++ b/application/modules/shop/controllers/Payment.php @@ -57,6 +57,6 @@ public function indexAction() $this->getView()->set('itemsMapper', $itemsMapper); $this->getView()->set('order', $order); $this->getView()->set('settings', $settings); - $this->getView()->set('currency', $currencyMapper->getCurrencyById($order->getCurrencyId())[0]); + $this->getView()->set('currency', $currencyMapper->getCurrencyById($order->getCurrencyId())); } } diff --git a/application/modules/shop/controllers/admin/Currency.php b/application/modules/shop/controllers/admin/Currency.php index e5f8cf868..49d751588 100644 --- a/application/modules/shop/controllers/admin/Currency.php +++ b/application/modules/shop/controllers/admin/Currency.php @@ -104,7 +104,7 @@ public function indexAction() $currencyIds[] = $order->getCurrencyId(); } foreach ($this->getRequest()->getPost('check_currencies') as $id) { - $currencyInUse = (in_array($this->getConfig()->get('shop_currency'), $currencyIds) && $currencyMapper->getCurrencyById($id)[0]->getId() == $this->getConfig()->get('shop_currency')); + $currencyInUse = (in_array($this->getConfig()->get('shop_currency'), $currencyIds) && $currencyMapper->getCurrencyById($id)->getId() == $this->getConfig()->get('shop_currency')); if ($currencyInUse) { $this->addMessage('currencyInUse', 'danger'); @@ -145,7 +145,7 @@ public function treatAction() foreach ($orders as $order) { $currencyIds[] = $order->getCurrencyId(); } - $currencyInUse = (in_array($this->getConfig()->get('shop_currency'), $currencyIds) && $currencyMapper->getCurrencyById($id)[0]->getId() == $this->getConfig()->get('shop_currency')); + $currencyInUse = (in_array($this->getConfig()->get('shop_currency'), $currencyIds) && $currencyMapper->getCurrencyById($id)->getId() == $this->getConfig()->get('shop_currency')); } else { $this->getLayout()->getAdminHmenu() ->add($this->getTranslator()->trans('menuShops'), ['action' => 'index']) @@ -190,15 +190,9 @@ public function treatAction() } } - if ($this->getRequest()->getParam('id')) { - $currency = $currencyMapper->getCurrencyById($id); - } else { - $currency = []; - } + $currency = $this->getRequest()->getParam('id') ? $currencyMapper->getCurrencyById($id) : null; - if (count($currency) > 0) { - $currency = $currency[0]; - } else { + if (!$currency) { $currency = new CurrencyModel(); } @@ -219,7 +213,7 @@ public function deleteAction() foreach ($orders as $order) { $currencyIds[] = $order->getCurrencyId(); } - $currencyInUse = (in_array($this->getConfig()->get('shop_currency'), $currencyIds) && $currencyMapper->getCurrencyById($id)[0]->getId() == $this->getConfig()->get('shop_currency')); + $currencyInUse = (in_array($this->getConfig()->get('shop_currency'), $currencyIds) && $currencyMapper->getCurrencyById($id)->getId() == $this->getConfig()->get('shop_currency')); if ($currencyInUse) { $this->addMessage('currencyInUse', 'danger'); diff --git a/application/modules/shop/controllers/admin/Items.php b/application/modules/shop/controllers/admin/Items.php index a8a643890..6f4e81e82 100644 --- a/application/modules/shop/controllers/admin/Items.php +++ b/application/modules/shop/controllers/admin/Items.php @@ -96,7 +96,7 @@ public function indexAction() $ordersMapper = new OrdersMapper(); $itemsMapper = new ItemsMapper(); - $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency'))[0]; + $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency')); $this->getLayout()->getAdminHmenu() ->add($this->getTranslator()->trans('menuShops'), ['controller' => 'index', 'action' => 'index']) @@ -137,7 +137,7 @@ public function treatAction() $itemsMapper = new ItemsMapper(); $settingsMapper = new SettingsMapper(); - $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency'))[0]; + $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency')); if ($this->getRequest()->getParam('id')) { if (!is_numeric($this->getRequest()->getParam('id'))) { diff --git a/application/modules/shop/controllers/admin/Orders.php b/application/modules/shop/controllers/admin/Orders.php index c7efb82b6..b23c394df 100644 --- a/application/modules/shop/controllers/admin/Orders.php +++ b/application/modules/shop/controllers/admin/Orders.php @@ -122,7 +122,7 @@ public function treatAction() if ($this->getRequest()->getParam('id') && is_numeric($this->getRequest()->getParam('id'))) { $order = $ordersMapper->getOrderById($this->getRequest()->getParam('id')); // Get the currency from the order as you don't want a currency change for existing orders. - $currency = $currencyMapper->getCurrencyById($order->getCurrencyId())[0]; + $currency = $currencyMapper->getCurrencyById($order->getCurrencyId()); $this->getView()->set('order', $order); $this->getView()->set('currency', $currency->getName()); $this->getView()->set('itemsMapper', $itemsMapper); diff --git a/application/modules/shop/controllers/admin/Settings.php b/application/modules/shop/controllers/admin/Settings.php index ae8fcd3b2..53d324f78 100644 --- a/application/modules/shop/controllers/admin/Settings.php +++ b/application/modules/shop/controllers/admin/Settings.php @@ -163,7 +163,7 @@ public function defaultAction() $currencyMapper = new CurrencyMapper(); $settingsMapper = new SettingsMapper(); - $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency'))[0]; + $currency = $currencyMapper->getCurrencyById($this->getConfig()->get('shop_currency')); $this->getLayout()->getAdminHmenu() ->add($this->getTranslator()->trans('menuShops'), ['controller' => 'index', 'action' => 'index']) @@ -178,7 +178,8 @@ public function defaultAction() 'allowWillCollect' => 'required|numeric|integer|min:0|max:1', 'deliveryTextTop' => 'required', 'invoiceTextTop' => 'required', - 'invoiceTextBottom' => 'required' + 'invoiceTextBottom' => 'required', + 'shopCurrency' => 'required|exists:shop_currencies,id', ]); if ($validation->isValid()) { diff --git a/application/modules/shop/mappers/Currency.php b/application/modules/shop/mappers/Currency.php index 9241d2bed..9d4af4bd3 100644 --- a/application/modules/shop/mappers/Currency.php +++ b/application/modules/shop/mappers/Currency.php @@ -49,11 +49,17 @@ public function getCurrencies(array $where = []): array * Gets the currencies by id. * * @param int $id - * @return CurrencyModel[]|array + * @return CurrencyModel|null */ - public function getCurrencyById(int $id): array + public function getCurrencyById(int $id): ?CurrencyModel { - return $this->getCurrencies(['id' => $id]); + $currency = $this->getCurrencies(['id' => $id]); + + if (empty($currency)) { + return null; + } + + return reset($currency); } /**