1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25:
26:
27:
28: 29: 30: 31: 32: 33: 34:
35: class Mage_Bundle_Model_Resource_Option extends Mage_Core_Model_Resource_Db_Abstract
36: {
37: 38: 39: 40:
41: protected function _construct()
42: {
43: $this->_init('bundle/option', 'option_id');
44: }
45:
46: 47: 48: 49: 50: 51:
52: protected function _afterSave(Mage_Core_Model_Abstract $object)
53: {
54: parent::_afterSave($object);
55:
56: $condition = array(
57: 'option_id = ?' => $object->getId(),
58: 'store_id = ? OR store_id = 0' => $object->getStoreId()
59: );
60:
61: $write = $this->_getWriteAdapter();
62: $write->delete($this->getTable('bundle/option_value'), $condition);
63:
64: $data = new Varien_Object();
65: $data->setOptionId($object->getId())
66: ->setStoreId($object->getStoreId())
67: ->setTitle($object->getTitle());
68:
69: $write->insert($this->getTable('bundle/option_value'), $data->getData());
70:
71: 72: 73:
74:
75: if ($object->getStoreId()) {
76: $data->setStoreId(0);
77: $data->setTitle($object->getDefaultTitle());
78: $write->insert($this->getTable('bundle/option_value'), $data->getData());
79: }
80:
81: return $this;
82: }
83:
84: 85: 86: 87: 88: 89:
90: protected function _afterDelete(Mage_Core_Model_Abstract $object)
91: {
92: parent::_afterDelete($object);
93:
94: $this->_getWriteAdapter()->delete(
95: $this->getTable('bundle/option_value'),
96: array('option_id = ?' => $object->getId())
97: );
98:
99: return $this;
100: }
101:
102: 103: 104: 105: 106: 107: 108:
109: public function getSearchableData($productId, $storeId)
110: {
111: $adapter = $this->_getReadAdapter();
112:
113: $title = $adapter->getCheckSql('option_title_store.title IS NOT NULL',
114: 'option_title_store.title',
115: 'option_title_default.title'
116: );
117: $bind = array(
118: 'store_id' => $storeId,
119: 'product_id' => $productId
120: );
121: $select = $adapter->select()
122: ->from(array('opt' => $this->getMainTable()), array())
123: ->join(
124: array('option_title_default' => $this->getTable('bundle/option_value')),
125: 'option_title_default.option_id = opt.option_id AND option_title_default.store_id = 0',
126: array()
127: )
128: ->joinLeft(
129: array('option_title_store' => $this->getTable('bundle/option_value')),
130: 'option_title_store.option_id = opt.option_id AND option_title_store.store_id = :store_id',
131: array('title' => $title)
132: )
133: ->where('opt.parent_id=:product_id');
134: if (!$searchData = $adapter->fetchCol($select, $bind)) {
135: $searchData = array();
136: }
137: return $searchData;
138: }
139: }
140: