/** * {@inheritdoc} */ public function save(Data\RuleInterface $rule) { if ($rule->getRuleId()) { $rule = $this->get($rule->getRuleId())->addData($rule->getData()); } try { $this->ruleResource->save($rule); unset($this->rules[$rule->getId()]); } catch (\Exception $e) { throw new CouldNotSaveException(__('Unable to save rule %1', $rule->getRuleId())); } return $rule; }
/** * @param \Magento\CatalogRule\Api\Data\RuleInterface $model * @param string $fieldsetId * @param string $formName * @return \Magento\Framework\Data\Form * @throws \Magento\Framework\Exception\LocalizedException */ protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'catalog_rule_form') { /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $newChildUrl = $this->getUrl('catalog_rule/promo_catalog/newConditionHtml/form/' . $model->getConditionsFieldSetId($formName), ['form_namespace' => $formName]); $renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')->setNewChildUrl($newChildUrl)->setFieldSetId($model->getConditionsFieldSetId($formName)); $fieldset = $form->addFieldset($fieldsetId, ['legend' => __('Conditions (don\'t add conditions if rule is applied to all products)')])->setRenderer($renderer); $fieldset->addField('conditions', 'text', ['name' => 'conditions', 'label' => __('Conditions'), 'title' => __('Conditions'), 'required' => true, 'data-form-part' => $formName])->setRule($model)->setRenderer($this->_conditions); $form->setValues($model->getData()); $this->setConditionFormName($model->getConditions(), $formName); return $form; }