/** * Prepare form before rendering HTML * * @return $this */ protected function _prepareForm() { $model = $this->_coreRegistry->registry('current_promo_quote_rule'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')->setNewChildUrl($this->getUrl('sales_rule/promo_quote/newConditionHtml/form/rule_conditions_fieldset')); $fieldset = $form->addFieldset('conditions_fieldset', ['legend' => __('Apply the rule only if the following conditions are met (leave blank for all products).')])->setRenderer($renderer); $fieldset->addField('conditions', 'text', ['name' => 'conditions', 'label' => __('Conditions'), 'title' => __('Conditions')])->setRule($model)->setRenderer($this->_conditions); $form->setValues($model->getData()); $this->setForm($form); return parent::_prepareForm(); }
/** * @return Form */ protected function _prepareForm() { $model = $this->_coreRegistry->registry('current_promo_catalog_rule'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')->setNewChildUrl($this->getUrl('catalog_rule/promo_catalog/newConditionHtml/form/rule_conditions_fieldset')); $fieldset = $form->addFieldset('conditions_fieldset', ['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])->setRule($model)->setRenderer($this->_conditions); $form->setValues($model->getData()); $this->setForm($form); return parent::_prepareForm(); }
/** * Handles addition of actions tab to supplied form. * * @param \Magento\SalesRule\Model\Rule $model * @param string $fieldsetId * @param string $formName * @return \Magento\Framework\Data\Form * @throws \Magento\Framework\Exception\LocalizedException */ protected function addTabToForm($model, $fieldsetId = 'actions_fieldset', $formName = 'sales_rule_form') { if (!$model) { $id = $this->getRequest()->getParam('id'); $model = $this->ruleFactory->create(); $model->load($id); } $actionsFieldSetId = $model->getActionsFieldSetId($formName); $newChildUrl = $this->getUrl('sales_rule/promo_quote/newActionHtml/form/rule_actions_fieldset_' . $actionsFieldSetId, ['form_namespace' => $formName]); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')->setNewChildUrl($newChildUrl)->setFieldSetId($actionsFieldSetId); $fieldset = $form->addFieldset($fieldsetId, ['legend' => __('Apply the rule only to cart items matching the following conditions ' . '(leave blank for all items).')])->setRenderer($renderer); $fieldset->addField('actions', 'text', ['name' => 'apply_to', 'label' => __('Apply To'), 'title' => __('Apply To'), 'required' => true, 'data-form-part' => $formName])->setRule($model)->setRenderer($this->_ruleActions); $this->_eventManager->dispatch('adminhtml_block_salesrule_actions_prepareform', ['form' => $form]); $form->setValues($model->getData()); $this->setActionFormName($model->getActions(), $formName); if ($model->isReadonly()) { foreach ($fieldset->getElements() as $element) { $element->setReadonly(true, true); } } return $form; }
/** * Prepare form before rendering HTML * * @return $this * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ protected function _prepareForm() { $model = $this->_coreRegistry->registry('current_promo_quote_rule'); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $fieldset = $form->addFieldset('action_fieldset', ['legend' => __('Pricing Structure Rules')]); $fieldset->addField('simple_action', 'select', ['label' => __('Apply'), 'name' => 'simple_action', 'options' => [\Magento\SalesRule\Model\Rule::BY_PERCENT_ACTION => __('Percent of product price discount'), \Magento\SalesRule\Model\Rule::BY_FIXED_ACTION => __('Fixed amount discount'), \Magento\SalesRule\Model\Rule::CART_FIXED_ACTION => __('Fixed amount discount for whole cart'), \Magento\SalesRule\Model\Rule::BUY_X_GET_Y_ACTION => __('Buy X get Y free (discount amount is Y)')]]); $fieldset->addField('discount_amount', 'text', ['name' => 'discount_amount', 'required' => true, 'class' => 'validate-not-negative-number', 'label' => __('Discount Amount')]); $model->setDiscountAmount($model->getDiscountAmount() * 1); $fieldset->addField('discount_qty', 'text', ['name' => 'discount_qty', 'label' => __('Maximum Qty Discount is Applied To')]); $model->setDiscountQty($model->getDiscountQty() * 1); $fieldset->addField('discount_step', 'text', ['name' => 'discount_step', 'label' => __('Discount Qty Step (Buy X)')]); $fieldset->addField('apply_to_shipping', 'select', ['label' => __('Apply to Shipping Amount'), 'title' => __('Apply to Shipping Amount'), 'name' => 'apply_to_shipping', 'values' => $this->_sourceYesno->toOptionArray()]); $fieldset->addField('stop_rules_processing', 'select', ['label' => __('Discard subsequent rules'), 'title' => __('Discard subsequent rules'), 'name' => 'stop_rules_processing', 'options' => ['1' => __('Yes'), '0' => __('No')]]); $renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')->setNewChildUrl($this->getUrl('sales_rule/promo_quote/newActionHtml/form/rule_actions_fieldset')); $fieldset = $form->addFieldset('actions_fieldset', ['legend' => __('Apply the rule only to cart items matching the following conditions ' . '(leave blank for all items).')])->setRenderer($renderer); $fieldset->addField('actions', 'text', ['name' => 'actions', 'label' => __('Apply To'), 'title' => __('Apply To'), 'required' => true])->setRule($model)->setRenderer($this->_ruleActions); $this->_eventManager->dispatch('adminhtml_block_salesrule_actions_prepareform', ['form' => $form]); $form->setValues($model->getData()); if ($model->isReadonly()) { foreach ($fieldset->getElements() as $element) { $element->setReadonly(true, true); } } $this->setForm($form); return parent::_prepareForm(); }
public function render(AbstractElement $element) { $element->addClass('m2epro-fieldset'); $tooltip = $element->getData('tooltip'); if (is_null($tooltip)) { return parent::render($element); } $element->addField('help_block_' . $element->getId(), \Ess\M2ePro\Block\Adminhtml\Magento\Form\AbstractForm::HELP_BLOCK, ['content' => $tooltip, 'tooltiped' => true], '^'); $directionClass = $element->getData('direction_class'); $element->setLegend($element->getLegend() . $this->getTooltipHtml($tooltip, empty($directionClass) ? 'right' : $directionClass)); return parent::render($element); }
/** * @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; }
/** * Handles addition of conditions tab to supplied form. * * @param \Magento\SalesRule\Model\Rule $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 = 'sales_rule_form') { if (!$model) { $id = $this->getRequest()->getParam('id'); $model = $this->getRuleFactory()->create(); $model->load($id); } $conditionsFieldSetId = $model->getConditionsFieldSetId($formName); $newChildUrl = $this->getUrl('sales_rule/promo_quote/newConditionHtml/form/' . $conditionsFieldSetId, ['form_namespace' => $formName]); /** @var \Magento\Framework\Data\Form $form */ $form = $this->_formFactory->create(); $form->setHtmlIdPrefix('rule_'); $renderer = $this->_rendererFieldset->setTemplate('Magento_CatalogRule::promo/fieldset.phtml')->setNewChildUrl($newChildUrl)->setFieldSetId($conditionsFieldSetId); $fieldset = $form->addFieldset($fieldsetId, ['legend' => __('Apply the rule only if the following conditions are met (leave blank for 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; }