Customer.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Model\ResourceModel\Rule;
  7. /**
  8. * SalesRule Rule Customer Model Resource
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Customer extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  13. {
  14. /**
  15. * Constructor
  16. *
  17. * @return void
  18. */
  19. protected function _construct()
  20. {
  21. $this->_init('salesrule_customer', 'rule_customer_id');
  22. }
  23. /**
  24. * Get rule usage record for a customer
  25. *
  26. * @param \Magento\SalesRule\Model\Rule\Customer $rule
  27. * @param int $customerId
  28. * @param int $ruleId
  29. * @return $this
  30. */
  31. public function loadByCustomerRule($rule, $customerId, $ruleId)
  32. {
  33. $connection = $this->getConnection();
  34. $select = $connection->select()->from(
  35. $this->getMainTable()
  36. )->where(
  37. 'customer_id = :customer_id'
  38. )->where(
  39. 'rule_id = :rule_id'
  40. );
  41. $data = $connection->fetchRow($select, [':rule_id' => $ruleId, ':customer_id' => $customerId]);
  42. if (false === $data) {
  43. // set empty data, as an existing rule object might be used
  44. $data = [];
  45. }
  46. $rule->setData($data);
  47. return $this;
  48. }
  49. }