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: class Mage_Weee_Model_Attribute_Backend_Weee_Tax extends Mage_Catalog_Model_Product_Attribute_Backend_Price
 28: {
 29:     public static function getBackendModelName()
 30:     {
 31:         return 'weee/attribute_backend_weee_tax';
 32:     }
 33:     /**
 34:      * Retrieve resource model
 35:      *
 36:      * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Weee
 37:      */
 38:     protected function _getResource()
 39:     {
 40:         return Mage::getResourceSingleton(self::getBackendModelName());
 41:     }
 42: 
 43:     /**
 44:      * Validate data
 45:      *
 46:      * @param   Mage_Catalog_Model_Product $object
 47:      * @return  this
 48:      */
 49:     public function validate($object)
 50:     {
 51:         $taxes = $object->getData($this->getAttribute()->getName());
 52:         if (empty($taxes)) {
 53:             return $this;
 54:         }
 55:         $dup = array();
 56: 
 57:         foreach ($taxes as $tax) {
 58:             if (!empty($tax['delete'])) {
 59:                 continue;
 60:             }
 61: 
 62:             $state = isset($tax['state']) ? $tax['state'] : '*';
 63:             $key1 = implode('-', array($tax['website_id'], $tax['country'], $state));
 64: 
 65:             if (!empty($dup[$key1])) {
 66:                 Mage::throwException(
 67:                     Mage::helper('catalog')->__('Duplicate website, country and state tax found.')
 68:                 );
 69:             }
 70:             $dup[$key1] = 1;
 71:         }
 72:         return $this;
 73:     }
 74: 
 75:     /**
 76:      * Assign WEEE taxes to product data
 77:      *
 78:      * @param   Mage_Catalog_Model_Product $object
 79:      * @return  Mage_Catalog_Model_Product_Attribute_Backend_Weee
 80:      */
 81:     public function afterLoad($object)
 82:     {
 83:         $data = $this->_getResource()->loadProductData($object, $this->getAttribute());
 84: 
 85:         foreach ($data as $i=>$row) {
 86:             if ($data[$i]['website_id'] == 0) {
 87:                 $rate = Mage::app()->getStore()->getBaseCurrency()->getRate(Mage::app()->getBaseCurrencyCode());
 88:                 if ($rate) {
 89:                     $data[$i]['website_value'] = $data[$i]['value']/$rate;
 90:                 } else {
 91:                     unset($data[$i]);
 92:                 }
 93:             } else {
 94:                 $data[$i]['website_value'] = $data[$i]['value'];
 95:             }
 96: 
 97:         }
 98:         $object->setData($this->getAttribute()->getName(), $data);
 99:         return $this;
100:     }
101: 
102:     public function afterSave($object)
103:     {
104:         $orig = $object->getOrigData($this->getAttribute()->getName());
105:         $current = $object->getData($this->getAttribute()->getName());
106:         if ($orig == $current) {
107:             return $this;
108:         }
109: 
110:         $this->_getResource()->deleteProductData($object, $this->getAttribute());
111:         $taxes = $object->getData($this->getAttribute()->getName());
112: 
113:         if (!is_array($taxes)) {
114:             return $this;
115:         }
116: 
117:         foreach ($taxes as $tax) {
118:             if (empty($tax['price']) || empty($tax['country']) || !empty($tax['delete'])) {
119:                 continue;
120:             }
121: 
122:             if (isset($tax['state']) && $tax['state']) {
123:                 $state = $tax['state'];
124:             } else {
125:                 $state = '*';
126:             }
127: 
128:             $data = array();
129:             $data['website_id']   = $tax['website_id'];
130:             $data['country']      = $tax['country'];
131:             $data['state']        = $state;
132:             $data['value']        = $tax['price'];
133:             $data['attribute_id'] = $this->getAttribute()->getId();
134: 
135:             $this->_getResource()->insertProductData($object, $data);
136:         }
137: 
138:         return $this;
139:     }
140: 
141:     public function afterDelete($object)
142:     {
143:         $this->_getResource()->deleteProductData($object, $this->getAttribute());
144:         return $this;
145:     }
146: 
147:     public function getTable()
148:     {
149:         return $this->_getResource()->getTable('weee/tax');
150:     }
151: }
152: 
153: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0