123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618 |
- <?php
- /**
- * @copyright Vertex. All rights reserved. https://www.vertexinc.com/
- * @author Mediotype https://www.mediotype.com/
- */
- namespace Vertex\Tax\Model;
- use Magento\Framework\App\Config\ScopeConfigInterface;
- use Magento\Store\Model\ScopeInterface;
- use Magento\Tax\Model\Config as TaxConfig;
- use Vertex\Tax\Model\Config\DeliveryTerm;
- /**
- * Configuration retrieval tool
- */
- class Config
- {
- /**
- * @var string
- * @deprecated This will be removed in the near future as we stop using a calculation method to determine if enabled
- */
- const CALC_UNIT_VERTEX = 'VERTEX_UNIT_BASE_CALCULATION';
- const CONFIG_XML_PATH_ROTATION_ACTION = 'tax/vertex_logging/rotation_action';
- const CONFIG_XML_PATH_DEFAULT_CUSTOMER_CODE = 'tax/classes/default_customer_code';
- const CONFIG_XML_PATH_DEFAULT_TAX_CALCULATION_ADDRESS_TYPE = 'tax/calculation/based_on';
- const CONFIG_XML_PATH_ENABLE_VERTEX = 'tax/vertex_settings/enable_vertex';
- const CONFIG_XML_PATH_ENABLE_TAX_CALCULATION = 'tax/vertex_settings/use_for_calculation';
- const CONFIG_XML_PATH_LOGGING_ENABLED = 'tax/vertex_logging/enable_logging';
- const CONFIG_XML_PATH_PRINTED_CARD_PRICE = 'sales/gift_options/printed_card_price';
- const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';
- const CONFIG_XML_PATH_TAX_APPLY_ON = 'tax/calculation/apply_tax_on';
- const CONFIG_XML_PATH_TAX_DISPLAY_IN_CATALOG = 'tax/display/type';
- const CONFIG_XML_PATH_VERTEX_API_KEY = 'tax/vertex_settings/password';
- const CONFIG_XML_PATH_VERTEX_API_TRUSTED_ID = 'tax/vertex_settings/trustedId';
- const CONFIG_XML_PATH_VERTEX_API_USER = 'tax/vertex_settings/login';
- const CONFIG_XML_PATH_VERTEX_CITY = 'tax/vertex_seller_info/city';
- const CONFIG_XML_PATH_VERTEX_COMPANY_CODE = 'tax/vertex_seller_info/company';
- const CONFIG_XML_PATH_VERTEX_COUNTRY = 'tax/vertex_seller_info/country_id';
- const CONFIG_XML_PATH_VERTEX_ENABLE_LOG_ROTATION = 'tax/vertex_logging/enable_rotation';
- const CONFIG_XML_PATH_VERTEX_INVOICE_DATE = 'tax/vertex_settings/invoice_tax_date';
- const CONFIG_XML_PATH_VERTEX_INVOICE_ORDER = 'tax/vertex_settings/invoice_order';
- const CONFIG_XML_PATH_VERTEX_DELIVERY_TERM_DEFAULT = 'tax/vertex_delivery_terms/default_term';
- const CONFIG_XML_PATH_VERTEX_DELIVERY_TERM_OVERRIDE = 'tax/vertex_delivery_terms/override';
- const CONFIG_XML_PATH_VERTEX_INVOICE_ORDER_STATUS = 'tax/vertex_settings/invoice_order_status';
- const CONFIG_XML_PATH_VERTEX_LOCATION_CODE = 'tax/vertex_seller_info/location_code';
- const CONFIG_XML_PATH_VERTEX_LOG_ROTATION_FREQUENCY = 'tax/vertex_logging/rotation_frequency';
- const CONFIG_XML_PATH_VERTEX_LOG_ROTATION_RUNTIME = 'tax/vertex_logging/rotation_runtime';
- const CONFIG_XML_PATH_VERTEX_POSTAL_CODE = 'tax/vertex_seller_info/postalCode';
- const CONFIG_XML_PATH_VERTEX_REGION = 'tax/vertex_seller_info/region_id';
- const CONFIG_XML_PATH_VERTEX_STREET1 = 'tax/vertex_seller_info/streetAddress1';
- const CONFIG_XML_PATH_VERTEX_STREET2 = 'tax/vertex_seller_info/streetAddress2';
- const CRON_STRING_PATH = 'crontab/default/jobs/vertex_log_rotation/schedule/cron_expr';
- const MAX_CHAR_PRODUCT_CODE_ALLOWED = 40;
- const VALUE_APPLY_ON_CUSTOM = 0;
- const VALUE_APPLY_ON_ORIGINAL_ONLY = 1;
- const VERTEX_ADDRESS_API_HOST = 'tax/vertex_settings/address_api_url';
- const VERTEX_COUNTRY_SORT_REGION = 'tax/vertex_settings/country_sort_by_region';
- const VERTEX_ALLOWED_COUNTRIES = 'tax/vertex_settings/allowed_countries';
- const VERTEX_SUMMARIZE_TAX = 'tax/vertex_settings/summarize_tax';
- const VERTEX_API_HOST = 'tax/vertex_settings/api_url';
- const VERTEX_CREDITMEMO_ADJUSTMENT_CLASS = 'tax/classes/creditmemo_adjustment_class';
- const VERTEX_CREDITMEMO_ADJUSTMENT_NEGATIVE_CODE = 'tax/classes/creditmemo_adjustment_negative_code';
- const VERTEX_CREDITMEMO_ADJUSTMENT_POSITIVE_CODE = 'tax/classes/creditmemo_adjustment_positive_code';
- const VERTEX_GIFTWRAP_ITEM_CLASS = 'tax/classes/giftwrap_item_class';
- const VERTEX_GIFTWRAP_ITEM_CODE_PREFIX = 'tax/classes/giftwrap_item_code';
- const VERTEX_GIFTWRAP_ORDER_CLASS = 'tax/classes/giftwrap_order_class';
- const VERTEX_GIFTWRAP_ORDER_CODE = 'tax/classes/giftwrap_order_code';
- const VERTEX_LOG_LIFETIME_DAYS = 'tax/vertex_logging/entry_lifetime';
- const VERTEX_PRINTED_GIFTCARD_CLASS = 'tax/classes/printed_giftcard_class';
- const VERTEX_PRINTED_GIFTCARD_CODE = 'tax/classes/printed_giftcard_code';
- /** @var DeliveryTerm */
- private $deliveryTermConfig;
- /** @var ScopeConfigInterface */
- private $scopeConfig;
- /**
- * @param ScopeConfigInterface $scopeConfig
- * @param DeliveryTerm $deliveryTermConfig
- */
- public function __construct(ScopeConfigInterface $scopeConfig, DeliveryTerm $deliveryTermConfig)
- {
- $this->scopeConfig = $scopeConfig;
- $this->deliveryTermConfig = $deliveryTermConfig;
- }
- /**
- * Retrieve which price we should be applying tax to
- *
- * @param null $store
- * @param string $scope
- * @return string
- */
- public function getApplyTaxOn($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_TAX_APPLY_ON, $store, $scope);
- }
- /**
- * Get the City of the Company Address
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCompanyCity($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_CITY, $store, $scope);
- }
- /**
- * Retrieve the Company Code
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCompanyCode($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_COMPANY_CODE, $store, $scope);
- }
- /**
- * Get the Country of the Company Address
- *
- * @param string|null $store
- * @param string $scope
- * @return bool|float|null
- */
- public function getCompanyCountry($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- $country = $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_COUNTRY, $store, $scope);
- return $country !== null ? $country : false;
- }
- /**
- * Get the Postal Code of the Company Address
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCompanyPostalCode($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_POSTAL_CODE, $store, $scope);
- }
- /**
- * Get the Region ID of the Company Address
- *
- * @param string|null $store
- * @param string $scope
- * @return bool|float|null
- */
- public function getCompanyRegionId($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- $region = $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_REGION, $store, $scope);
- return $region !== null ? $region : false;
- }
- /**
- * Get Line 1 of the Company Street Address
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCompanyStreet1($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_STREET1, $store, $scope);
- }
- /**
- * Get Line 2 of the Company Street Address
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCompanyStreet2($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_STREET2, $store, $scope);
- }
- /**
- * Retrieve a value from the configuration within a scope
- *
- * @param string $value
- * @param string|null $scopeId
- * @param string|null $scope
- * @return mixed
- */
- public function getConfigValue($value, $scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->scopeConfig->getValue($value, $scope, $scopeId);
- }
- /**
- * Get the Tax class for a creditmemo adjustment fee
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCreditmemoAdjustmentFeeClass($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_CREDITMEMO_ADJUSTMENT_CLASS, $store, $scope);
- }
- /**
- * Get the code for a creditmemo adjustment fee
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCreditmemoAdjustmentFeeCode($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_CREDITMEMO_ADJUSTMENT_NEGATIVE_CODE, $store, $scope);
- }
- /**
- * Get the tax class for a positive adjustment on a creditmemo
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCreditmemoAdjustmentPositiveClass($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_CREDITMEMO_ADJUSTMENT_CLASS, $store, $scope);
- }
- /**
- * Get the positive adjustment code for a creditmemo
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getCreditmemoAdjustmentPositiveCode($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_CREDITMEMO_ADJUSTMENT_POSITIVE_CODE, $store, $scope);
- }
- /**
- * Retrieve the frequency at which the cron should run
- *
- * @return string
- */
- public function getCronRotationFrequency()
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_LOG_ROTATION_FREQUENCY);
- }
- /**
- * Retrieve the time of day logs should be rotated
- *
- * @return string
- */
- public function getCronRotationTime()
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_LOG_ROTATION_RUNTIME);
- }
- /**
- * Retrieve the lifetime of logs, in days, before they are rotated
- *
- * @return string
- */
- public function getCronLogLifetime()
- {
- return $this->getConfigValue(self::VERTEX_LOG_LIFETIME_DAYS);
- }
- /**
- * Get the Default Customer Code
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getDefaultCustomerCode($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_DEFAULT_CUSTOMER_CODE, $store, $scope);
- }
- /**
- * Get the default Delivery Term
- *
- * @param string|null $store
- * @param string $scope
- * @return string
- */
- public function getDefaultDeliveryTerm($store = null, $scope = ScopeInterface::SCOPE_WEBSITE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_DELIVERY_TERM_DEFAULT, $store, $scope);
- }
- /**
- * Get the Delivery Term to Override
- *
- * @param string|null $store
- * @param string $scope
- * @return array
- */
- public function getDeliveryTermOverride($store = null, $scope = ScopeInterface::SCOPE_WEBSITE)
- {
- $configValue = $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_DELIVERY_TERM_OVERRIDE, $store, $scope);
- return $this->deliveryTermConfig->unserializeValue($configValue);
- }
- /**
- * Get the Tax Class for Item-level Giftwrapping
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getGiftWrappingItemClass($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_GIFTWRAP_ITEM_CLASS, $store, $scope);
- }
- /**
- * Get the code prefix for Item-level Giftwrapping
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getGiftWrappingItemCodePrefix($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_GIFTWRAP_ITEM_CODE_PREFIX, $store, $scope);
- }
- /**
- * Get the Tax Class for Order-level Giftwrapping
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getGiftWrappingOrderClass($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_GIFTWRAP_ORDER_CLASS, $store, $scope);
- }
- /**
- * Get the code for Order-level Giftwrapping
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getGiftWrappingOrderCode($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_GIFTWRAP_ORDER_CODE, $store, $scope);
- }
- /**
- * Retrieve the Location Code
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getLocationCode($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_LOCATION_CODE, $store, $scope);
- }
- /**
- * Retrieve the price of a Printed Gift Card
- *
- * @param string|null $store
- * @param string $scope
- * @return mixed
- */
- public function getPrintedCardPrice($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_PRINTED_CARD_PRICE, $store, $scope);
- }
- /**
- * Get the Tax Class for a Printed Gift Card
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getPrintedGiftcardClass($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_PRINTED_GIFTCARD_CLASS, $store, $scope);
- }
- /**
- * Get the code for a Printed Gift Card
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getPrintedGiftcardCode($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_PRINTED_GIFTCARD_CODE, $store, $scope);
- }
- /**
- * Retrieve the type of action to take to logs when rotating
- *
- * @return string|null
- */
- public function getRotationAction()
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_ROTATION_ACTION);
- }
- /**
- * Get the Tax Class ID to be used for Shipping
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getShippingTaxClassId($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $store, $scope);
- }
- /**
- * Get the Trusted ID for the Vertex Integration
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getTrustedId($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_API_TRUSTED_ID, $store, $scope);
- }
- /**
- * Get the URL of the Tax Area Lookup API Endpoint
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getVertexAddressHost($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_ADDRESS_API_HOST, $store, $scope);
- }
- /**
- * Get the URL of the Quotation and Invoicing API Endpoint
- *
- * @param string|null $store
- * @param string $scope
- * @return float|null
- */
- public function getVertexHost($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_API_HOST, $store, $scope);
- }
- /**
- * Grab the Order Status during which we should commit to the Tax Log
- *
- * @param string|null $store
- * @param string $scope
- * @return string
- */
- public function invoiceOrderStatus($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_INVOICE_ORDER_STATUS, $store, $scope);
- }
- /**
- * Determine if Vertex Logging has been enabled
- *
- * @param string|null $scopeCode
- * @param string $scope
- * @return bool
- */
- public function isLoggingEnabled($scopeCode = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->scopeConfig->isSetFlag(self::CONFIG_XML_PATH_LOGGING_ENABLED, $scope, $scopeCode);
- }
- /**
- * Retrieve a list of countries grouped by Vertex region
- *
- * @param string|null $store
- * @param string $scope
- * @return array A multi-dimensional array where the top level key is the Vertex region the country is associated
- * with and the value is an array of country codes
- */
- public function getListForAllowedCountrySort($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- $returnArray = json_decode($this->getConfigValue(self::VERTEX_COUNTRY_SORT_REGION, $store, $scope), true);
- return $returnArray ?: [];
- }
- /**
- * Retrieve list of countries Vertex should be used for
- *
- * @param string|null $store
- * @param string $scope
- * @return string[] of two character ISO country codes
- */
- public function getAllowedCountries($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return explode(',', $this->getConfigValue(self::VERTEX_ALLOWED_COUNTRIES, $store, $scope));
- }
- /**
- * Determine whether or not tax is turned on to display in the catalog
- *
- * @param string|null $store
- * @param string $scope
- * @return bool
- */
- public function isDisplayPriceInCatalogEnabled($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- $configValue = $this->getConfigValue(self::CONFIG_XML_PATH_TAX_DISPLAY_IN_CATALOG, $store, $scope);
- return (int)$configValue !== TaxConfig::DISPLAY_TYPE_EXCLUDING_TAX;
- }
- /**
- * Determine if Vertex has been enabled
- *
- * @param string|null $scopeId
- * @param string $scope
- * @return bool
- */
- public function isVertexActive($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->scopeConfig->isSetFlag(self::CONFIG_XML_PATH_ENABLE_VERTEX, $scope, $scopeId);
- }
- /**
- * Determine if tax calculation is enabled
- *
- * @param string|null $scopeId
- * @param string $scope
- * @return bool
- */
- public function isTaxCalculationEnabled($scopeId = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->scopeConfig->isSetFlag(self::CONFIG_XML_PATH_ENABLE_TAX_CALCULATION, $scope, $scopeId);
- }
- /**
- * Determine if Vertex Archiving has been enabled.
- *
- * @return bool
- */
- public function isLogRotationEnabled()
- {
- return $this->scopeConfig->isSetFlag(
- self::CONFIG_XML_PATH_VERTEX_ENABLE_LOG_ROTATION,
- ScopeConfigInterface::SCOPE_TYPE_DEFAULT
- );
- }
- /**
- * Determine if we commit to the Tax Log during Invoice Creation or not
- *
- * @param string|null $store
- * @param string $scope
- * @return bool
- */
- public function requestByInvoiceCreation($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- $vertexInvoiceEvent = $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_INVOICE_ORDER, $store, $scope);
- return $vertexInvoiceEvent === 'invoice_created';
- }
- /**
- * Determine if we commit to the Tax Log during an Order Status change or not
- *
- * @param string|null $store
- * @param string $scope
- * @return bool
- */
- public function requestByOrderStatus($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- $vertexInvoiceEvent = $this->getConfigValue(self::CONFIG_XML_PATH_VERTEX_INVOICE_ORDER, $store, $scope);
- return $vertexInvoiceEvent === 'order_status';
- }
- /**
- * Determine how customer receive their tax summaries
- *
- * @param string|null $store
- * @param string $scope
- * @return string
- */
- public function getSummarizeTax($store = null, $scope = ScopeInterface::SCOPE_STORE)
- {
- return $this->getConfigValue(self::VERTEX_SUMMARIZE_TAX, $store, $scope);
- }
- }
|