1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27: 28: 29: 30: 31: 32: 33:
34: class Mage_Tax_Model_Config
35: {
36:
37: const CONFIG_XML_PATH_SHIPPING_TAX_CLASS = 'tax/classes/shipping_tax_class';
38:
39:
40: const CONFIG_XML_PATH_PRICE_INCLUDES_TAX = 'tax/calculation/price_includes_tax';
41: const CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX = 'tax/calculation/shipping_includes_tax';
42: const CONFIG_XML_PATH_BASED_ON = 'tax/calculation/based_on';
43: const CONFIG_XML_PATH_APPLY_ON = 'tax/calculation/apply_tax_on';
44: const CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT = 'tax/calculation/apply_after_discount';
45: const CONFIG_XML_PATH_DISCOUNT_TAX = 'tax/calculation/discount_tax';
46: const XML_PATH_ALGORITHM = 'tax/calculation/algorithm';
47:
48:
49: const CONFIG_XML_PATH_DEFAULT_COUNTRY = 'tax/defaults/country';
50: const CONFIG_XML_PATH_DEFAULT_REGION = 'tax/defaults/region';
51: const CONFIG_XML_PATH_DEFAULT_POSTCODE = 'tax/defaults/postcode';
52:
53: 54: 55:
56: const CONFIG_XML_PATH_PRICE_DISPLAY_TYPE = 'tax/display/type';
57: const CONFIG_XML_PATH_DISPLAY_SHIPPING = 'tax/display/shipping';
58:
59: 60: 61:
62: const XML_PATH_DISPLAY_CART_PRICE = 'tax/cart_display/price';
63: const XML_PATH_DISPLAY_CART_SUBTOTAL = 'tax/cart_display/subtotal';
64: const XML_PATH_DISPLAY_CART_SHIPPING = 'tax/cart_display/shipping';
65: const XML_PATH_DISPLAY_CART_DISCOUNT = 'tax/cart_display/discount';
66: const XML_PATH_DISPLAY_CART_GRANDTOTAL = 'tax/cart_display/grandtotal';
67: const XML_PATH_DISPLAY_CART_FULL_SUMMARY= 'tax/cart_display/full_summary';
68: const XML_PATH_DISPLAY_CART_ZERO_TAX = 'tax/cart_display/zero_tax';
69:
70: 71: 72:
73: const XML_PATH_DISPLAY_SALES_PRICE = 'tax/sales_display/price';
74: const XML_PATH_DISPLAY_SALES_SUBTOTAL = 'tax/sales_display/subtotal';
75: const XML_PATH_DISPLAY_SALES_SHIPPING = 'tax/sales_display/shipping';
76: const XML_PATH_DISPLAY_SALES_DISCOUNT = 'tax/sales_display/discount';
77: const XML_PATH_DISPLAY_SALES_GRANDTOTAL = 'tax/sales_display/grandtotal';
78: const XML_PATH_DISPLAY_SALES_FULL_SUMMARY= 'tax/sales_display/full_summary';
79: const XML_PATH_DISPLAY_SALES_ZERO_TAX = 'tax/sales_display/zero_tax';
80:
81: const CALCULATION_STRING_SEPARATOR = '|';
82:
83: const DISPLAY_TYPE_EXCLUDING_TAX = 1;
84: const DISPLAY_TYPE_INCLUDING_TAX = 2;
85: const DISPLAY_TYPE_BOTH = 3;
86:
87: 88: 89:
90: const CONFIG_XML_PATH_SHOW_IN_CATALOG = 'tax/display/show_in_catalog';
91: const CONFIG_XML_PATH_DEFAULT_PRODUCT_TAX_GROUP = 'catalog/product/default_tax_group';
92: const CONFIG_XML_PATH_DISPLAY_TAX_COLUMN = 'tax/display/column_in_summary';
93: const CONFIG_XML_PATH_DISPLAY_FULL_SUMMARY = 'tax/display/full_summary';
94: const CONFIG_XML_PATH_DISPLAY_ZERO_TAX = 'tax/display/zero_tax';
95:
96: 97: 98: 99: 100:
101: protected $_needUsePriceExcludeTax = false;
102:
103: 104: 105: 106: 107:
108: protected $_needUseShippingExcludeTax = false;
109:
110: 111: 112:
113: protected $_shippingPriceIncludeTax = null;
114:
115: 116: 117: 118: 119: 120:
121: public function priceIncludesTax($store=null)
122: {
123: if ($this->_needUsePriceExcludeTax) {
124: return false;
125: }
126: return (bool)Mage::getStoreConfig(self::CONFIG_XML_PATH_PRICE_INCLUDES_TAX, $store);
127: }
128:
129: 130: 131: 132: 133: 134:
135: public function applyTaxAfterDiscount($store=null)
136: {
137: return (bool)Mage::getStoreConfig(self::CONFIG_XML_PATH_APPLY_AFTER_DISCOUNT, $store);
138: }
139:
140: 141: 142: 143: 144: 145: 146: 147: 148:
149: public function getPriceDisplayType($store = null)
150: {
151: return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_PRICE_DISPLAY_TYPE, $store);
152: }
153:
154: 155: 156: 157: 158: 159:
160: public function discountTax($store=null)
161: {
162: return ((int)Mage::getStoreConfig(self::CONFIG_XML_PATH_DISCOUNT_TAX, $store) == 1);
163: }
164:
165: 166: 167: 168: 169: 170: 171:
172: public function getCalculationSequence($store=null)
173: {
174: if ($this->applyTaxAfterDiscount($store)) {
175: if ($this->discountTax($store)) {
176: $seq = Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_INCL;
177: } else {
178: $seq = Mage_Tax_Model_Calculation::CALC_TAX_AFTER_DISCOUNT_ON_EXCL;
179: }
180: } else {
181: if ($this->discountTax($store)) {
182: $seq = Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_INCL;
183: } else {
184: $seq = Mage_Tax_Model_Calculation::CALC_TAX_BEFORE_DISCOUNT_ON_EXCL;
185: }
186: }
187: return $seq;
188: }
189:
190: 191: 192: 193: 194: 195:
196: public function setNeedUsePriceExcludeTax($flag)
197: {
198: $this->_needUsePriceExcludeTax = $flag;
199: return $this;
200: }
201:
202: 203: 204: 205: 206:
207: public function getNeedUsePriceExcludeTax()
208: {
209: return $this->_needUsePriceExcludeTax;
210: }
211:
212: 213: 214: 215: 216: 217:
218: public function setNeedUseShippingExcludeTax($flag)
219: {
220: $this->_needUseShippingExcludeTax = $flag;
221: return $this;
222: }
223:
224: 225: 226: 227: 228:
229: public function getNeedUseShippingExcludeTax()
230: {
231: return $this->_needUseShippingExcludeTax;
232: }
233:
234:
235: 236: 237: 238: 239: 240:
241: public function getAlgorithm($store=null)
242: {
243: return Mage::getStoreConfig(self::XML_PATH_ALGORITHM, $store);
244: }
245:
246: 247: 248: 249: 250: 251:
252: public function getShippingTaxClass($store=null)
253: {
254: return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_SHIPPING_TAX_CLASS, $store);
255: }
256:
257: 258: 259: 260: 261: 262:
263: public function getShippingPriceDisplayType($store = null)
264: {
265: return (int)Mage::getStoreConfig(self::CONFIG_XML_PATH_DISPLAY_SHIPPING, $store);
266: }
267:
268: 269: 270: 271: 272: 273:
274: public function shippingPriceIncludesTax($store = null)
275: {
276: if ($this->_shippingPriceIncludeTax === null) {
277: $this->_shippingPriceIncludeTax = (bool)Mage::getStoreConfig(
278: self::CONFIG_XML_PATH_SHIPPING_INCLUDES_TAX,
279: $store
280: );
281: }
282: return $this->_shippingPriceIncludeTax;
283: }
284:
285: 286: 287: 288:
289: public function setShippingPriceIncludeTax($flag)
290: {
291: $this->_shippingPriceIncludeTax = $flag;
292: return $this;
293: }
294:
295:
296: 297: 298: 299: 300: 301: 302:
303: public function displayFullSummary($store = null)
304: {
305: return $this->displayCartFullSummary($store);
306: }
307:
308: 309: 310: 311: 312: 313: 314:
315: public function displayZeroTax($store = null)
316: {
317: return $this->displayCartZeroTax($store);
318: }
319:
320: 321: 322: 323: 324: 325: 326:
327: public function displayTaxColumn($store = null)
328: {
329: return (bool)Mage::getStoreConfig(self::CONFIG_XML_PATH_DISPLAY_TAX_COLUMN, $store);
330: }
331:
332:
333:
334:
335: public function displayCartPricesInclTax($store = null)
336: {
337: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_PRICE, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
338: }
339:
340: public function displayCartPricesExclTax($store = null)
341: {
342: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_PRICE, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
343: }
344:
345: public function displayCartPricesBoth($store = null)
346: {
347: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_PRICE, $store) == self::DISPLAY_TYPE_BOTH;
348: }
349:
350: public function displayCartSubtotalInclTax($store = null)
351: {
352: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SUBTOTAL, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
353: }
354:
355: public function displayCartSubtotalExclTax($store = null)
356: {
357: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SUBTOTAL, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
358: }
359:
360: public function displayCartSubtotalBoth($store = null)
361: {
362: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SUBTOTAL, $store) == self::DISPLAY_TYPE_BOTH;
363: }
364:
365: public function displayCartShippingInclTax($store = null)
366: {
367: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SHIPPING, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
368: }
369:
370: public function displayCartShippingExclTax($store = null)
371: {
372: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SHIPPING, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
373: }
374:
375: public function displayCartShippingBoth($store = null)
376: {
377: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_SHIPPING, $store) == self::DISPLAY_TYPE_BOTH;
378: }
379:
380: public function displayCartDiscountInclTax($store = null)
381: {
382: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_DISCOUNT, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
383: }
384:
385: public function displayCartDiscountExclTax($store = null)
386: {
387: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_DISCOUNT, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
388: }
389:
390: public function displayCartDiscountBoth($store = null)
391: {
392: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_DISCOUNT, $store) == self::DISPLAY_TYPE_BOTH;
393: }
394:
395: public function displayCartTaxWithGrandTotal($store = null)
396: {
397: return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_GRANDTOTAL, $store);
398: }
399:
400: public function displayCartFullSummary($store = null)
401: {
402: return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_FULL_SUMMARY, $store);
403: }
404:
405: public function displayCartZeroTax($store = null)
406: {
407: return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_CART_ZERO_TAX, $store);
408: }
409:
410:
411: public function displaySalesPricesInclTax($store = null)
412: {
413: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_PRICE, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
414: }
415:
416: public function displaySalesPricesExclTax($store = null)
417: {
418: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_PRICE, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
419: }
420:
421: public function displaySalesPricesBoth($store = null)
422: {
423: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_PRICE, $store) == self::DISPLAY_TYPE_BOTH;
424: }
425:
426: public function displaySalesSubtotalInclTax($store = null)
427: {
428: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SUBTOTAL, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
429: }
430:
431: public function displaySalesSubtotalExclTax($store = null)
432: {
433: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SUBTOTAL, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
434: }
435:
436: public function displaySalesSubtotalBoth($store = null)
437: {
438: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SUBTOTAL, $store) == self::DISPLAY_TYPE_BOTH;
439: }
440:
441: public function displaySalesShippingInclTax($store = null)
442: {
443: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SHIPPING, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
444: }
445:
446: public function displaySalesShippingExclTax($store = null)
447: {
448: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SHIPPING, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
449: }
450:
451: public function displaySalesShippingBoth($store = null)
452: {
453: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_SHIPPING, $store) == self::DISPLAY_TYPE_BOTH;
454: }
455:
456: public function displaySalesDiscountInclTax($store = null)
457: {
458: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_DISCOUNT, $store) == self::DISPLAY_TYPE_INCLUDING_TAX;
459: }
460:
461: public function displaySalestDiscountExclTax($store = null)
462: {
463: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_DISCOUNT, $store) == self::DISPLAY_TYPE_EXCLUDING_TAX;
464: }
465:
466: public function displaySalesDiscountBoth($store = null)
467: {
468: return Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_DISCOUNT, $store) == self::DISPLAY_TYPE_BOTH;
469: }
470:
471: public function displaySalesTaxWithGrandTotal($store = null)
472: {
473: return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_GRANDTOTAL, $store);
474: }
475:
476: public function displaySalesFullSummary($store = null)
477: {
478: return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_FULL_SUMMARY, $store);
479: }
480:
481: public function displaySalesZeroTax($store = null)
482: {
483: return (bool)Mage::getStoreConfig(self::XML_PATH_DISPLAY_SALES_ZERO_TAX, $store);
484: }
485: }
486:
487: