107 \
Magento\Framework\Data\FormFactory $formFactory,
108 \
Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
110 \
Magento\Framework\Data\Collection\AbstractDb $resourceCollection =
null,
116 $this->_formFactory = $formFactory;
117 $this->_localeDate = $localeDate;
119 \
Magento\Framework\Serialize\Serializer\Json::class
124 $extensionFactory ?: $this->getExtensionFactory(),
142 if ($this->hasDiscountAmount()) {
143 if ((
int)$this->getDiscountAmount() < 0) {
144 throw new \Magento\Framework\Exception\LocalizedException(
__(
'Please choose a valid discount amount.'));
150 $this->setConditionsSerialized($this->serializer->serialize($this->getConditions()->asArray()));
151 $this->_conditions =
null;
156 $this->setActionsSerialized($this->serializer->serialize($this->getActions()->asArray()));
157 $this->_actions =
null;
164 if ($this->hasWebsiteIds()) {
175 if ($this->hasCustomerGroupIds()) {
176 $groupIds = $this->getCustomerGroupIds();
177 if (is_string($groupIds) && !empty($groupIds)) {
178 $this->setCustomerGroupIds(explode(
',', $groupIds));
182 parent::beforeSave();
194 $this->_conditions = $conditions;
205 if (empty($this->_conditions)) {
210 if ($this->hasConditionsSerialized()) {
211 $conditions = $this->getConditionsSerialized();
212 if (!empty($conditions)) {
213 $conditions = $this->serializer->unserialize($conditions);
214 if (is_array($conditions) && !empty($conditions)) {
215 $this->_conditions->loadArray($conditions);
218 $this->unsConditionsSerialized();
232 $this->_actions = $actions;
243 if (!$this->_actions) {
248 if ($this->hasActionsSerialized()) {
249 $actions = $this->getActionsSerialized();
250 if (!empty($actions)) {
251 $actions = $this->serializer->unserialize($actions);
252 if (is_array($actions) && !empty($actions)) {
253 $this->_actions->loadArray($actions);
256 $this->unsActionsSerialized();
270 if (
null === $conditions) {
273 $conditions->setRule($this)->setId(
'1')->setPrefix(
'conditions');
287 if (
null === $actions) {
290 $actions->setRule($this)->setId(
'1')->setPrefix(
'actions');
304 $this->_form = $this->_formFactory->create();
318 if (isset($arr[
'conditions'])) {
319 $this->
getConditions()->setConditions([])->loadArray($arr[
'conditions'][1]);
321 if (isset($arr[
'actions'])) {
322 $this->
getActions()->setActions([])->loadArray($arr[
'actions'][1],
'actions');
341 if (($key ===
'conditions' || $key ===
'actions') && is_array(
$value)) {
346 if (!isset($node[$key][
$path[
$i]])) {
349 $node = & $node[$key][
$path[
$i]];
351 foreach (
$data as $k => $v) {
359 if (in_array($key, [
'from_date',
'to_date'],
true) &&
$value) {
391 $fromDate = $toDate =
null;
393 if ($dataObject->hasFromDate() && $dataObject->hasToDate()) {
394 $fromDate = $dataObject->getFromDate();
395 $toDate = $dataObject->getToDate();
398 if ($fromDate && $toDate) {
399 $fromDate = new \DateTime($fromDate);
400 $toDate = new \DateTime($toDate);
402 if ($fromDate > $toDate) {
403 $result[] =
__(
'End Date must follow Start Date.');
407 if ($dataObject->hasWebsiteIds()) {
410 $result[] =
__(
'Please specify a website.');
413 if ($dataObject->hasCustomerGroupIds()) {
414 $customerGroupIds = $dataObject->getCustomerGroupIds();
415 if (empty($customerGroupIds)) {
416 $result[] =
__(
'Please specify Customer Groups.');
443 $this->_isDeleteable = (bool)
$value;
467 $this->_isReadonly = (bool)
$value;
478 if (!$this->hasWebsiteIds()) {
482 return $this->
_getData(
'website_ids');
489 private function getExtensionFactory()
491 return \Magento\Framework\App\ObjectManager::getInstance()
492 ->get(\
Magento\Framework\Api\ExtensionAttributesFactory::class);
499 private function getCustomAttributeFactory()
501 return \Magento\Framework\App\ObjectManager::getInstance()
502 ->get(\
Magento\Framework\Api\AttributeValueFactory::class);
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Data\FormFactory $formFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[], ExtensionAttributesFactory $extensionFactory=null, AttributeValueFactory $customAttributeFactory=null, \Magento\Framework\Serialize\Serializer\Json $serializer=null)
validateData(\Magento\Framework\DataObject $dataObject)
_resetConditions($conditions=null)
_convertFlatToRecursive(array $data)
setConditions($conditions)
_resetActions($actions=null)
validate(\Magento\Framework\DataObject $object)
setData($key, $value=null)
if(isset($opts->o)) if(! $usingStdout) $l