ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**
|
||||
* @package Plumrocket_GlobalPrivacyControl
|
||||
* @copyright Copyright (c) 2025 Plumrocket Inc.
|
||||
* @license https://plumrocket.com/license End-user License Agreement
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Plumrocket\GlobalPrivacyControl\Helper\Config;
|
||||
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
use Plumrocket\Base\Api\ConfigUtilsInterface;
|
||||
use Plumrocket\Base\Helper\ConfigUtils;
|
||||
use Plumrocket\GeoIPLookup\Api\LocationsListInterface;
|
||||
|
||||
class Geotargeting extends ConfigUtils
|
||||
{
|
||||
public const XML_PATH_TARGET_COUNTRIES = 'pr_gpc/general/geo_targeting';
|
||||
public const XML_PATH_TARGET_US_STATES = 'pr_gpc/general/states_geo_targeting';
|
||||
|
||||
/**
|
||||
* @var \Plumrocket\Base\Api\ConfigUtilsInterface
|
||||
*/
|
||||
private $configUtils;
|
||||
|
||||
/**
|
||||
* @param \Magento\Framework\App\Helper\Context $context
|
||||
* @param \Plumrocket\Base\Api\ConfigUtilsInterface $configUtils
|
||||
*/
|
||||
public function __construct(
|
||||
Context $context,
|
||||
ConfigUtilsInterface $configUtils
|
||||
) {
|
||||
parent::__construct($context);
|
||||
$this->configUtils = $configUtils;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $store
|
||||
* @param $scope
|
||||
* @return bool
|
||||
*/
|
||||
public function isEnabled($store = null, $scope = null): bool
|
||||
{
|
||||
return ! in_array(LocationsListInterface::ALL, $this->getTargetCountries($store, $scope), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $store
|
||||
* @param $scope
|
||||
* @return array
|
||||
*/
|
||||
public function getTargetCountries($store = null, $scope = null): array
|
||||
{
|
||||
$targetingConfig = (string) $this->configUtils->getConfig(self::XML_PATH_TARGET_COUNTRIES, $store, $scope);
|
||||
|
||||
return $this->configUtils->prepareMultiselectValue($targetingConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $store
|
||||
* @param $scope
|
||||
* @return array
|
||||
*/
|
||||
public function getTargetUsStates($store = null, $scope = null): array
|
||||
{
|
||||
if (! in_array(LocationsListInterface::COUNTRY_CODE_USA, $this->getTargetCountries($store, $scope), true)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$targetingConfig = $this->configUtils->prepareMultiselectValue(
|
||||
(string) $this->configUtils->getConfig(self::XML_PATH_TARGET_US_STATES, $store, $scope)
|
||||
);
|
||||
|
||||
if (in_array(LocationsListInterface::ALL, $targetingConfig, true)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $targetingConfig;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user