Your IP : 216.73.217.13


Current Path : /var/www/magento.test.indacotrentino.com/www/app/code/Webkul/BuyButton/Helper/
Upload File :
Current File : /var/www/magento.test.indacotrentino.com/www/app/code/Webkul/BuyButton/Helper/Data.php

<?php
/**
 * Webkul Software.
 *
 * @category  Webkul
 * @package   Webkul_BuyButton
 * @author    Webkul
 * @copyright Copyright (c)  Webkul Software Private Limited (https://webkul.com)
 * @license   https://store.webkul.com/license.html
 */
namespace Webkul\BuyButton\Helper;

use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Customer\Model\Session;
use Magento\Framework\Data\Form\FormKey\Validator as FormKeyValidator;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Api\SearchCriteriaInterface;
use Magento\Directory\Model\CurrencyConfig;
use Magento\Directory\Helper\Data as DirectoryHelper;

/**
 * BuyButton helper.
 */
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
    /**
     * @var Magento\Framework\Stdlib\DateTime\DateTime
     */
    protected $_date;

    /**
     * Customer session.
     *
     * @var \Magento\Customer\Model\Session
     */
    protected $_customerSession;

    /**
     * @var ObjectManagerInterface
     */
    protected $_objectManager;

    /**
     * @var \Magento\Framework\Data\Form\FormKey\Validator
     */
    protected $_formKeyValidator;

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

    /**
     * @var \Magento\Catalog\Api\ProductRepositoryInterface
     */
    protected $_productRepository;

    /**
     * @var \Magento\Directory\Model\Config\Source\Country
     */
    protected $_country;

    /**
     * @var \Magento\Directory\Model\RegionFactory
     */
    protected $_regionFactory;

    /**
     * @var Magento\Framework\Filesystem
     */
    protected $fileSystem;

    /**
     * @var SearchCriteriaBuilder
     */
    protected $searchCreteriaBuilder;

    /**
     * @var Magento\Framework\App\ProductMetadataInterface
     */
    protected $productMeta;

    /**
     * @var CurrencyConfig
     */
    protected $currencyConfig;

    /**
     * @var DirectoryHelper
     */
    protected $directoryHelper;

    /**
     * __constructor
     *
     * @param Session $customerSession
     * @param \Magento\Framework\App\Helper\Context $context
     * @param FormKeyValidator $formKeyValidator
     * @param DateTime $date
     * @param \Magento\Framework\ObjectManagerInterface $objectManager
     * @param \Magento\Store\Model\StoreManagerInterface $storeManager
     * @param \Magento\Catalog\Api\ProductRepositoryInterface $productRepository
     * @param \Magento\Directory\Model\Config\Source\Country $country
     * @param \Magento\Directory\Model\RegionFactory $regionFactory
     * @param \Magento\Framework\Filesystem $fileSystem
     * @param \Magento\Framework\Api\SearchCriteriaBuilder $searchCreteriaBuilder
     * @param \Magento\Framework\App\ProductMetadataInterface $productMeta
     * @param CurrencyConfig $currencyConfig
     * @param DirectoryHelper $directoryHelper
     */
    public function __construct(
        Session $customerSession,
        \Magento\Framework\App\Helper\Context $context,
        FormKeyValidator $formKeyValidator,
        DateTime $date,
        \Magento\Framework\ObjectManagerInterface $objectManager,
        \Magento\Store\Model\StoreManagerInterface $storeManager,
        \Magento\Catalog\Api\ProductRepositoryInterface $productRepository,
        \Magento\Directory\Model\Config\Source\Country $country,
        \Magento\Directory\Model\RegionFactory $regionFactory,
        \Magento\Framework\Filesystem $fileSystem,
        \Magento\Framework\Api\SearchCriteriaBuilder $searchCreteriaBuilder,
        \Magento\Framework\App\ProductMetadataInterface $productMeta,
        CurrencyConfig $currencyConfig,
        DirectoryHelper $directoryHelper
    ) {
        
        $this->_date = $date;
        $this->_customerSession = $customerSession;
        $this->_objectManager = $objectManager;
        $this->_formKeyValidator = $formKeyValidator;
        $this->_storeManager = $storeManager;
        $this->_productRepository = $productRepository;
        $this->_country  = $country;
        $this->_regionFactory = $regionFactory;
        $this->fileSystem = $fileSystem;
        $this->searchCreteriaBuilder = $searchCreteriaBuilder;
        $this->productMeta = $productMeta;
        $this->currencyConfig = $currencyConfig;
        $this->directoryHelper = $directoryHelper;

        parent::__construct($context);
    }

    /**
     * get creteria builder
     *
     * @return Magento\Framework\Api\SearchCriteriaBuilder
     */
    public function getCreteriaBuilder()
    {
        return $this->searchCreteriaBuilder;
    }

    /**
     * get access key
     *
     * @return string
     */
    public function getAccessKey()
    {
        return $this->scopeConfig->getValue(
            "buybutton/general_settings/access_key",
            \Magento\Store\Model\ScopeInterface::SCOPE_STORES
        );
    }

    /**
     * get do redirect
     *
     * @return string
     */
    public function getDoRedirect()
    {
        return $this->scopeConfig->getValue(
            "buybutton/general_settings/do_redirect",
            \Magento\Store\Model\ScopeInterface::SCOPE_STORES
        );
    }

    /**
     * get allowed currency
     *
     * @return string
     */
    public function getAllowedCurrency()
    {
        $allowedCurrencies = $this->currencyConfig->getConfigCurrencies('currency/options/allow');
        $appBaseCurrencyCode = $this->directoryHelper->getBaseCurrencyCode();
        if (!in_array($appBaseCurrencyCode, $allowedCurrencies)) {
            $allowedCurrencies[] = $appBaseCurrencyCode;
        }
        foreach ($this->_storeManager->getStores() as $store) {
            $code = $store->getBaseCurrencyCode();
            if (!in_array($code, $allowedCurrencies)) {
                $allowedCurrencies[] = $code;
            }
        }

        return array_values($allowedCurrencies);
    }

    /**
     * get allowed currency
     *
     * @return string
     */
    public function getAllStores()
    {
        $stores = $this->_storeManager->getStores(false, true);
        $storeArray = [];
        foreach ($stores as $code => $store) {
            array_push($storeArray, [
                'label' => $code,
                'value' => $store->getId()
            ]);
        }
        return $storeArray;
    }

    /**
     * get locale code
     *
     * @param int $storeId
     * @return string
     */
    public function getLocaleCode($storeId)
    {
        return $this->scopeConfig->getValue(
            'general/locale/code',
            \Magento\Store\Model\ScopeInterface::SCOPE_STORE,
            $storeId
        );
    }
}