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: /**
29: * Catalog product WEEE tax backend attribute model
30: *
31: * @category Mage
32: * @package Mage_Weee
33: * @author Magento Core Team <core@magentocommerce.com>
34: */
35: class Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax extends Mage_Core_Model_Resource_Db_Abstract
36: {
37: /**
38: * Defines main resource table and table identifier field
39: *
40: */
41: protected function _construct()
42: {
43: $this->_init('weee/tax', 'value_id');
44: }
45:
46: /**
47: * Load product data
48: *
49: * @param Mage_Catalog_Model_Product $product
50: * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
51: * @return array
52: */
53: public function loadProductData($product, $attribute)
54: {
55: $select = $this->_getReadAdapter()->select()
56: ->from($this->getMainTable(), array(
57: 'website_id',
58: 'country',
59: 'state',
60: 'value'
61: ))
62: ->where('entity_id = ?', (int)$product->getId())
63: ->where('attribute_id = ?', (int)$attribute->getId());
64: if ($attribute->isScopeGlobal()) {
65: $select->where('website_id = ?', 0);
66: } else {
67: $storeId = $product->getStoreId();
68: if ($storeId) {
69: $select->where('website_id IN (?)', array(0, Mage::app()->getStore($storeId)->getWebsiteId()));
70: }
71: }
72: return $this->_getReadAdapter()->fetchAll($select);
73: }
74:
75: /**
76: * Delete product data
77: *
78: * @param Mage_Catalog_Model_Product $product
79: * @param Mage_Eav_Model_Entity_Attribute_Abstract $attribute
80: * @return Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax
81: */
82: public function deleteProductData($product, $attribute)
83: {
84: $where = array(
85: 'entity_id = ?' => (int)$product->getId(),
86: 'attribute_id = ?' => (int)$attribute->getId()
87: );
88:
89: $adapter = $this->_getWriteAdapter();
90: if (!$attribute->isScopeGlobal()) {
91: $storeId = $product->getStoreId();
92: if ($storeId) {
93: $where['website_id IN(?)'] = array(0, Mage::app()->getStore($storeId)->getWebsiteId());
94: }
95: }
96: $adapter->delete($this->getMainTable(), $where);
97: return $this;
98: }
99:
100: /**
101: * Insert product data
102: *
103: * @param Mage_Catalog_Model_Product $product
104: * @param array $data
105: * @return Mage_Weee_Model_Resource_Attribute_Backend_Weee_Tax
106: */
107: public function insertProductData($product, $data)
108: {
109: $data['entity_id'] = (int)$product->getId();
110: $data['entity_type_id'] = (int)$product->getEntityTypeId();
111:
112: $this->_getWriteAdapter()->insert($this->getMainTable(), $data);
113: return $this;
114: }
115: }
116:
117: