Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ValueProvider.php
Go to the documentation of this file.
1 <?php
7 
14 
19 {
23  protected $store;
24 
28  protected $groupRepository;
29 
34 
38  protected $objectConverter;
39 
43  protected $salesRuleFactory;
44 
54  public function __construct(
55  Store $store,
59  \Magento\SalesRule\Model\RuleFactory $salesRuleFactory
60  ) {
61  $this->store = $store;
62  $this->groupRepository = $groupRepository;
63  $this->searchCriteriaBuilder = $searchCriteriaBuilder;
64  $this->objectConverter = $objectConverter;
65  $this->salesRuleFactory = $salesRuleFactory;
66  }
67 
75  public function getMetadataValues(\Magento\SalesRule\Model\Rule $rule)
76  {
77  $customerGroups = $this->groupRepository->getList($this->searchCriteriaBuilder->create())->getItems();
78  $applyOptions = [
79  ['label' => __('Percent of product price discount'), 'value' => Rule::BY_PERCENT_ACTION],
80  ['label' => __('Fixed amount discount'), 'value' => Rule::BY_FIXED_ACTION],
81  ['label' => __('Fixed amount discount for whole cart'), 'value' => Rule::CART_FIXED_ACTION],
82  ['label' => __('Buy X get Y free (discount amount is Y)'), 'value' => Rule::BUY_X_GET_Y_ACTION]
83  ];
84 
85  $couponTypesOptions = [];
86  $couponTypes = $this->salesRuleFactory->create()->getCouponTypes();
87  foreach ($couponTypes as $key => $couponType) {
88  $couponTypesOptions[] = [
89  'label' => $couponType,
90  'value' => $key,
91  ];
92  }
93 
94  $labels = $rule->getStoreLabels();
95 
96  return [
97  'rule_information' => [
98  'children' => [
99  'website_ids' => [
100  'arguments' => [
101  'data' => [
102  'config' => [
103  'options' => $this->store->getWebsiteValuesForForm(),
104  ],
105  ],
106  ],
107  ],
108  'is_active' => [
109  'arguments' => [
110  'data' => [
111  'config' => [
112  'options' => [
113  ['label' => __('Active'), 'value' => '1'],
114  ['label' => __('Inactive'), 'value' => '0']
115  ],
116  ],
117  ],
118  ],
119  ],
120  'customer_group_ids' => [
121  'arguments' => [
122  'data' => [
123  'config' => [
124  'options' => $this->objectConverter->toOptionArray($customerGroups, 'id', 'code'),
125  ],
126  ],
127  ],
128  ],
129  'coupon_type' => [
130  'arguments' => [
131  'data' => [
132  'config' => [
133  'options' => $couponTypesOptions,
134  ],
135  ],
136  ],
137  ],
138  'is_rss' => [
139  'arguments' => [
140  'data' => [
141  'config' => [
142  'options' => [
143  ['label' => __('Yes'), 'value' => '1'],
144  ['label' => __('No'), 'value' => '0']
145  ],
146  ],
147  ],
148  ],
149  ],
150  ]
151  ],
152  'actions' => [
153  'children' => [
154  'simple_action' => [
155  'arguments' => [
156  'data' => [
157  'config' => [
158  'options' => $applyOptions
159  ],
160  ]
161  ]
162  ],
163  'discount_amount' => [
164  'arguments' => [
165  'data' => [
166  'config' => [
167  'value' => '0',
168  ],
169  ],
170  ],
171  ],
172  'discount_qty' => [
173  'arguments' => [
174  'data' => [
175  'config' => [
176  'value' => '0',
177  ],
178  ],
179  ],
180  ],
181  'apply_to_shipping' => [
182  'arguments' => [
183  'data' => [
184  'config' => [
185  'options' => [
186  ['label' => __('Yes'), 'value' => '1'],
187  ['label' => __('No'), 'value' => '0']
188  ]
189  ],
190  ],
191  ],
192  ],
193  'stop_rules_processing' => [
194  'arguments' => [
195  'data' => [
196  'config' => [
197  'options' => [
198  ['label' => __('Yes'), 'value' => '1'],
199  ['label' => __('No'), 'value' => '0'],
200  ],
201  ],
202  ]
203  ]
204  ],
205  ]
206  ],
207  'labels' => [
208  'children' => [
209  'store_labels[0]' => [
210  'arguments' => [
211  'data' => [
212  'config' => [
213  'value' => isset($labels[0]) ? $labels[0] : '',
214  ],
215  ]
216  ]
217  ]
218  ]
219  ],
220  ];
221  }
222 }
__()
Definition: __.php:13
getMetadataValues(\Magento\SalesRule\Model\Rule $rule)
__construct(Store $store, GroupRepositoryInterface $groupRepository, SearchCriteriaBuilder $searchCriteriaBuilder, DataObject $objectConverter, \Magento\SalesRule\Model\RuleFactory $salesRuleFactory)