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
00035 class Mage_ProductAlert_Model_Mysql4_Price extends Mage_Core_Model_Mysql4_Abstract
00036 {
00037
00038
00039
00040
00041 protected function _construct()
00042 {
00043 $this->_init('productalert/price', 'alert_price_id');
00044 }
00045
00046
00047
00048
00049
00050
00051
00052 protected function _beforeSave(Mage_Core_Model_Abstract $object)
00053 {
00054 if (is_null($object->getId()) && $object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) {
00055 if ($row = $this->_getAlertRow($object)) {
00056 $price = $object->getPrice();
00057 $object->addData($row);
00058 if ($price) {
00059 $object->setPrice($price);
00060 }
00061 $object->setStatus(0);
00062 }
00063 }
00064 if (is_null($object->getAddDate())) {
00065 $object->setAddDate(Mage::getModel('core/date')->gmtDate());
00066 }
00067 return parent::_beforeSave($object);
00068 }
00069
00070
00071
00072
00073
00074
00075
00076 protected function _getAlertRow(Mage_Core_Model_Abstract $object)
00077 {
00078 if ($object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) {
00079 $sql = $this->_getWriteAdapter()->select()
00080 ->from($this->getMainTable())
00081 ->where('customer_id=?', $object->getCustomerId())
00082 ->where('product_id=?', $object->getProductId())
00083 ->where('website_id=?', $object->getWebsiteId());
00084 return $this->_getWriteAdapter()->fetchRow($sql);
00085 }
00086 return false;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095 public function loadByParam(Mage_Core_Model_Abstract $object)
00096 {
00097 $row = $this->_getAlertRow($object);
00098 if ($row) {
00099 $object->setData($row);
00100 }
00101 return $this;
00102 }
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 public function deleteCustomer(Mage_Core_Model_Abstract $object, $customerId, $websiteId = null)
00113 {
00114 $where = array();
00115 $where[] = $this->_getWriteAdapter()->quoteInto('customer_id=?', $customerId);
00116 if ($websiteId) {
00117 $where[] = $this->_getWriteAdapter()->quoteInto('website_id=?', $websiteId);
00118 }
00119 $this->_getWriteAdapter()->delete($this->getMainTable(), $where);
00120 return $this;
00121 }
00122 }