Collection.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Variable\Model\ResourceModel\Variable;
  7. /**
  8. * Custom variable collection
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
  13. {
  14. /**
  15. * Store Id
  16. *
  17. * @var int
  18. */
  19. protected $_storeId = 0;
  20. /**
  21. * Define resource model
  22. *
  23. * @return void
  24. */
  25. protected function _construct()
  26. {
  27. parent::_construct();
  28. $this->_init(\Magento\Variable\Model\Variable::class, \Magento\Variable\Model\ResourceModel\Variable::class);
  29. }
  30. /**
  31. * Setter
  32. *
  33. * @param integer $storeId
  34. * @return $this
  35. */
  36. public function setStoreId($storeId)
  37. {
  38. $this->_storeId = $storeId;
  39. return $this;
  40. }
  41. /**
  42. * Getter
  43. *
  44. * @return integer
  45. */
  46. public function getStoreId()
  47. {
  48. return $this->_storeId;
  49. }
  50. /**
  51. * Add store values to result
  52. *
  53. * @return $this
  54. */
  55. public function addValuesToResult()
  56. {
  57. $this->getSelect()->join(
  58. ['value_table' => $this->getTable('variable_value')],
  59. 'value_table.variable_id = main_table.variable_id',
  60. ['value_table.plain_value', 'value_table.html_value']
  61. );
  62. $this->addFieldToFilter('value_table.store_id', ['eq' => $this->getStoreId()]);
  63. return $this;
  64. }
  65. /**
  66. * Retrieve option array
  67. *
  68. * @return array
  69. */
  70. public function toOptionArray()
  71. {
  72. return $this->_toOptionArray('code', 'name');
  73. }
  74. }