CollectionFactory.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\ResourceModel\Order;
  7. /**
  8. * Class CollectionFactory
  9. */
  10. class CollectionFactory implements CollectionFactoryInterface
  11. {
  12. /**
  13. * Object Manager instance
  14. *
  15. * @var \Magento\Framework\ObjectManagerInterface
  16. */
  17. private $objectManager = null;
  18. /**
  19. * Instance name to create
  20. *
  21. * @var string
  22. */
  23. private $instanceName = null;
  24. /**
  25. * Factory constructor
  26. *
  27. * @param \Magento\Framework\ObjectManagerInterface $objectManager
  28. * @param string $instanceName
  29. */
  30. public function __construct(
  31. \Magento\Framework\ObjectManagerInterface $objectManager,
  32. $instanceName = \Magento\Sales\Model\ResourceModel\Order\Collection::class
  33. ) {
  34. $this->objectManager = $objectManager;
  35. $this->instanceName = $instanceName;
  36. }
  37. /**
  38. * {@inheritdoc}
  39. */
  40. public function create($customerId = null)
  41. {
  42. /** @var \Magento\Sales\Model\ResourceModel\Order\Collection $collection */
  43. $collection = $this->objectManager->create($this->instanceName);
  44. if ($customerId) {
  45. $collection->addFieldToFilter('customer_id', $customerId);
  46. }
  47. return $collection;
  48. }
  49. }