b374k
m1n1 1.01
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 / MageWorx / GiftCards / Helper /
Filename/home/a/home/dev2.destoffenstraat.com/app/code/MageWorx/GiftCards/Helper/Data.php
Size7.81 kb
Permissionrwxrwxrwx
Ownerroot : root
Create time21-Aug-2025 12:26
Last modified13-May-2022 10:39
Last accessed22-Aug-2025 22:33
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © MageWorx. All rights reserved.
* See LICENSE.txt for license details.
*/

namespace MageWorx\GiftCards\Helper;

use Magento\Store\Model\ScopeInterface;

/**
* MageWorx data helper
*/
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
/**#@+
* XML paths for config settings
*/
const XML_SHOW_IN_CART = 'mageworx_giftcards/main/show_in_shopping_cart';
const XML_EXPAND_GIFT_CARD_BLOCK = 'mageworx_giftcards/main/expand_gift_card_block';
const XML_APPLY_TO_TOTAL_AMOUNTS = 'mageworx_giftcards/main/apply_to';
const XML_CARD_ACTIVATION_ORDER_STATUSES = 'mageworx_giftcards/main/orderstatus';
const XML_ORDER_STATUSES = 'mageworx_giftcards/email/orderstatus';
const XML_ADD_CODE_TO_PRODUCT = 'mageworx_giftcards/main/add_code_to_product';
const XML_SUPPORT_MAIL = 'trans_email/ident_general/email';
const XML_DISABLE_MULTISHIPPING = 'mageworx_giftcards/main/disable_multishipping';
const XML_EXPIRATION_ALERT = 'mageworx_giftcards/email/expiration_alert';
const XML_USE_DEFAULT_GIFTCARDS_PICTURE = 'mageworx_giftcards/email/giftcards_picture';
const XML_EMAIL_TEMPLATE_IDENTIFIER = 'mageworx_giftcards/email/email_template';
const XML_PRINT_TEMPLATE_IDENTIFIER = 'mageworx_giftcards/email/print_template';
const XML_OFFLINE_TEMPLATE_IDENTIFIER = 'mageworx_giftcards/email/offline_template';
const XML_EXPIRED_TEMPLATE_IDENTIFIER = 'mageworx_giftcards/email/expired_template';
const XML_EXPIRATION_ALERT_TEMPLATE_IDENTIFIER = 'mageworx_giftcards/email/expiration_alert_template';

/**
* @var \Magento\Store\Model\Information
*/
protected $storeInformation;

/**
* Store manager
*
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $storeManager;

/**
* Data constructor.
*
* @param \Magento\Framework\App\Helper\Context $context
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Store\Model\Information $storeInformation
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function __construct(
\Magento\Framework\App\Helper\Context $context,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Store\Model\Information $storeInformation
) {
$this->storeManager = $storeManager;
$this->storeInformation = $storeInformation->getStoreInformationObject($this->storeManager->getStore());
parent::__construct($context);
}

public function showInCart()
{
return (bool)$this->scopeConfig->getValue(
self::XML_SHOW_IN_CART,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return bool
*/
public function isExpandedGiftCardBlock()
{
return (bool)$this->scopeConfig->getValue(self::XML_EXPAND_GIFT_CARD_BLOCK, ScopeInterface::SCOPE_STORE);
}

/**
* @return array
*/
public function getApplyToTotalAmounts()
{
$totalAmounts = $this->scopeConfig->getValue(
self::XML_APPLY_TO_TOTAL_AMOUNTS,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);

if (!$totalAmounts) {
return [];
}

return explode(',', $totalAmounts);
}

public function getStoreName()
{
return $this->storeInformation['name'];
}

public function getSupportMail()
{
return $this->scopeConfig->getValue(self::XML_SUPPORT_MAIL, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

public function getOrderStatuses()
{
return $this->scopeConfig->getValue(self::XML_ORDER_STATUSES, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* Retrieve comma-separated order statuses
*
* @return string|null
*/
public function getCardActivationOrderStatuses()
{
return $this->scopeConfig->getValue(
self::XML_CARD_ACTIVATION_ORDER_STATUSES,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return bool
*/
public function getAddCodeToProduct()
{
return (bool)$this->scopeConfig->getValue(
self::XML_ADD_CODE_TO_PRODUCT,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string
*/
public function getStorePhone()
{
return $this->storeInformation['phone'];
}

/**
* @return bool
*/
public function getIsDisableMultishipping()
{
return (bool)$this->scopeConfig->getValue(
self::XML_DISABLE_MULTISHIPPING,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @param $xmlPath
* @return mixed
*/
public function getConfigValue($xmlPath)
{
return $this->scopeConfig->getValue($xmlPath, \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
}

/**
* @param $item
* @return bool
*/
public function isExpired($item)
{
if (!$item->getExpireDate()) {
return false;
}
$daysLeft = $this->calculateExpireIn($item->getExpireDate());

return $daysLeft < 0;
}

/**
* @param $product
* @return bool|string
*/
public function getExpireDateForProduct($product)
{
$lifetimeValue = $product->getMageworxGcLifetimeValue();
$expireDate = '';
if (!empty($lifetimeValue)) {
$expireDate = date_add(date_create(), date_interval_create_from_date_string($lifetimeValue . 'days'));
}

return $expireDate;
}

/**
* @param string $expireDate
* @return float
*/
public function calculateExpireIn($expireDate)
{
return round((strtotime($expireDate)) - strtotime(date('M d Y'))) / 3600 / 24;
}

/**
* @return string
*/
public function getAlertDays()
{
return $this->scopeConfig->getValue(
self::XML_EXPIRATION_ALERT,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return mixed
*/
public function isUseDefaultGiftCardsPicture()
{
return $this->scopeConfig->getValue(
self::XML_USE_DEFAULT_GIFTCARDS_PICTURE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string
*/
public function getEmailTemplateIdentifier()
{
return $this->scopeConfig->getValue(
self::XML_EMAIL_TEMPLATE_IDENTIFIER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string
*/
public function getPrintTemplateIdentifier()
{
return $this->scopeConfig->getValue(
self::XML_PRINT_TEMPLATE_IDENTIFIER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string
*/
public function getOfflineTemplateIdentifier()
{
return $this->scopeConfig->getValue(
self::XML_OFFLINE_TEMPLATE_IDENTIFIER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string
*/
public function getExpirationAlertTemplateIdentifier()
{
return $this->scopeConfig->getValue(
self::XML_EXPIRATION_ALERT_TEMPLATE_IDENTIFIER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}

/**
* @return string
*/
public function getExpiredTemplateIdentifier()
{
return $this->scopeConfig->getValue(
self::XML_EXPIRED_TEMPLATE_IDENTIFIER,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
}