Mage_Weee_Model_Mysql4_Tax Class Reference

Inheritance diagram for Mage_Weee_Model_Mysql4_Tax:

Mage_Core_Model_Mysql4_Abstract Mage_Core_Model_Resource_Abstract

List of all members.

Public Member Functions

 fetchOne ($select)
 fetchCol ($select)
 updateDiscountPercents ()
 getProductDiscountPercent ($product, $website, $group)

Protected Member Functions

 _construct ()


Detailed Description

Definition at line 2 of file Tax.php.


Member Function Documentation

_construct (  )  [protected]

Resource initialization

Reimplemented from Mage_Core_Model_Resource_Abstract.

Definition at line 3 of file Tax.php.

00004     {
00005         $this->_init('weee/tax', 'value_id');
00006     }

fetchCol ( select  ) 

Definition at line 13 of file Tax.php.

00014     {
00015         return $this->_getReadAdapter()->fetchCol($select);
00016     }

fetchOne ( select  ) 

Definition at line 8 of file Tax.php.

00009     {
00010         return $this->_getReadAdapter()->fetchOne($select);
00011     }

getProductDiscountPercent ( product,
website,
group 
)

Definition at line 61 of file Tax.php.

00062     {
00063         $select = $this->_getReadAdapter()->select();
00064         $select->from($this->getTable('weee/discount'), 'value')
00065             ->where('website_id = ?', $website)
00066             ->where('entity_id = ?', $product)
00067             ->where('customer_group_id = ?', $group);
00068 
00069         return $this->_getReadAdapter()->fetchOne($select);
00070     }

updateDiscountPercents (  ) 

Definition at line 18 of file Tax.php.

00019     {
00020         $this->_getWriteAdapter()->delete($this->getTable('weee/discount'));
00021         $now = strtotime(now());
00022 
00023         $select = $this->_getReadAdapter()->select();
00024         $select->from(array('data'=>$this->getTable('catalogrule/rule_product')))
00025             ->where('(from_time <= ? OR from_time = 0)', $now)
00026             ->where('(to_time >= ? OR to_time = 0)', $now)
00027             ->order(array('data.website_id', 'data.customer_group_id', 'data.product_id', 'data.sort_order'));
00028 
00029         $data = $this->_getReadAdapter()->fetchAll($select);
00030         $productData = array();
00031         $stops = array();
00032         foreach ($data as $row) {
00033             $key = "{$row['product_id']}-{$row['website_id']}-{$row['customer_group_id']}";
00034             if (isset($stops[$key]) && $stops[$key]) {
00035                 continue;
00036             }
00037 
00038             if ($row['action_operator'] == 'by_percent') {
00039                 if (isset($productData[$key])) {
00040                     $productData[$key]['value'] += $productData[$key]['value']/100*$row['action_amount'];
00041                 } else {
00042                     $productData[$key] = array(
00043                         'entity_id'         => $row['product_id'],
00044                         'customer_group_id' => $row['customer_group_id'],
00045                         'website_id'        => $row['website_id'],
00046                         'value'             => 100-max(0, min(100, $row['action_amount'])),
00047                     );
00048                 }                
00049             }
00050 
00051             if ($row['action_stop']) {
00052                 $stops[$key] = true;
00053             }
00054         }
00055 
00056         foreach ($productData as $product) {
00057             $this->_getWriteAdapter()->insert($this->getTable('weee/discount'), $product);
00058         }
00059     }


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