Wishlist.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Wishlist resource model
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Wishlist\Model\ResourceModel;
  12. /**
  13. * @api
  14. * @since 100.0.2
  15. */
  16. class Wishlist extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  17. {
  18. /**
  19. * Store wishlist items count
  20. *
  21. * @var null|int
  22. */
  23. protected $_itemsCount = null;
  24. /**
  25. * Store customer ID field name
  26. *
  27. * @var string
  28. */
  29. protected $_customerIdFieldName = 'customer_id';
  30. /**
  31. * Set main entity table name and primary key field name
  32. *
  33. * @return void
  34. */
  35. protected function _construct()
  36. {
  37. $this->_init('wishlist', 'wishlist_id');
  38. }
  39. /**
  40. * Prepare wishlist load select query
  41. *
  42. * @param string $field
  43. * @param mixed $value
  44. * @param \Magento\Framework\Model\AbstractModel $object
  45. * @return \Magento\Framework\DB\Select
  46. */
  47. protected function _getLoadSelect($field, $value, $object)
  48. {
  49. $select = parent::_getLoadSelect($field, $value, $object);
  50. if ($field == $this->_customerIdFieldName) {
  51. $select->order('wishlist_id ' . \Magento\Framework\DB\Select::SQL_ASC)->limit(1);
  52. }
  53. return $select;
  54. }
  55. /**
  56. * Getter for customer ID field name
  57. *
  58. * @return string
  59. */
  60. public function getCustomerIdFieldName()
  61. {
  62. return $this->_customerIdFieldName;
  63. }
  64. /**
  65. * Setter for customer ID field name
  66. *
  67. * @param string $fieldName
  68. * @return $this
  69. */
  70. public function setCustomerIdFieldName($fieldName)
  71. {
  72. $this->_customerIdFieldName = $fieldName;
  73. return $this;
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function save(\Magento\Framework\Model\AbstractModel $object)
  79. {
  80. $object->setHasDataChanges(true);
  81. return parent::save($object);
  82. }
  83. }