Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage_Weee_Block_Element_Weee_Tax
  • Mage_Weee_Helper_Data
  • Mage_Weee_Model_Attribute_Backend_Weee_Tax
  • Mage_Weee_Model_Config_Source_Display
  • Mage_Weee_Model_Mysql4_Attribute_Backend_Weee_Tax
  • Mage_Weee_Model_Mysql4_Setup
  • Mage_Weee_Model_Mysql4_Tax
  • Mage_Weee_Model_Observer
  • Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax
  • Mage_Weee_Model_Resource_Setup
  • Mage_Weee_Model_Resource_Tax
  • Mage_Weee_Model_Tax
  • Mage_Weee_Model_Total_Creditmemo_Weee
  • Mage_Weee_Model_Total_Invoice_Weee
  • Mage_Weee_Model_Total_Quote_Nominal_Weee
  • Mage_Weee_Model_Total_Quote_Weee
  • Overview
  • Package
  • Class
  • Tree
  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_Weee
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: /**
 28:  * WEEE data helper
 29:  *
 30:  * @category Mage
 31:  * @package  Mage_Weee
 32:  * @author   Magento Core Team <core@magentocommerce.com>
 33:  */
 34: class Mage_Weee_Helper_Data extends Mage_Core_Helper_Abstract
 35: {
 36: 
 37:     const XML_PATH_FPT_ENABLED       = 'tax/weee/enable';
 38: 
 39:     protected $_storeDisplayConfig   = array();
 40: 
 41:     /**
 42:      * Get weee amount display type on product view page
 43:      *
 44:      * @param   mixed $store
 45:      * @return  int
 46:      */
 47:     public function getPriceDisplayType($store = null)
 48:     {
 49:         return Mage::getStoreConfig('tax/weee/display', $store);
 50:     }
 51: 
 52:     /**
 53:      * Get weee amount display type on product list page
 54:      *
 55:      * @param   mixed $store
 56:      * @return  int
 57:      */
 58:     public function getListPriceDisplayType($store = null)
 59:     {
 60:         return Mage::getStoreConfig('tax/weee/display_list', $store);
 61:     }
 62: 
 63:     /**
 64:      * Get weee amount display type in sales modules
 65:      *
 66:      * @param   mixed $store
 67:      * @return  int
 68:      */
 69:     public function getSalesPriceDisplayType($store = null)
 70:     {
 71:         return Mage::getStoreConfig('tax/weee/display_sales', $store);
 72:     }
 73: 
 74:     /**
 75:      * Get weee amount display type in email templates
 76:      *
 77:      * @param   mixed $store
 78:      * @return  int
 79:      */
 80:     public function getEmailPriceDisplayType($store = null)
 81:     {
 82:         return Mage::getStoreConfig('tax/weee/display_email', $store);
 83:     }
 84: 
 85:     /**
 86:      * Check if weee tax amount should be discounted
 87:      *
 88:      * @param   mixed $store
 89:      * @return  bool
 90:      */
 91:     public function isDiscounted($store = null)
 92:     {
 93:         return Mage::getStoreConfigFlag('tax/weee/discount', $store);
 94:     }
 95: 
 96:     /**
 97:      * Check if weee tax amount should be taxable
 98:      *
 99:      * @param   mixed $store
100:      * @return  bool
101:      */
102:     public function isTaxable($store = null)
103:     {
104:         return Mage::getStoreConfigFlag('tax/weee/apply_vat', $store);
105:     }
106: 
107:     /**
108:      * Check if weee tax amount should be included to subtotal
109:      *
110:      * @param   mixed $store
111:      * @return  bool
112:      */
113:     public function includeInSubtotal($store = null)
114:     {
115:         return Mage::getStoreConfigFlag('tax/weee/include_in_subtotal', $store);
116:     }
117: 
118:     /**
119:      * Get weee tax amount for product based on shipping and billing addresses, website and tax settings
120:      *
121:      * @param   Mage_Catalog_Model_Product $product
122:      * @param   null|Mage_Customer_Model_Address_Abstract $shipping
123:      * @param   null|Mage_Customer_Model_Address_Abstract $billing
124:      * @param   mixed $website
125:      * @param   bool $calculateTaxes
126:      * @return  float
127:      */
128:     public function getAmount($product, $shipping = null, $billing = null, $website = null, $calculateTaxes = false)
129:     {
130:         if ($this->isEnabled()) {
131:             return Mage::getSingleton('weee/tax')->
132:                     getWeeeAmount($product, $shipping, $billing, $website, $calculateTaxes);
133:         }
134:         return 0;
135:     }
136: 
137:     /**
138:      * Returns diaplay type for price accordingly to current zone
139:      *
140:      * @param Mage_Catalog_Model_Product $product
141:      * @param array|null                 $compareTo
142:      * @param string                     $zone
143:      * @param Mage_Core_Model_Store      $store
144:      * @return bool|int
145:      */
146:     public function typeOfDisplay($product, $compareTo = null, $zone = null, $store = null)
147:     {
148:         if (!$this->isEnabled($store)) {
149:             return false;
150:         }
151:         switch ($zone) {
152:             case 'product_view':
153:                 $type = $this->getPriceDisplayType($store);
154:                 break;
155:             case 'product_list':
156:                 $type = $this->getListPriceDisplayType($store);
157:                 break;
158:             case 'sales':
159:                 $type = $this->getSalesPriceDisplayType($store);
160:                 break;
161:             case 'email':
162:                 $type = $this->getEmailPriceDisplayType($store);
163:                 break;
164:             default:
165:                 if (Mage::registry('current_product')) {
166:                     $type = $this->getPriceDisplayType($store);
167:                 } else {
168:                     $type = $this->getListPriceDisplayType($store);
169:                 }
170:                 break;
171:         }
172: 
173:         if (is_null($compareTo)) {
174:             return $type;
175:         } else {
176:             if (is_array($compareTo)) {
177:                 return in_array($type, $compareTo);
178:             } else {
179:                 return $type == $compareTo;
180:             }
181:         }
182:     }
183: 
184:     /**
185:      * Proxy for Mage_Weee_Model_Tax::getProductWeeeAttributes()
186:      *
187:      * @param Mage_Catalog_Model_Product $product
188:      * @param null|false|Varien_Object   $shipping
189:      * @param null|false|Varien_Object   $billing
190:      * @param Mage_Core_Model_Website    $website
191:      * @param bool                       $calculateTaxes
192:      * @return array
193:      */
194:     public function getProductWeeeAttributes($product, $shipping = null, $billing = null,
195:         $website = null, $calculateTaxes = false)
196:     {
197:         return Mage::getSingleton('weee/tax')
198:                 ->getProductWeeeAttributes($product, $shipping, $billing, $website, $calculateTaxes);
199:     }
200: 
201:     /**
202:      * Returns applied weee taxes
203:      *
204:      * @param Mage_Sales_Model_Quote_Item_Abstract $item
205:      * @return array
206:      */
207:     public function getApplied($item)
208:     {
209:         if ($item instanceof Mage_Sales_Model_Quote_Item_Abstract) {
210:             if ($item->getHasChildren() && $item->isChildrenCalculated()) {
211:                 $result = array();
212:                 foreach ($item->getChildren() as $child) {
213:                     $childData = $this->getApplied($child);
214:                     if (is_array($childData)) {
215:                         $result = array_merge($result, $childData);
216:                     }
217:                 }
218:                 return $result;
219:             }
220:         }
221: 
222:         /**
223:          * if order item data is old enough then weee_tax_applied cab be
224:          * not valid serialized data
225:          */
226:         $data = $item->getWeeeTaxApplied();
227:         if (empty($data)){
228:             return array();
229:         }
230:         return unserialize($item->getWeeeTaxApplied());
231:     }
232: 
233:     /**
234:      * Sets applied weee taxes
235:      *
236:      * @param Mage_Sales_Model_Quote_Item_Abstract $item
237:      * @param array                                $value
238:      * @return Mage_Weee_Helper_Data
239:      */
240:     public function setApplied($item, $value)
241:     {
242:         $item->setWeeeTaxApplied(serialize($value));
243:         return $this;
244:     }
245: 
246:     /**
247:      * Returns array of weee attributes allowed for display
248:      *
249:      * @param Mage_Catalog_Model_Product $product
250:      * @return array
251:      */
252:     public function getProductWeeeAttributesForDisplay($product)
253:     {
254:         if ($this->isEnabled()) {
255:             return $this->getProductWeeeAttributes($product, null, null, null, $this->typeOfDisplay($product, 1));
256:         }
257:         return array();
258:     }
259: 
260:     /**
261:      * Get Product Weee attributes for price renderer
262:      *
263:      * @param Mage_Catalog_Model_Product $product
264:      * @param null|false|Varien_Object $shipping Shipping Address
265:      * @param null|false|Varien_Object $billing Billing Address
266:      * @param null|Mage_Core_Model_Website $website
267:      * @param mixed $calculateTaxes
268:      * @return array
269:      */
270:     public function getProductWeeeAttributesForRenderer($product, $shipping = null, $billing = null,
271:         $website = null, $calculateTaxes = false)
272:     {
273:         if ($this->isEnabled()) {
274:             return $this->getProductWeeeAttributes(
275:                 $product,
276:                 $shipping,
277:                 $billing,
278:                 $website,
279:                 $calculateTaxes ? $calculateTaxes : $this->typeOfDisplay($product, 1)
280:             );
281:         }
282:         return array();
283:     }
284: 
285:     /**
286:      * Returns amount to display
287:      *
288:      * @param Mage_Catalog_Model_Product $product
289:      * @return int
290:      */
291:     public function getAmountForDisplay($product)
292:     {
293:         if ($this->isEnabled()) {
294:             return Mage::getModel('weee/tax')
295:                     ->getWeeeAmount($product, null, null, null, $this->typeOfDisplay($product, 1));
296:         }
297:         return 0;
298:     }
299: 
300:     /**
301:      * Returns original amount
302:      *
303:      * @param Mage_Catalog_Model_Product $product
304:      * @return int
305:      */
306:     public function getOriginalAmount($product)
307:     {
308:         if ($this->isEnabled()) {
309:             return Mage::getModel('weee/tax')->getWeeeAmount($product, null, null, null, false, true);
310:         }
311:         return 0;
312:     }
313: 
314:     /**
315:      * Adds HTML containers and formats tier prices accordingly to the currency used
316:      *
317:      * @param Mage_Catalog_Model_Product $product
318:      * @param array                      $tierPrices
319:      * @return Mage_Weee_Helper_Data
320:      */
321:     public function processTierPrices($product, &$tierPrices)
322:     {
323:         $weeeAmount = $this->getAmountForDisplay($product);
324:         $store = Mage::app()->getStore();
325:         foreach ($tierPrices as $index => &$tier) {
326:             $html = $store->formatPrice($store->convertPrice(
327:                 Mage::helper('tax')->getPrice($product, $tier['website_price'], true)+$weeeAmount), false);
328:             $tier['formated_price_incl_weee'] = '<span class="price tier-' . $index . '-incl-tax">' . $html . '</span>';
329:             $html = $store->formatPrice($store->convertPrice(
330:                 Mage::helper('tax')->getPrice($product, $tier['website_price'])+$weeeAmount), false);
331:             $tier['formated_price_incl_weee_only'] = '<span class="price tier-' . $index . '">' . $html . '</span>';
332:             $tier['formated_weee'] = $store->formatPrice($store->convertPrice($weeeAmount));
333:         }
334:         return $this;
335:     }
336: 
337:     /**
338:      * Check if fixed taxes are used in system
339:      *
340:      * @param Mage_Core_Model_Store $store
341:      * @return bool
342:      */
343:     public function isEnabled($store = null)
344:     {
345:         return Mage::getStoreConfig(self::XML_PATH_FPT_ENABLED, $store);
346:     }
347: 
348:     /**
349:      * Returns all summed WEEE taxes with all local taxes applied
350:      *
351:      * @throws Mage_Exception
352:      * @param array $attributes Array of Varien_Object, result from getProductWeeeAttributes()
353:      * @return float
354:      */
355:     public function getAmountInclTaxes($attributes)
356:     {
357:         if (is_array($attributes)) {
358:             $amount = 0;
359:             foreach ($attributes as $attribute) {
360:                 /* @var $attribute Varien_Object */
361:                 $amount += $attribute->getAmount() + $attribute->getTaxAmount();
362:             }
363:         } else {
364:             throw new Mage_Exception('$attributes must be an array');
365:         }
366: 
367:         return (float)$amount;
368:     }
369: }
370: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0