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_Downloadable_Model_Mysql4_Link extends Mage_Core_Model_Mysql4_Abstract
00035 {
00036
00037
00038
00039
00040 protected function _construct()
00041 {
00042 $this->_init('downloadable/link', 'link_id');
00043 }
00044
00045
00046
00047
00048
00049
00050
00051 public function saveItemTitleAndPrice($linkObject)
00052 {
00053 $stmt = $this->_getReadAdapter()->select()
00054 ->from($this->getTable('downloadable/link_title'))
00055 ->where('link_id = ?', $linkObject->getId())
00056 ->where('store_id = ?', $linkObject->getStoreId());
00057 if ($this->_getReadAdapter()->fetchOne($stmt)) {
00058 $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) .
00059 ' AND ' . $this->_getReadAdapter()->quoteInto('store_id = ?', $linkObject->getStoreId());
00060 if ($linkObject->getUseDefaultTitle()) {
00061 $this->_getWriteAdapter()->delete(
00062 $this->getTable('downloadable/link_title'), $where);
00063 } else {
00064 $this->_getWriteAdapter()->update(
00065 $this->getTable('downloadable/link_title'),
00066 array('title' => $linkObject->getTitle()), $where);
00067 }
00068 } else {
00069 if (!$linkObject->getUseDefaultTitle()) {
00070 $this->_getWriteAdapter()->insert(
00071 $this->getTable('downloadable/link_title'),
00072 array(
00073 'link_id' => $linkObject->getId(),
00074 'store_id' => $linkObject->getStoreId(),
00075 'title' => $linkObject->getTitle(),
00076 ));
00077 }
00078 }
00079 $stmt = null;
00080 $stmt = $this->_getReadAdapter()->select()
00081 ->from($this->getTable('downloadable/link_price'))
00082 ->where('link_id = ?', $linkObject->getId())
00083 ->where('website_id = ?', $linkObject->getWebsiteId());
00084 if ($this->_getReadAdapter()->fetchOne($stmt)) {
00085 $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $linkObject->getId()) .
00086 ' AND ' . $this->_getReadAdapter()->quoteInto('website_id = ?', $linkObject->getWebsiteId());
00087 if ($linkObject->getUseDefaultPrice()) {
00088 $this->_getReadAdapter()->delete(
00089 $this->getTable('downloadable/link_price'), $where);
00090 } else {
00091 $this->_getWriteAdapter()->update(
00092 $this->getTable('downloadable/link_price'),
00093 array('price' => $linkObject->getPrice()), $where);
00094 }
00095 } else {
00096 if (!$linkObject->getUseDefaultPrice()) {
00097 $this->_getWriteAdapter()->insert(
00098 $this->getTable('downloadable/link_price'),
00099 array(
00100 'link_id' => $linkObject->getId(),
00101 'website_id' => $linkObject->getWebsiteId(),
00102 'price' => $linkObject->getPrice()
00103 ));
00104 }
00105 }
00106 return $this;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115 public function deleteItems($items)
00116 {
00117 $where = '';
00118 if ($items instanceof Mage_Downloadable_Model_Link) {
00119 $where = $this->_getReadAdapter()->quoteInto('link_id = ?', $items->getId());
00120 }
00121 elseif (is_array($items)) {
00122 $where = $this->_getReadAdapter()->quoteInto('link_id in (?)', $items);
00123 }
00124 else {
00125 $where = $this->_getReadAdapter()->quoteInto('sample_id = ?', $items);
00126 }
00127 if ($where) {
00128 $this->_getWriteAdapter()->delete(
00129 $this->getTable('downloadable/link'), $where);
00130 $this->_getWriteAdapter()->delete(
00131 $this->getTable('downloadable/link_title'), $where);
00132 $this->_getWriteAdapter()->delete(
00133 $this->getTable('downloadable/link_price'), $where);
00134 }
00135 return $this;
00136 }
00137
00138
00139
00140
00141
00142
00143
00144
00145 public function getSearchableData($productId, $storeId)
00146 {
00147 $select = $this->_getReadAdapter()->select()
00148 ->from(array('link' => $this->getMainTable()), null)
00149 ->join(
00150 array('link_title_default' => $this->getTable('downloadable/link_title')),
00151 'link_title_default.link_id=link.link_id AND link_title_default.store_id=0',
00152 array())
00153 ->joinLeft(
00154 array('link_title_store' => $this->getTable('downloadable/link_title')),
00155 'link_title_store.link_id=link.link_id AND link_title_store.store_id=' . intval($storeId),
00156 array('title' => 'IFNULL(link_title_store.title, link_title_default.title)'))
00157 ->where('link.product_id=?', $productId);
00158 if (!$searchData = $this->_getReadAdapter()->fetchCol($select)) {
00159 $searchData = array();
00160 }
00161 return $searchData;
00162 }
00163 }