Files

115 lines
2.8 KiB
PHP
Raw Permalink Normal View History

<?php
namespace Shopkeeper\VendorSalesReport\Helper;
use Magento\Framework\App\Helper\AbstractHelper;
use Magento\Framework\App\Helper\Context;
use Magento\Store\Model\ScopeInterface;
class Data extends AbstractHelper
{
const XML_PATH_ENABLED = 'vendorsalesreport/general/enabled';
const XML_PATH_ORDER_STATUS = 'vendorsalesreport/general/order_status';
const XML_PATH_EMAIL_ENABLED = 'vendorsalesreport/email/enabled';
const XML_PATH_EMAIL_RECIPIENTS = 'vendorsalesreport/email/recipients';
const XML_PATH_EMAIL_SUBJECT = 'vendorsalesreport/email/subject';
const XML_PATH_EMAIL_SENDER = 'vendorsalesreport/email/sender';
/**
* Check if automated report is enabled
*
* @return bool
*/
public function isEnabled()
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_ENABLED,
ScopeInterface::SCOPE_STORE
);
}
/**
* Get order status filter
*
* @return array
*/
public function getOrderStatus()
{
$value = $this->scopeConfig->getValue(
self::XML_PATH_ORDER_STATUS,
ScopeInterface::SCOPE_STORE
);
if (is_string($value)) {
return explode(',', $value);
}
return is_array($value) ? $value : ['complete'];
}
/**
* Check if email is enabled
*
* @return bool
*/
public function isEmailEnabled()
{
return $this->scopeConfig->isSetFlag(
self::XML_PATH_EMAIL_ENABLED,
ScopeInterface::SCOPE_STORE
);
}
/**
* Get email recipients
*
* @return array
*/
public function getEmailRecipients()
{
$recipients = $this->scopeConfig->getValue(
self::XML_PATH_EMAIL_RECIPIENTS,
ScopeInterface::SCOPE_STORE
);
if (empty($recipients)) {
return [];
}
return array_map('trim', explode(',', $recipients));
}
/**
* Get email subject
*
* @param string $month
* @param string $year
* @return string
*/
public function getEmailSubject($month = null, $year = null)
{
$subject = $this->scopeConfig->getValue(
self::XML_PATH_EMAIL_SUBJECT,
ScopeInterface::SCOPE_STORE
);
if ($month && $year) {
$subject = str_replace(['{{month}}', '{{year}}'], [$month, $year], $subject);
}
return $subject ?: 'Monthly Thermo Report';
}
/**
* Get email sender
*
* @return string
*/
public function getEmailSender()
{
return $this->scopeConfig->getValue(
self::XML_PATH_EMAIL_SENDER,
ScopeInterface::SCOPE_STORE
) ?: 'general';
}
}