Mage_Weee_Model_Attribute_Backend_Weee_Tax Class Reference

Inheritance diagram for Mage_Weee_Model_Attribute_Backend_Weee_Tax:

Mage_Catalog_Model_Product_Attribute_Backend_Price Mage_Eav_Model_Entity_Attribute_Backend_Abstract Mage_Eav_Model_Entity_Attribute_Backend_Interface

List of all members.

Public Member Functions

 validate ($object)
 afterLoad ($object)
 afterSave ($object)
 afterDelete ($object)
 getTable ()

Protected Member Functions

 _getResource ()


Detailed Description

Definition at line 21 of file Tax.php.


Member Function Documentation

_getResource (  )  [protected]

Retrieve resource model

Returns:
Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Attribute_Backend_Weee

Definition at line 28 of file Tax.php.

00029     {
00030         return Mage::getResourceSingleton('weee/attribute_backend_weee_tax');
00031     }

afterDelete ( object  ) 

Reimplemented from Mage_Eav_Model_Entity_Attribute_Backend_Abstract.

Definition at line 131 of file Tax.php.

00132     {
00133         $this->_getResource()->deleteProductData($object, $this->getAttribute());
00134         return $this;
00135     }

afterLoad ( object  ) 

Assign WEEE taxes to product data

Parameters:
Mage_Catalog_Model_Product $object
Returns:
Mage_Catalog_Model_Product_Attribute_Backend_Weee

Reimplemented from Mage_Eav_Model_Entity_Attribute_Backend_Abstract.

Definition at line 71 of file Tax.php.

00072     {
00073         $data = $this->_getResource()->loadProductData($object, $this->getAttribute());
00074 
00075         foreach ($data as $i=>$row) {
00076             if ($data[$i]['website_id'] == 0) {
00077                 $rate = Mage::app()->getStore()->getBaseCurrency()->getRate(Mage::app()->getBaseCurrencyCode());
00078                 if ($rate) {
00079                     $data[$i]['website_value'] = $data[$i]['value']/$rate;
00080                 } else {
00081                     unset($data[$i]);
00082                 }
00083             } else {
00084                 $data[$i]['website_value'] = $data[$i]['value'];
00085             }
00086 
00087         }
00088         $object->setData($this->getAttribute()->getName(), $data);
00089         return $this;
00090     }

afterSave ( object  ) 

After Save Attribute manipulation

Parameters:
Mage_Catalog_Model_Product $object
Returns:
Mage_Catalog_Model_Product_Attribute_Backend_Price

Orig value is only for existing objects

Reimplemented from Mage_Catalog_Model_Product_Attribute_Backend_Price.

Definition at line 92 of file Tax.php.

00093     {
00094         $orig = $object->getOrigData($this->getAttribute()->getName());
00095         $current = $object->getData($this->getAttribute()->getName());
00096         if ($orig == $current) {
00097             return $this;
00098         }
00099 
00100         $this->_getResource()->deleteProductData($object, $this->getAttribute());
00101         $taxes = $object->getData($this->getAttribute()->getName());
00102 
00103         if (!is_array($taxes)) {
00104             return $this;
00105         }
00106 
00107         foreach ($taxes as $tax) {
00108             if (empty($tax['price']) || empty($tax['country']) || !empty($tax['delete'])) {
00109                 continue;
00110             }
00111 
00112             if (isset($tax['state']) && $tax['state']) {
00113                 $state = $tax['state'];
00114             } else {
00115                 $state = '*';
00116             }
00117 
00118             $data = array();
00119             $data['website_id']   = $tax['website_id'];
00120             $data['country']      = $tax['country'];
00121             $data['state']        = $state;
00122             $data['value']        = $tax['price'];
00123             $data['attribute_id'] = $this->getAttribute()->getId();
00124 
00125             $this->_getResource()->insertProductData($object, $data);
00126         }
00127 
00128         return $this;
00129     }

getTable (  ) 

Get table name for the values of the attribute

Returns:
string

Reimplemented from Mage_Eav_Model_Entity_Attribute_Backend_Abstract.

Definition at line 137 of file Tax.php.

00138     {
00139         return $this->_getResource()->getTable('weee/tax');
00140     }

validate ( object  ) 

Validate data

Parameters:
Mage_Catalog_Model_Product $object
Returns:
this

Reimplemented from Mage_Eav_Model_Entity_Attribute_Backend_Abstract.

Definition at line 39 of file Tax.php.

00040     {
00041         $taxes = $object->getData($this->getAttribute()->getName());
00042         if (empty($taxes)) {
00043             return $this;
00044         }
00045         $dup = array();
00046 
00047         foreach ($taxes as $tax) {
00048             if (!empty($tax['delete'])) {
00049                 continue;
00050             }
00051 
00052             $state = isset($tax['state']) ? $tax['state'] : '*';
00053             $key1 = implode('-', array($tax['website_id'], $tax['country'], $state));
00054 
00055             if (!empty($dup[$key1])) {
00056                 Mage::throwException(
00057                     Mage::helper('catalog')->__('Duplicate website, country and state tax found.')
00058                 );
00059             }
00060             $dup[$key1] = 1;
00061         }
00062         return $this;
00063     }


The documentation for this class was generated from the following file:

Generated on Sat Jul 4 17:24:56 2009 for Magento by  doxygen 1.5.8