PageRenderTime 49ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/app/code/core/Mage/ProductAlert/Model/Resource/Abstract.php

https://github.com/speedupmate/Magento-CE-Mirror
PHP | 96 lines | 41 code | 4 blank | 51 comment | 5 complexity | 609156c197bfb0cd505152c2541a54ab MD5 | raw file
  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@magento.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.magento.com for more information.
  20. *
  21. * @category Mage
  22. * @package Mage_ProductAlert
  23. * @copyright Copyright (c) 2006-2020 Magento, Inc. (http://www.magento.com)
  24. * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
  25. */
  26. /**
  27. * Product alert for back in abstract resource model
  28. *
  29. * @category Mage
  30. * @package Mage_ProductAlert
  31. * @author Magento Core Team <core@magentocommerce.com>
  32. */
  33. abstract class Mage_ProductAlert_Model_Resource_Abstract extends Mage_Core_Model_Resource_Db_Abstract
  34. {
  35. /**
  36. * Retrieve alert row by object parameters
  37. *
  38. * @param Mage_Core_Model_Abstract $object
  39. * @return array|bool
  40. */
  41. protected function _getAlertRow(Mage_Core_Model_Abstract $object)
  42. {
  43. $adapter = $this->_getReadAdapter();
  44. if ($object->getCustomerId() && $object->getProductId() && $object->getWebsiteId()) {
  45. $select = $adapter->select()
  46. ->from($this->getMainTable())
  47. ->where('customer_id = :customer_id')
  48. ->where('product_id = :product_id')
  49. ->where('website_id = :website_id');
  50. $bind = array(
  51. ':customer_id' => $object->getCustomerId(),
  52. ':product_id' => $object->getProductId(),
  53. ':website_id' => $object->getWebsiteId()
  54. );
  55. return $adapter->fetchRow($select, $bind);
  56. }
  57. return false;
  58. }
  59. /**
  60. * Load object data by parameters
  61. *
  62. * @param Mage_Core_Model_Abstract $object
  63. * @return Mage_ProductAlert_Model_Resource_Abstract
  64. */
  65. public function loadByParam(Mage_Core_Model_Abstract $object)
  66. {
  67. $row = $this->_getAlertRow($object);
  68. if ($row) {
  69. $object->setData($row);
  70. }
  71. return $this;
  72. }
  73. /**
  74. * Delete all customer alerts on website
  75. *
  76. * @param Mage_Core_Model_Abstract $object
  77. * @param int $customerId
  78. * @param int $websiteId
  79. * @return Mage_ProductAlert_Model_Resource_Abstract
  80. */
  81. public function deleteCustomer(Mage_Core_Model_Abstract $object, $customerId, $websiteId=null)
  82. {
  83. $adapter = $this->_getWriteAdapter();
  84. $where = array();
  85. $where[] = $adapter->quoteInto('customer_id=?', $customerId);
  86. if ($websiteId) {
  87. $where[] = $adapter->quoteInto('website_id=?', $websiteId);
  88. }
  89. $adapter->delete($this->getMainTable(), $where);
  90. return $this;
  91. }
  92. }