PageRenderTime 42ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/Tax/Model/Config.php

https://bitbucket.org/jokusafet/magento2
PHP | 429 lines | 239 code | 57 blank | 133 comment | 35 complexity | f653973aeee294e3324a18782486f12c MD5 | raw file
  1. <?php
  2. /**
  3. * Magento
  4. *
  5. * NOTICE OF LICENSE
  6. *
  7. * This source file is subject to the Open Software License (OSL 3.0)
  8. * that is bundled with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://opensource.org/licenses/osl-3.0.php
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@magentocommerce.com so we can send you a copy immediately.
  14. *
  15. * DISCLAIMER
  16. *
  17. * Do not edit or add to this file if you wish to upgrade Magento to newer
  18. * versions in the future. If you wish to customize Magento for your
  19. * needs please refer to http://www.magentocommerce.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_Tax
  23. * @copyright Copyright (c) 2012 X.commerce, Inc. (http://www.magentocommerce.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Configuration pathes storage
  28. *
  29. * @category Mage
  30. * @package Mage_Tax
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. class Mage_Tax_Model_Config
  34. {
  35. // tax classes
  36. const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';
  37. // tax calculation
  38. const CONFIG_XML_PATH_PRICE_INCLUDES_TAX = 'tax/calculation/price_includes_tax';
  39. const CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX = 'tax/calculation/shipping_includes_tax';
  40. const CONFIG_XML_PATH_BASED_ON = 'tax/calculation/based_on';
  41. const CONFIG_XML_PATH_APPLY_ON = 'tax/calculation/apply_tax_on';
  42. const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT = 'tax/calculation/apply_after_discount';
  43. const CONFIG_XML_PATH_DISCOUNT_TAX = 'tax/calculation/discount_tax';
  44. const XML_PATH_ALGORITHM = 'tax/calculation/algorithm';
  45. // tax defaults
  46. const CONFIG_XML_PATH_DEFAULT_COUNTRY = 'tax/defaults/country';
  47. const CONFIG_XML_PATH_DEFAULT_REGION = 'tax/defaults/region';
  48. const CONFIG_XML_PATH_DEFAULT_POSTCODE = 'tax/defaults/postcode';
  49. /**
  50. * Prices display settings
  51. */
  52. const CONFIG_XML_PATH_PRICE_DISPLAY_TYPE = 'tax/display/type';
  53. const CONFIG_XML_PATH_DISPLAY_SHIPPING = 'tax/display/shipping';
  54. /**
  55. * Shopping cart display settings
  56. */
  57. const XML_PATH_DISPLAY_CART_PRICE = 'tax/cart_display/price';
  58. const XML_PATH_DISPLAY_CART_SUBTOTAL = 'tax/cart_display/subtotal';
  59. const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';
  60. const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';
  61. const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';
  62. const XML_PATH_DISPLAY_CART_FULL_SUMMARY= 'tax/cart_display/full_summary';
  63. const XML_PATH_DISPLAY_CART_ZERO_TAX = 'tax/cart_display/zero_tax';
  64. /**
  65. * Shopping cart display settings
  66. */
  67. const XML_PATH_DISPLAY_SALES_PRICE = 'tax/sales_display/price';
  68. const XML_PATH_DISPLAY_SALES_SUBTOTAL = 'tax/sales_display/subtotal';
  69. const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';
  70. const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';
  71. const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
  72. const XML_PATH_DISPLAY_SALES_FULL_SUMMARY= 'tax/sales_display/full_summary';
  73. const XML_PATH_DISPLAY_SALES_ZERO_TAX = 'tax/sales_display/zero_tax';
  74. const CALCULATION_STRING_SEPARATOR = '|';
  75. const DISPLAY_TYPE_EXCLUDING_TAX = 1;
  76. const DISPLAY_TYPE_INCLUDING_TAX = 2;
  77. const DISPLAY_TYPE_BOTH = 3;
  78. /**
  79. * @var bool|null
  80. */
  81. protected $_priceIncludesTax = null;
  82. /**
  83. * Flag which notify what we need use shipping prices exclude tax for calculations
  84. *
  85. * @var bool
  86. */
  87. protected $_needUseShippingExcludeTax = false;
  88. /**
  89. * @var $_shippingPriceIncludeTax bool
  90. */
  91. protected $_shippingPriceIncludeTax = null;
  92. /**
  93. * Check if prices of product in catalog include tax
  94. *
  95. * @param mixed $store
  96. * @return bool
  97. */
  98. public function priceIncludesTax($store = null)
  99. {
  100. if (null !== $this->_priceIncludesTax) {
  101. return $this->_priceIncludesTax;
  102. }
  103. return (bool)Mage::getStoreConfig(self::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $store);
  104. }
  105. /**
  106. * Override "price includes tax" variable regardless of system configuration of any store
  107. *
  108. * @param bool|null $value
  109. * @return Mage_Tax_Model_Config
  110. */
  111. public function setPriceIncludesTax($value)
  112. {
  113. if (null === $value) {
  114. $this->_priceIncludesTax = null;
  115. } else {
  116. $this->_priceIncludesTax = (bool)$value;
  117. }
  118. return $this;
  119. }
  120. /**
  121. * Check what taxes should be applied after discount
  122. *
  123. * @param mixed $store
  124. * @return bool
  125. */
  126. public function applyTaxAfterDiscount($store=null)
  127. {
  128. return (bool)Mage::getStoreConfig(self::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $store);
  129. }
  130. /**
  131. * Get product price display type
  132. * 1 - Excluding tax
  133. * 2 - Including tax
  134. * 3 - Both
  135. *
  136. * @param mixed $store
  137. * @return int
  138. */
  139. public function getPriceDisplayType($store = null)
  140. {
  141. return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE, $store);
  142. }
  143. /**
  144. * Get configuration setting "Apply Discount On Prices Including Tax" value
  145. *
  146. * @param null|int $store
  147. * @return 0|1
  148. */
  149. public function discountTax($store=null)
  150. {
  151. return ((int)Mage::getStoreConfig(self::CONFIG_XML_PATH_DISCOUNT_TAX, $store) == 1);
  152. }
  153. /**
  154. * Get taxes/discounts calculation sequence.
  155. * This sequence depends on "Apply Customer Tax" and "Apply Discount On Prices" configuration options.
  156. *
  157. * @param null|int|string|Mage_Core_Model_Store $store
  158. * @return string
  159. */
  160. public function getCalculationSequence($store=null)
  161. {
  162. if ($this->applyTaxAfterDiscount($store)) {
  163. if ($this->discountTax($store)) {
  164. $seq = Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL;
  165. } else {
  166. $seq = Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL;
  167. }
  168. } else {
  169. if ($this->discountTax($store)) {
  170. $seq = Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL;
  171. } else {
  172. $seq = Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL;
  173. }
  174. }
  175. return $seq;
  176. }
  177. /**
  178. * Specify flag what we need use shipping price exclude tax
  179. *
  180. * @param bool $flag
  181. * @return Mage_Tax_Model_Config
  182. */
  183. public function setNeedUseShippingExcludeTax($flag)
  184. {
  185. $this->_needUseShippingExcludeTax = $flag;
  186. return $this;
  187. }
  188. /**
  189. * Get flag what we need use shipping price exclude tax
  190. *
  191. * @return bool $flag
  192. */
  193. public function getNeedUseShippingExcludeTax()
  194. {
  195. return $this->_needUseShippingExcludeTax;
  196. }
  197. /**
  198. * Get defined tax calculation agorithm
  199. *
  200. * @param store $store
  201. * @return string
  202. */
  203. public function getAlgorithm($store=null)
  204. {
  205. return Mage::getStoreConfig(self::XML_PATH_ALGORITHM, $store);
  206. }
  207. /**
  208. * Get tax class id specified for shipping tax estimation
  209. *
  210. * @param store $store
  211. * @return int
  212. */
  213. public function getShippingTaxClass($store=null)
  214. {
  215. return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $store);
  216. }
  217. /**
  218. * Get shipping methods prices display type
  219. *
  220. * @param store $store
  221. * @return int
  222. */
  223. public function getShippingPriceDisplayType($store = null)
  224. {
  225. return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_DISPLAY_SHIPPING, $store);
  226. }
  227. /**
  228. * Check if shiping prices include tax
  229. *
  230. * @param store $store
  231. * @return bool
  232. */
  233. public function shippingPriceIncludesTax($store = null)
  234. {
  235. if ($this->_shippingPriceIncludeTax === null) {
  236. $this->_shippingPriceIncludeTax = (bool)Mage::getStoreConfig(
  237. self::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX,
  238. $store
  239. );
  240. }
  241. return $this->_shippingPriceIncludeTax;
  242. }
  243. /**
  244. * Declare shipping prices type
  245. * @param bool $flag
  246. */
  247. public function setShippingPriceIncludeTax($flag)
  248. {
  249. $this->_shippingPriceIncludeTax = $flag;
  250. return $this;
  251. }
  252. public function displayCartPricesInclTax($store = null)
  253. {
  254. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_PRICE, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
  255. }
  256. public function displayCartPricesExclTax($store = null)
  257. {
  258. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_PRICE, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
  259. }
  260. public function displayCartPricesBoth($store = null)
  261. {
  262. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_PRICE, $store) == self::DISPLAY_TYPE_BOTH;
  263. }
  264. public function displayCartSubtotalInclTax($store = null)
  265. {
  266. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SUBTOTAL, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
  267. }
  268. public function displayCartSubtotalExclTax($store = null)
  269. {
  270. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SUBTOTAL, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
  271. }
  272. public function displayCartSubtotalBoth($store = null)
  273. {
  274. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SUBTOTAL, $store) == self::DISPLAY_TYPE_BOTH;
  275. }
  276. public function displayCartShippingInclTax($store = null)
  277. {
  278. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SHIPPING, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
  279. }
  280. public function displayCartShippingExclTax($store = null)
  281. {
  282. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SHIPPING, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
  283. }
  284. public function displayCartShippingBoth($store = null)
  285. {
  286. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SHIPPING, $store) == self::DISPLAY_TYPE_BOTH;
  287. }
  288. public function displayCartDiscountInclTax($store = null)
  289. {
  290. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_DISCOUNT, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
  291. }
  292. public function displayCartDiscountExclTax($store = null)
  293. {
  294. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_DISCOUNT, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
  295. }
  296. public function displayCartDiscountBoth($store = null)
  297. {
  298. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_DISCOUNT, $store) == self::DISPLAY_TYPE_BOTH;
  299. }
  300. public function displayCartTaxWithGrandTotal($store = null)
  301. {
  302. return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_GRANDTOTAL, $store);
  303. }
  304. public function displayCartFullSummary($store = null)
  305. {
  306. return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_FULL_SUMMARY, $store);
  307. }
  308. public function displayCartZeroTax($store = null)
  309. {
  310. return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_ZERO_TAX, $store);
  311. }
  312. public function displaySalesPricesInclTax($store = null)
  313. {
  314. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_PRICE, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
  315. }
  316. public function displaySalesPricesExclTax($store = null)
  317. {
  318. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_PRICE, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
  319. }
  320. public function displaySalesPricesBoth($store = null)
  321. {
  322. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_PRICE, $store) == self::DISPLAY_TYPE_BOTH;
  323. }
  324. public function displaySalesSubtotalInclTax($store = null)
  325. {
  326. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SUBTOTAL, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
  327. }
  328. public function displaySalesSubtotalExclTax($store = null)
  329. {
  330. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SUBTOTAL, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
  331. }
  332. public function displaySalesSubtotalBoth($store = null)
  333. {
  334. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SUBTOTAL, $store) == self::DISPLAY_TYPE_BOTH;
  335. }
  336. public function displaySalesShippingInclTax($store = null)
  337. {
  338. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SHIPPING, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
  339. }
  340. public function displaySalesShippingExclTax($store = null)
  341. {
  342. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SHIPPING, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
  343. }
  344. public function displaySalesShippingBoth($store = null)
  345. {
  346. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SHIPPING, $store) == self::DISPLAY_TYPE_BOTH;
  347. }
  348. public function displaySalesDiscountInclTax($store = null)
  349. {
  350. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_DISCOUNT, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
  351. }
  352. public function displaySalestDiscountExclTax($store = null)
  353. {
  354. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_DISCOUNT, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
  355. }
  356. public function displaySalesDiscountBoth($store = null)
  357. {
  358. return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_DISCOUNT, $store) == self::DISPLAY_TYPE_BOTH;
  359. }
  360. public function displaySalesTaxWithGrandTotal($store = null)
  361. {
  362. return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_GRANDTOTAL, $store);
  363. }
  364. public function displaySalesFullSummary($store = null)
  365. {
  366. return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_FULL_SUMMARY, $store);
  367. }
  368. public function displaySalesZeroTax($store = null)
  369. {
  370. return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_ZERO_TAX, $store);
  371. }
  372. }