CollectionModifier.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Data;
  7. use Magento\Framework\Data\Collection\AbstractDb;
  8. /**
  9. * It is pool of collection conditions, which can be add to
  10. * Product Collection.
  11. * This class was created, as extension point, in order to resolve problem with area specific plugins, which
  12. * listens product collection. F.E. this class allows to apply stock filter not only for frontend area
  13. * but for other areas for product collection too
  14. */
  15. class CollectionModifier implements CollectionModifierInterface
  16. {
  17. /**
  18. * @var CollectionModifierInterface[]
  19. */
  20. private $conditions;
  21. /**
  22. * CollectionConditionApplier constructor.
  23. * @param array $conditions
  24. */
  25. public function __construct(
  26. array $conditions
  27. ) {
  28. $this->conditions = $conditions;
  29. }
  30. /**
  31. * Composite method, which apply different product conditions
  32. * you can register new condition in module/di.xml
  33. *
  34. * @param AbstractDb $collection
  35. * @return void
  36. */
  37. public function apply(AbstractDb $collection)
  38. {
  39. foreach ($this->conditions as $condition) {
  40. $condition->apply($collection);
  41. }
  42. }
  43. }