Combine.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\SalesRule\Model\Rule\Condition;
  7. /**
  8. * @api
  9. * @since 100.0.2
  10. */
  11. class Combine extends \Magento\Rule\Model\Condition\Combine
  12. {
  13. /**
  14. * Core event manager proxy
  15. *
  16. * @var \Magento\Framework\Event\ManagerInterface
  17. */
  18. protected $_eventManager = null;
  19. /**
  20. * @var \Magento\SalesRule\Model\Rule\Condition\Address
  21. */
  22. protected $_conditionAddress;
  23. /**
  24. * @param \Magento\Rule\Model\Condition\Context $context
  25. * @param \Magento\Framework\Event\ManagerInterface $eventManager
  26. * @param \Magento\SalesRule\Model\Rule\Condition\Address $conditionAddress
  27. * @param array $data
  28. */
  29. public function __construct(
  30. \Magento\Rule\Model\Condition\Context $context,
  31. \Magento\Framework\Event\ManagerInterface $eventManager,
  32. \Magento\SalesRule\Model\Rule\Condition\Address $conditionAddress,
  33. array $data = []
  34. ) {
  35. $this->_eventManager = $eventManager;
  36. $this->_conditionAddress = $conditionAddress;
  37. parent::__construct($context, $data);
  38. $this->setType(\Magento\SalesRule\Model\Rule\Condition\Combine::class);
  39. }
  40. /**
  41. * Get new child select options
  42. *
  43. * @return array
  44. */
  45. public function getNewChildSelectOptions()
  46. {
  47. $addressAttributes = $this->_conditionAddress->loadAttributeOptions()->getAttributeOption();
  48. $attributes = [];
  49. foreach ($addressAttributes as $code => $label) {
  50. $attributes[] = [
  51. 'value' => 'Magento\SalesRule\Model\Rule\Condition\Address|' . $code,
  52. 'label' => $label,
  53. ];
  54. }
  55. $conditions = parent::getNewChildSelectOptions();
  56. $conditions = array_merge_recursive(
  57. $conditions,
  58. [
  59. [
  60. 'value' => \Magento\SalesRule\Model\Rule\Condition\Product\Found::class,
  61. 'label' => __('Product attribute combination'),
  62. ],
  63. [
  64. 'value' => \Magento\SalesRule\Model\Rule\Condition\Product\Subselect::class,
  65. 'label' => __('Products subselection')
  66. ],
  67. [
  68. 'value' => \Magento\SalesRule\Model\Rule\Condition\Combine::class,
  69. 'label' => __('Conditions combination')
  70. ],
  71. ['label' => __('Cart Attribute'), 'value' => $attributes]
  72. ]
  73. );
  74. $additional = new \Magento\Framework\DataObject();
  75. $this->_eventManager->dispatch('salesrule_rule_condition_combine', ['additional' => $additional]);
  76. $additionalConditions = $additional->getConditions();
  77. if ($additionalConditions) {
  78. $conditions = array_merge_recursive($conditions, $additionalConditions);
  79. }
  80. return $conditions;
  81. }
  82. }