|
Apache/2.4.41 (Ubuntu) Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) server ip : 62.171.164.128 | your ip : 127.0.0.1 safemode OFF > / home / a / home / dev2.destoffenstraat.com / app / code / Neklo / LowStockNotification / Helper / |
Filename | /home/a/home/dev2.destoffenstraat.com/app/code/Neklo/LowStockNotification/Helper/Config.php |
Size | 4.88 kb |
Permission | rwxrwxrwx |
Owner | root : root |
Create time | 21-Aug-2025 12:26 |
Last modified | 06-Apr-2021 18:06 |
Last accessed | 23-Aug-2025 20:45 |
Actions | edit | rename | delete | download (gzip) |
View | text | code | image |
<?php
/*
NOTICE OF LICENSE
This source file is subject to the NekloEULA that is bundled with this package in the file ICENSE.txt.
It is also available through the world-wide-web at this URL: http://store.neklo.com/LICENSE.txt
Copyright (c) Neklo (http://store.neklo.com/)
*/
namespace Neklo\LowStockNotification\Helper;
use InvalidArgumentException;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\ScopeInterface;
use Neklo\Core\Model\Config\Backend\ArraySerialized\Email as EmailBackendModel;
use Neklo\Core\Serialize\Serializer;
class Config extends AbstractHelper
{
/**
* The configuration path for the value:
* - "Low Stock Notification / Notification Settings / Notify Instantly"
* - "Inventory / Product Stock Options / Low Stock Notification Instantly"
*/
const LOW_STOCK_NOTIFICATION_INSTANT_IS_ENABLE = 'neklo_lowstocknotification/notification/instant_is_enabled';
/**
* The configuration path for the value:
* - "Low Stock Notification / Notification Settings / Notify by Cron"
* - "Inventory / Product Stock Options / Low Stock Notification by Cron"
*/
const LOW_STOCK_NOTIFICATION_CRON_IS_ENABLED = 'neklo_lowstocknotification/notification/cron_is_enabled';
/**
* The configuration path for the value:
* - "Low Stock Notification / Notification Settings / Recipient Emails"
* - "Inventory / Product Stock Options / Low Stock Notification Emails"
*/
const LOW_STOCK_NOTIFICATION_EMAIL = 'neklo_lowstocknotification/notification/emails';
/**
* The configuration path for the value
* - "Low Stock Notification / Notification Settings / Sender"
* - "Inventory / Product Stock Options / Low Stock Notification Sender"
*/
const LOW_STOCK_NOTIFICATION_IDENTITY = 'neklo_lowstocknotification/notification/email_identity';
/**
* @var Serializer
*/
private $serializer;
/**
* @param Context $context
* @param Serializer $serializer
*/
public function __construct(Context $context, Serializer $serializer)
{
parent::__construct($context);
$this->serializer = $serializer;
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
public function isEnabledInstant($store = null)
{
return $this->scopeConfig->isSetFlag(
self::LOW_STOCK_NOTIFICATION_INSTANT_IS_ENABLE,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
public function isEnabledCron($store = null)
{
return $this->scopeConfig->isSetFlag(
self::LOW_STOCK_NOTIFICATION_CRON_IS_ENABLED,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return array
*/
public function getEmailList($store = null)
{
$emails = (string)$this->scopeConfig->getValue(
self::LOW_STOCK_NOTIFICATION_EMAIL,
ScopeInterface::SCOPE_STORE,
$store
);
if (!$emails) {
return [];
}
try {
$emails = $this->serializer->unserialize($emails);
if (!is_array($emails)) {
$emails = (array)$emails;
}
} catch (LocalizedException $e) {
$emails = [];
} catch (InvalidArgumentException $e) {
$emails = [];
}
$emailList = [];
foreach ($emails as $email) {
if (isset($email[EmailBackendModel::FIELD_EMAIL])) {
$emailList[] = $email[EmailBackendModel::FIELD_EMAIL];
}
}
$emailList = array_filter($emailList);
return $emailList;
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return string
*/
public function getEmailSender($store = null)
{
return (string)$this->scopeConfig->getValue(
self::LOW_STOCK_NOTIFICATION_IDENTITY,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
public function canSendInstant($store = null)
{
return $this->isEnabledInstant($store) && $this->canSend($store);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
public function canSendCron($store = null)
{
return $this->isEnabledCron($store) && $this->canSend($store);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
private function canSend($store = null)
{
return $this->getEmailSender($store) && !empty($this->getEmailList($store));
}
}
/*
NOTICE OF LICENSE
This source file is subject to the NekloEULA that is bundled with this package in the file ICENSE.txt.
It is also available through the world-wide-web at this URL: http://store.neklo.com/LICENSE.txt
Copyright (c) Neklo (http://store.neklo.com/)
*/
namespace Neklo\LowStockNotification\Helper;
use InvalidArgumentException;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\ScopeInterface;
use Neklo\Core\Model\Config\Backend\ArraySerialized\Email as EmailBackendModel;
use Neklo\Core\Serialize\Serializer;
class Config extends AbstractHelper
{
/**
* The configuration path for the value:
* - "Low Stock Notification / Notification Settings / Notify Instantly"
* - "Inventory / Product Stock Options / Low Stock Notification Instantly"
*/
const LOW_STOCK_NOTIFICATION_INSTANT_IS_ENABLE = 'neklo_lowstocknotification/notification/instant_is_enabled';
/**
* The configuration path for the value:
* - "Low Stock Notification / Notification Settings / Notify by Cron"
* - "Inventory / Product Stock Options / Low Stock Notification by Cron"
*/
const LOW_STOCK_NOTIFICATION_CRON_IS_ENABLED = 'neklo_lowstocknotification/notification/cron_is_enabled';
/**
* The configuration path for the value:
* - "Low Stock Notification / Notification Settings / Recipient Emails"
* - "Inventory / Product Stock Options / Low Stock Notification Emails"
*/
const LOW_STOCK_NOTIFICATION_EMAIL = 'neklo_lowstocknotification/notification/emails';
/**
* The configuration path for the value
* - "Low Stock Notification / Notification Settings / Sender"
* - "Inventory / Product Stock Options / Low Stock Notification Sender"
*/
const LOW_STOCK_NOTIFICATION_IDENTITY = 'neklo_lowstocknotification/notification/email_identity';
/**
* @var Serializer
*/
private $serializer;
/**
* @param Context $context
* @param Serializer $serializer
*/
public function __construct(Context $context, Serializer $serializer)
{
parent::__construct($context);
$this->serializer = $serializer;
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
public function isEnabledInstant($store = null)
{
return $this->scopeConfig->isSetFlag(
self::LOW_STOCK_NOTIFICATION_INSTANT_IS_ENABLE,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
public function isEnabledCron($store = null)
{
return $this->scopeConfig->isSetFlag(
self::LOW_STOCK_NOTIFICATION_CRON_IS_ENABLED,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return array
*/
public function getEmailList($store = null)
{
$emails = (string)$this->scopeConfig->getValue(
self::LOW_STOCK_NOTIFICATION_EMAIL,
ScopeInterface::SCOPE_STORE,
$store
);
if (!$emails) {
return [];
}
try {
$emails = $this->serializer->unserialize($emails);
if (!is_array($emails)) {
$emails = (array)$emails;
}
} catch (LocalizedException $e) {
$emails = [];
} catch (InvalidArgumentException $e) {
$emails = [];
}
$emailList = [];
foreach ($emails as $email) {
if (isset($email[EmailBackendModel::FIELD_EMAIL])) {
$emailList[] = $email[EmailBackendModel::FIELD_EMAIL];
}
}
$emailList = array_filter($emailList);
return $emailList;
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return string
*/
public function getEmailSender($store = null)
{
return (string)$this->scopeConfig->getValue(
self::LOW_STOCK_NOTIFICATION_IDENTITY,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
public function canSendInstant($store = null)
{
return $this->isEnabledInstant($store) && $this->canSend($store);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
public function canSendCron($store = null)
{
return $this->isEnabledCron($store) && $this->canSend($store);
}
/**
* @param ScopeInterface|string|int|null $store
*
* @return bool
*/
private function canSend($store = null)
{
return $this->getEmailSender($store) && !empty($this->getEmailList($store));
}
}