00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Bundle_Model_Mysql4_Option extends Mage_Core_Model_Mysql4_Abstract
00035 {
00036
00037
00038
00039
00040 protected function _construct()
00041 {
00042 $this->_init('bundle/option', 'option_id');
00043 }
00044
00045
00046
00047
00048
00049
00050
00051 protected function _afterSave(Mage_Core_Model_Abstract $object)
00052 {
00053 parent::_afterSave($object);
00054
00055 $condition = $this->_getWriteAdapter()->quoteInto('option_id = ?', $object->getId());
00056 $condition .= ' and (' . $this->_getWriteAdapter()->quoteInto('store_id = ?', $object->getStoreId());
00057 $condition .= ' or store_id = 0)';
00058
00059 $this->_getWriteAdapter()->delete($this->getTable('option_value'), $condition);
00060
00061 $data = new Varien_Object();
00062 $data->setOptionId($object->getId())
00063 ->setStoreId($object->getStoreId())
00064 ->setTitle($object->getTitle());
00065
00066 $this->_getWriteAdapter()->insert($this->getTable('option_value'), $data->getData());
00067
00068
00069
00070
00071
00072 if ($object->getStoreId()) {
00073 $data->setStoreId('0');
00074 $data->setTitle($object->getDefaultTitle());
00075 $this->_getWriteAdapter()->insert($this->getTable('option_value'), $data->getData());
00076 }
00077
00078 return $this;
00079 }
00080
00081
00082
00083
00084
00085
00086
00087 protected function _afterDelete(Mage_Core_Model_Abstract $object)
00088 {
00089 parent::_afterDelete($object);
00090
00091 $condition = $this->_getWriteAdapter()->quoteInto('option_id = ?', $object->getId());
00092 $this->_getWriteAdapter()->delete($this->getTable('option_value'), $condition);
00093
00094 return $this;
00095 }
00096
00097
00098
00099
00100
00101
00102
00103
00104 public function getSearchableData($productId, $storeId)
00105 {
00106 $select = $this->_getReadAdapter()->select()
00107 ->from(array('option' => $this->getMainTable()), null)
00108 ->join(
00109 array('option_title_default' => $this->getTable('bundle/option_value')),
00110 'option_title_default.option_id=option.option_id AND option_title_default.store_id=0',
00111 array())
00112 ->joinLeft(
00113 array('option_title_store' => $this->getTable('bundle/option_value')),
00114 'option_title_store.option_id=option.option_id AND option_title_store.store_id=' . intval($storeId),
00115 array('title' => 'IFNULL(option_title_store.title, option_title_default.title)'))
00116 ->where('option.parent_id=?', $productId);
00117 if (!$searchData = $this->_getReadAdapter()->fetchCol($select)) {
00118 $searchData = array();
00119 }
00120 return $searchData;
00121 }
00122 }