123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462 |
- <?php
- /**
- * Refer to LICENSE.txt distributed with the Temando Shipping module for notice of license
- */
- namespace Temando\Shipping\Model\Config;
- use Magento\Framework\DataObjectFactory;
- use Magento\Framework\Module\ModuleList;
- use Temando\Shipping\Webservice\Config\WsConfigInterface;
- /**
- * Temando Config Values Handler
- *
- * @package Temando\Shipping\Model
- * @author Sebastian Ertner <sebastian.ertner@netresearch.de>
- * @author Christoph Aßmann <christoph.assmann@netresearch.de>
- * @author Max Melzer <max.melzer@netresearch.de>
- * @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
- * @link https://www.temando.com/
- */
- class ModuleConfig implements ModuleConfigInterface, WsConfigInterface
- {
- const CONFIG_XML_PATH_CHECKOUT_ENABLED = 'carriers/temando/active';
- const CONFIG_XML_PATH_LOGGING_ENABLED = 'carriers/temando/logging_enabled';
- const CONFIG_XML_PATH_SESSION_ENDPOINT = 'carriers/temando/session_endpoint';
- const CONFIG_XML_PATH_API_ENDPOINT = 'carriers/temando/sovereign_endpoint';
- const CONFIG_XML_PATH_API_VERSION = 'carriers/temando/api_version';
- const CONFIG_XML_PATH_ACCOUNT_ID = 'carriers/temando/account_id';
- const CONFIG_XML_PATH_BEARER_TOKEN = 'carriers/temando/bearer_token';
- const CONFIG_XML_PATH_BEARER_TOKEN_EXPIRY = 'carriers/temando/bearer_token_expiry';
- const CONFIG_XML_PATH_SYNC_ENABLED = 'carriers/temando/sync_enabled';
- const CONFIG_XML_PATH_SYNC_SHIPMENTS_ENABLED = 'carriers/temando/sync_shipments_enabled';
- const CONFIG_XML_PATH_SYNC_ORDERS_ENABLED = 'carriers/temando/sync_orders_enabled';
- const CONFIG_XML_PATH_SYNC_STREAM_ID = 'carriers/temando/sync_stream_id';
- const CONFIG_XML_PATH_CHECKOUT_FIELDS = 'carriers/temando/additional_checkout_fields';
- const CONFIG_XML_PATH_REGISTER_ACCOUNT_URL = 'carriers/temando/register_account_url';
- const CONFIG_XML_PATH_SHIPPING_PORTAL_URL = 'carriers/temando/shipping_portal_url';
- const CONFIG_XML_PATH_TEMANDO_RETURNS_ACTIVE = 'carriers/temando/rma_enabled';
- const CONFIG_XML_PATH_COLLECTION_POINTS_ENABLED = 'carriers/temando/collectionpoints_enabled';
- const CONFIG_XML_PATH_COLLECTION_POINTS_COUNTRIES = 'carriers/temando/collectionpoints_countries';
- const CONFIG_XML_PATH_CLICK_AND_COLLECT_ENABLED = 'carriers/temando/clickandcollect_enabled';
- const CONFIG_XML_PATH_CLICK_AND_COLLECT_COUNTRIES = 'carriers/temando/clickandcollect_countries';
- /**
- * @var DataObjectFactory
- */
- private $dataObjectFactory;
- /**
- * @var ConfigAccessor
- */
- private $configAccessor;
- /**
- * @var ModuleList
- */
- private $moduleList;
- /**
- * ModuleConfig constructor.
- *
- * @param DataObjectFactory $dataObjectFactory
- * @param ConfigAccessor $configAccessor
- * @param ModuleList $moduleList
- */
- public function __construct(
- DataObjectFactory $dataObjectFactory,
- ConfigAccessor $configAccessor,
- ModuleList $moduleList
- ) {
- $this->dataObjectFactory = $dataObjectFactory;
- $this->configAccessor = $configAccessor;
- $this->moduleList = $moduleList;
- }
- /**
- * Check if shipping module is enabled in checkout.
- *
- * @param int $storeId
- *
- * @return bool
- */
- public function isEnabled($storeId = null)
- {
- return (bool) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_CHECKOUT_ENABLED, $storeId);
- }
- /**
- * Check if webservice communication logging is enabled.
- *
- * @return bool
- */
- public function isLoggingEnabled()
- {
- return (bool) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_LOGGING_ENABLED);
- }
- /**
- * @param int $storeId
- * @return \Magento\Framework\DataObject
- */
- public function getStoreInformation($storeId = null)
- {
- $storeInformation = $this->configAccessor->getConfigValue(
- 'general/store_information',
- $storeId
- );
- $storeInfo = $this->dataObjectFactory->create(['data' => (array)$storeInformation]);
- return $storeInfo;
- }
- /**
- * @param int $storeId
- * @return \Magento\Framework\DataObject
- */
- public function getShippingOrigin($storeId = null)
- {
- $shippingOrigin = $this->configAccessor->getConfigValue(
- 'shipping/origin',
- $storeId
- );
- $storeInfo = $this->dataObjectFactory->create(['data' => (array)$shippingOrigin]);
- return $storeInfo;
- }
- /**
- * @param int $storeId
- * @return string
- */
- public function getWeightUnit($storeId = null)
- {
- return $this->configAccessor->getConfigValue('general/locale/weight_unit', $storeId);
- }
- /**
- * Obtain Register Account Url.
- *
- * @return string
- */
- public function getRegisterAccountUrl()
- {
- return (string) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_REGISTER_ACCOUNT_URL);
- }
- /**
- * Obtain Shipping Portal Url.
- *
- * @return string
- */
- public function getShippingPortalUrl()
- {
- return (string) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_SHIPPING_PORTAL_URL);
- }
- /**
- * Check if merchant registered an account at Temando.
- *
- * @return bool
- */
- public function isRegistered()
- {
- return ($this->getAccountId() !== '') && ($this->getBearerToken() !== '');
- }
- /**
- * Read URL of Temando REST API.
- *
- * @return string
- */
- public function getSessionEndpoint()
- {
- return $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_SESSION_ENDPOINT);
- }
- /**
- * Read URL of Temando REST API.
- *
- * @return string
- */
- public function getApiEndpoint()
- {
- return $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_API_ENDPOINT);
- }
- /**
- * Save URL of Temando REST API.
- *
- * @param string $apiEndpoint
- * @return void
- */
- public function saveApiEndpoint($apiEndpoint)
- {
- $this->configAccessor->saveConfigValue(self::CONFIG_XML_PATH_API_ENDPOINT, $apiEndpoint);
- }
- /**
- * Obtain the API version to connect to.
- *
- * @return string
- */
- public function getApiVersion()
- {
- return (string) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_API_VERSION);
- }
- /**
- * Read Temando Account Id.
- *
- * @return string
- */
- public function getAccountId()
- {
- return (string) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_ACCOUNT_ID);
- }
- /**
- * Save Temando Account Id.
- *
- * @param string $accountId
- * @return void
- */
- public function saveAccountId($accountId)
- {
- $this->configAccessor->saveConfigValue(self::CONFIG_XML_PATH_ACCOUNT_ID, $accountId);
- }
- /**
- * Read Temando Authentication Token.
- *
- * @return string
- */
- public function getBearerToken()
- {
- return (string)$this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_BEARER_TOKEN);
- }
- /**
- * Save Temando Authentication Token.
- *
- * @param string $bearerToken
- * @return void
- */
- public function saveBearerToken($bearerToken)
- {
- $this->configAccessor->saveConfigValue(self::CONFIG_XML_PATH_BEARER_TOKEN, $bearerToken);
- }
- /**
- * Read Temando Authentication Token Expiry Timestamp.
- *
- * @return string
- */
- public function getBearerTokenExpiry()
- {
- return (string) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_BEARER_TOKEN_EXPIRY);
- }
- /**
- * Save Temando Authentication Token Expiry Timestamp.
- *
- * @param string $bearerTokenExpiry
- * @return void
- */
- public function saveBearerTokenExpiry($bearerTokenExpiry)
- {
- $this->configAccessor->saveConfigValue(self::CONFIG_XML_PATH_BEARER_TOKEN_EXPIRY, $bearerTokenExpiry);
- }
- /**
- * Check whether stream events should be processed or not.
- *
- * @return bool
- */
- public function isSyncEnabled()
- {
- return (bool) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_SYNC_ENABLED);
- }
- /**
- * Save new stream event processing configuration.
- *
- * @param string $value
- * @return void
- */
- public function saveSyncEnabled($value)
- {
- $this->configAccessor->saveConfigValue(self::CONFIG_XML_PATH_SYNC_ENABLED, $value);
- }
- /**
- * Check whether shipment events should be processed or not.
- *
- * @return bool
- */
- public function isSyncShipmentEnabled()
- {
- return (bool) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_SYNC_SHIPMENTS_ENABLED);
- }
- /**
- * Save new stream event processing configuration.
- *
- * @param string $value
- * @return void
- */
- public function saveSyncShipmentEnabled($value)
- {
- $this->configAccessor->saveConfigValue(self::CONFIG_XML_PATH_SYNC_SHIPMENTS_ENABLED, $value);
- }
- /**
- * Check whether order events should be processed or not.
- *
- * @return bool
- */
- public function isSyncOrderEnabled()
- {
- return (bool) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_SYNC_ORDERS_ENABLED);
- }
- /**
- * Save new stream event processing configuration.
- *
- * @param string $value
- * @return void
- */
- public function saveSyncOrderEnabled($value)
- {
- $this->configAccessor->saveConfigValue(self::CONFIG_XML_PATH_SYNC_ORDERS_ENABLED, $value);
- }
- /**
- * Multiple streams may exists. Obtain the stream ID to request events from.
- *
- * @return string
- */
- public function getStreamId()
- {
- return (string) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_SYNC_STREAM_ID);
- }
- /**
- * Get checkout field definitions. This is the plain serialized string as stored in config.
- *
- * @return string
- */
- public function getCheckoutFieldsDefinition()
- {
- $checkoutFields = (string) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_CHECKOUT_FIELDS);
- if (!$checkoutFields) {
- $checkoutFields = '[]';
- }
- return $checkoutFields;
- }
- /**
- * Check if RMA feature is enabled.
- *
- * @return bool
- */
- public function isRmaEnabled()
- {
- return (bool) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_TEMANDO_RETURNS_ACTIVE);
- }
- /**
- * Check if RMA module is installed
- *
- * @return bool
- */
- public function isRmaAvailable()
- {
- return (bool) $this->moduleList->has('Magento_Rma');
- }
- /**
- * Save checkout field definitions in config.
- *
- * @param string $fieldsDefinition
- * @return void
- */
- public function saveCheckoutFieldsDefinition($fieldsDefinition)
- {
- $this->configAccessor->saveConfigValue(self::CONFIG_XML_PATH_CHECKOUT_FIELDS, $fieldsDefinition);
- }
- /**
- * Check if collection points feature is enabled in config.
- *
- * @param int $storeId
- *
- * @return bool
- */
- public function isCollectionPointsEnabled($storeId = null)
- {
- return (bool) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_COLLECTION_POINTS_ENABLED, $storeId);
- }
- /**
- * Obtain country codes enabled for collection point deliveries.
- *
- * @param int $storeId
- *
- * @return string[]
- */
- public function getCollectionPointDeliveryCountries($storeId = null)
- {
- return $this->configAccessor->getConfigValue(
- self::CONFIG_XML_PATH_COLLECTION_POINTS_COUNTRIES,
- $storeId
- );
- }
- /**
- * Check if click and collect feature is enabled in config.
- *
- * @param int $storeId
- *
- * @return bool
- */
- public function isClickAndCollectEnabled($storeId = null)
- {
- return (bool) $this->configAccessor->getConfigValue(self::CONFIG_XML_PATH_CLICK_AND_COLLECT_ENABLED, $storeId);
- }
- /**
- * Save new account data.
- *
- * @param string $accountId
- * @param string $bearerToken
- * @param string $bearerTokenExpiry
- * @return void
- */
- public function setAccount($accountId, $bearerToken, $bearerTokenExpiry)
- {
- $this->saveAccountId($accountId);
- $this->saveBearerToken($bearerToken);
- $this->saveBearerTokenExpiry($bearerTokenExpiry);
- }
- /**
- * Unset all account data.
- *
- * @return void
- */
- public function unsetAccount()
- {
- $this->configAccessor->deleteConfigValue(self::CONFIG_XML_PATH_ACCOUNT_ID);
- $this->configAccessor->deleteConfigValue(self::CONFIG_XML_PATH_BEARER_TOKEN);
- $this->configAccessor->deleteConfigValue(self::CONFIG_XML_PATH_BEARER_TOKEN_EXPIRY);
- }
- }
|