Combine.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Catalog Rule Combine Condition data model
  8. */
  9. namespace Magento\CatalogRule\Model\Rule\Condition;
  10. class Combine extends \Magento\Rule\Model\Condition\Combine
  11. {
  12. /**
  13. * @var \Magento\CatalogRule\Model\Rule\Condition\ProductFactory
  14. */
  15. protected $_productFactory;
  16. /**
  17. * @param \Magento\Rule\Model\Condition\Context $context
  18. * @param \Magento\CatalogRule\Model\Rule\Condition\ProductFactory $conditionFactory
  19. * @param array $data
  20. */
  21. public function __construct(
  22. \Magento\Rule\Model\Condition\Context $context,
  23. \Magento\CatalogRule\Model\Rule\Condition\ProductFactory $conditionFactory,
  24. array $data = []
  25. ) {
  26. $this->_productFactory = $conditionFactory;
  27. parent::__construct($context, $data);
  28. $this->setType(\Magento\CatalogRule\Model\Rule\Condition\Combine::class);
  29. }
  30. /**
  31. * @return array
  32. */
  33. public function getNewChildSelectOptions()
  34. {
  35. $productAttributes = $this->_productFactory->create()->loadAttributeOptions()->getAttributeOption();
  36. $attributes = [];
  37. foreach ($productAttributes as $code => $label) {
  38. $attributes[] = [
  39. 'value' => 'Magento\CatalogRule\Model\Rule\Condition\Product|' . $code,
  40. 'label' => $label,
  41. ];
  42. }
  43. $conditions = parent::getNewChildSelectOptions();
  44. $conditions = array_merge_recursive(
  45. $conditions,
  46. [
  47. [
  48. 'value' => \Magento\CatalogRule\Model\Rule\Condition\Combine::class,
  49. 'label' => __('Conditions Combination'),
  50. ],
  51. ['label' => __('Product Attribute'), 'value' => $attributes]
  52. ]
  53. );
  54. return $conditions;
  55. }
  56. /**
  57. * @param array $productCollection
  58. * @return $this
  59. */
  60. public function collectValidatedAttributes($productCollection)
  61. {
  62. foreach ($this->getConditions() as $condition) {
  63. /** @var Product|Combine $condition */
  64. $condition->collectValidatedAttributes($productCollection);
  65. }
  66. return $this;
  67. }
  68. }