BundleDataProvider.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Bundle\Ui\DataProvider\Product;
  7. use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
  8. use Magento\Catalog\Ui\DataProvider\Product\ProductDataProvider;
  9. use Magento\Bundle\Helper\Data;
  10. class BundleDataProvider extends ProductDataProvider
  11. {
  12. /**
  13. * @var Data
  14. */
  15. protected $dataHelper;
  16. /**
  17. * Construct
  18. *
  19. * @param string $name
  20. * @param string $primaryFieldName
  21. * @param string $requestFieldName
  22. * @param CollectionFactory $collectionFactory
  23. * @param Data $dataHelper
  24. * @param \Magento\Ui\DataProvider\AddFieldToCollectionInterface[] $addFieldStrategies
  25. * @param \Magento\Ui\DataProvider\AddFilterToCollectionInterface[] $addFilterStrategies
  26. * @param array $meta
  27. * @param array $data
  28. */
  29. public function __construct(
  30. $name,
  31. $primaryFieldName,
  32. $requestFieldName,
  33. CollectionFactory $collectionFactory,
  34. Data $dataHelper,
  35. array $meta = [],
  36. array $data = [],
  37. array $addFieldStrategies = [],
  38. array $addFilterStrategies = []
  39. ) {
  40. parent::__construct(
  41. $name,
  42. $primaryFieldName,
  43. $requestFieldName,
  44. $collectionFactory,
  45. $addFieldStrategies,
  46. $addFilterStrategies,
  47. $meta,
  48. $data
  49. );
  50. $this->dataHelper = $dataHelper;
  51. }
  52. /**
  53. * Get data
  54. *
  55. * @return array
  56. */
  57. public function getData()
  58. {
  59. if (!$this->getCollection()->isLoaded()) {
  60. $this->getCollection()->addAttributeToFilter(
  61. 'type_id',
  62. $this->dataHelper->getAllowedSelectionTypes()
  63. );
  64. $this->getCollection()->addFilterByRequiredOptions();
  65. $this->getCollection()->addStoreFilter(
  66. \Magento\Store\Model\Store::DEFAULT_STORE_ID
  67. );
  68. $this->getCollection()->load();
  69. }
  70. $items = $this->getCollection()->toArray();
  71. return [
  72. 'totalRecords' => $this->getCollection()->getSize(),
  73. 'items' => array_values($items),
  74. ];
  75. }
  76. }