Magento 2 : Product Attribute Rule ConditionsMagento Enterprise Catalog Price Rules (rule based on custom...

Why did Democrats in the Senate oppose the Born-Alive Abortion Survivors Protection Act?

How do I prevent a homebrew Grappling Hook feature from trivializing Tomb of Annihilation?

How does one write from a minority culture? A question on cultural references

In Linux what happens if 1000 files in a directory are moved to another location while another 300 files were added to the source directory?

What is the difference between rolling more dice versus fewer dice?

How does Leonard in "Memento" remember reading and writing?

Non-Cancer terminal illness that can affect young (age 10-13) girls?

Square Root Distance from Integers

Why is there a prohibition of gevinat aku"m?

Why did Luke use his left hand to shoot?

How to not let the Identify spell spoil everything?

How to remove from the data the rows of with fixed number of elements?

The effect of fishing on total land area needed to feed an island settlement

Does Skippy chunky peanut butter contain trans fat?

Is there any risk in sharing info about technologies and products we use with a supplier?

After checking in online, how do I know whether I need to go show my passport at airport check-in?

Most demanding German Newspapers

Changing the laptop's CPU. Should I reinstall Linux?

Eww, those bytes are gross

Building an exterior wall within an exterior wall for insulation

How do you voice extended chords?

What language shall they sing in?

Count repetitions of an array

Can 5 Aarakocra PCs summon an Air Elemental?



Magento 2 : Product Attribute Rule Conditions


Magento Enterprise Catalog Price Rules (rule based on custom attribute)Use group price in shopping cart price rule conditionsCart Rule Configurable productMagento Shopping Cart Rule diiferent discount in a single ruleMagento 2.1 :- Add Conditions Rule in custom formAdd customer attribute to shopping cart rule conditionMake Magento 2 Product Attribute Read-OnlyMagento 2.1.4 Cannot exclude Category from Promotional Cart Price Rule ConditionsMagento 2.2.5: Adding cart-attribute for cart-rules / conditions tabMagento2: How to properly set actions & conditions when creating sales-rule programmatically?













1















I have added following field in my UI Component Form in a custom module to get the Product Attributes ** in conditions, but the options given in the drop-down are **Cart Attributes whereas I need Product Attributes!



Here is my code,



<fieldset name="conditions">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Products with Conditions</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">127</item>
</item>
</argument>
<container name="conditions_apply_to" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
<htmlContent name="html_content">
<argument name="block" xsi:type="object">MagentoSalesRuleBlockAdminhtmlPromoQuoteEditTabConditions</argument>
</htmlContent>
</container>
</fieldset>


How can I change this?










share|improve this question

























  • do you want to display your product custom attribute to product attribute select list?

    – Nikunj Vadariya
    Jun 7 '18 at 6:13











  • Please review this 2 file: MagentoRuleModelConditionCombine and MagentoRuleModelConditionAbstractCondition.

    – Dhaduk Mitesh
    Jun 7 '18 at 6:22











  • @NikunjVadariya I only need the default Product attributes provided by magento , no customization.

    – Verdu
    Jun 7 '18 at 6:27











  • Which default attribute you want to add inside product attribute condition?

    – Nikunj Vadariya
    Jun 7 '18 at 6:41











  • @NikunjVadariya go to content->widgets and in widgets options you can see CONDITIONS at the bottom . I need same product attributes

    – Verdu
    Jun 7 '18 at 6:45
















1















I have added following field in my UI Component Form in a custom module to get the Product Attributes ** in conditions, but the options given in the drop-down are **Cart Attributes whereas I need Product Attributes!



Here is my code,



<fieldset name="conditions">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Products with Conditions</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">127</item>
</item>
</argument>
<container name="conditions_apply_to" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
<htmlContent name="html_content">
<argument name="block" xsi:type="object">MagentoSalesRuleBlockAdminhtmlPromoQuoteEditTabConditions</argument>
</htmlContent>
</container>
</fieldset>


How can I change this?










share|improve this question

























  • do you want to display your product custom attribute to product attribute select list?

    – Nikunj Vadariya
    Jun 7 '18 at 6:13











  • Please review this 2 file: MagentoRuleModelConditionCombine and MagentoRuleModelConditionAbstractCondition.

    – Dhaduk Mitesh
    Jun 7 '18 at 6:22











  • @NikunjVadariya I only need the default Product attributes provided by magento , no customization.

    – Verdu
    Jun 7 '18 at 6:27











  • Which default attribute you want to add inside product attribute condition?

    – Nikunj Vadariya
    Jun 7 '18 at 6:41











  • @NikunjVadariya go to content->widgets and in widgets options you can see CONDITIONS at the bottom . I need same product attributes

    – Verdu
    Jun 7 '18 at 6:45














1












1








1








I have added following field in my UI Component Form in a custom module to get the Product Attributes ** in conditions, but the options given in the drop-down are **Cart Attributes whereas I need Product Attributes!



Here is my code,



<fieldset name="conditions">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Products with Conditions</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">127</item>
</item>
</argument>
<container name="conditions_apply_to" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
<htmlContent name="html_content">
<argument name="block" xsi:type="object">MagentoSalesRuleBlockAdminhtmlPromoQuoteEditTabConditions</argument>
</htmlContent>
</container>
</fieldset>


How can I change this?










share|improve this question
















I have added following field in my UI Component Form in a custom module to get the Product Attributes ** in conditions, but the options given in the drop-down are **Cart Attributes whereas I need Product Attributes!



Here is my code,



<fieldset name="conditions">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="label" xsi:type="string" translate="true">Products with Conditions</item>
<item name="collapsible" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">127</item>
</item>
</argument>
<container name="conditions_apply_to" >
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="sortOrder" xsi:type="number">10</item>
</item>
</argument>
<htmlContent name="html_content">
<argument name="block" xsi:type="object">MagentoSalesRuleBlockAdminhtmlPromoQuoteEditTabConditions</argument>
</htmlContent>
</container>
</fieldset>


How can I change this?







magento2 product product-attribute shopping-cart-price-rules






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 7 '18 at 8:20









Uday Akoliya

425




425










asked Jun 7 '18 at 6:02









VerduVerdu

1,066523




1,066523













  • do you want to display your product custom attribute to product attribute select list?

    – Nikunj Vadariya
    Jun 7 '18 at 6:13











  • Please review this 2 file: MagentoRuleModelConditionCombine and MagentoRuleModelConditionAbstractCondition.

    – Dhaduk Mitesh
    Jun 7 '18 at 6:22











  • @NikunjVadariya I only need the default Product attributes provided by magento , no customization.

    – Verdu
    Jun 7 '18 at 6:27











  • Which default attribute you want to add inside product attribute condition?

    – Nikunj Vadariya
    Jun 7 '18 at 6:41











  • @NikunjVadariya go to content->widgets and in widgets options you can see CONDITIONS at the bottom . I need same product attributes

    – Verdu
    Jun 7 '18 at 6:45



















  • do you want to display your product custom attribute to product attribute select list?

    – Nikunj Vadariya
    Jun 7 '18 at 6:13











  • Please review this 2 file: MagentoRuleModelConditionCombine and MagentoRuleModelConditionAbstractCondition.

    – Dhaduk Mitesh
    Jun 7 '18 at 6:22











  • @NikunjVadariya I only need the default Product attributes provided by magento , no customization.

    – Verdu
    Jun 7 '18 at 6:27











  • Which default attribute you want to add inside product attribute condition?

    – Nikunj Vadariya
    Jun 7 '18 at 6:41











  • @NikunjVadariya go to content->widgets and in widgets options you can see CONDITIONS at the bottom . I need same product attributes

    – Verdu
    Jun 7 '18 at 6:45

















do you want to display your product custom attribute to product attribute select list?

– Nikunj Vadariya
Jun 7 '18 at 6:13





do you want to display your product custom attribute to product attribute select list?

– Nikunj Vadariya
Jun 7 '18 at 6:13













Please review this 2 file: MagentoRuleModelConditionCombine and MagentoRuleModelConditionAbstractCondition.

– Dhaduk Mitesh
Jun 7 '18 at 6:22





Please review this 2 file: MagentoRuleModelConditionCombine and MagentoRuleModelConditionAbstractCondition.

– Dhaduk Mitesh
Jun 7 '18 at 6:22













@NikunjVadariya I only need the default Product attributes provided by magento , no customization.

– Verdu
Jun 7 '18 at 6:27





@NikunjVadariya I only need the default Product attributes provided by magento , no customization.

– Verdu
Jun 7 '18 at 6:27













Which default attribute you want to add inside product attribute condition?

– Nikunj Vadariya
Jun 7 '18 at 6:41





Which default attribute you want to add inside product attribute condition?

– Nikunj Vadariya
Jun 7 '18 at 6:41













@NikunjVadariya go to content->widgets and in widgets options you can see CONDITIONS at the bottom . I need same product attributes

– Verdu
Jun 7 '18 at 6:45





@NikunjVadariya go to content->widgets and in widgets options you can see CONDITIONS at the bottom . I need same product attributes

– Verdu
Jun 7 '18 at 6:45










2 Answers
2






active

oldest

votes


















1














You need replace follow lines in file app/code/Vendor/Rules/Model/Rule.php



Find this:



MagentoSalesRuleModelRuleConditionCombineFactory $condCombineFactory,
MagentoSalesRuleModelRuleConditionProductCombineFactory $condProdCombineF,


Replace with:



MagentoCatalogWidgetModelRuleConditionCombineFactory $condCombineFactory,
MagentoCatalogWidgetModelRuleConditionProductFactory $condProdCombineF,





share|improve this answer
























  • what is the path for /Rules/Model/Rule.php in Magento Core Files?

    – Verdu
    Jun 7 '18 at 10:58











  • You override rule.php or not.

    – Dhaduk Mitesh
    Jun 7 '18 at 11:42











  • No, not at the moment.

    – Verdu
    Jun 7 '18 at 11:49











  • You want to change in core file first and check it. If working then override it.

    – Dhaduk Mitesh
    Jun 7 '18 at 11:54











  • Yes! so where is the actual file in core to this one app/code/Vendor/Rules/Model/Rule.php ?

    – Verdu
    Jun 8 '18 at 5:57



















0














You are using SalesRule, you need to use CatalogRule.



You can extends from MagentoBackendBlockWidgetFormGeneric. You need your conditions class with a constructor and method like this:



 /**
* Constructor
*
* @param MagentoBackendBlockTemplateContext $context
* @param MagentoFrameworkRegistry $registry
* @param MagentoFrameworkDataFormFactory $formFactory
* @param MagentoRuleBlockConditions $conditions
* @param MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset
* @param array $data
* @param MagentoSalesRuleModelRuleFactory|null $ruleFactory
*/
public function __construct(
MagentoBackendBlockTemplateContext $context,
MagentoFrameworkRegistry $registry,
MagentoFrameworkDataFormFactory $formFactory,
MagentoRuleBlockConditions $conditions,
MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset,
array $data = [],
MagentoCatalogRuleModelRuleFactory $ruleFactory = null
) {
$this->_rendererFieldset = $rendererFieldset;
$this->_conditions = $conditions;
$this->ruleFactory = $ruleFactory ?: ObjectManager::getInstance()
->get(MagentoCatalogRuleModelRuleFactory::class);
parent::__construct($context, $registry, $formFactory, $data);
}

/**
* Handles addition of conditions tab to supplied form.
*
* @param MagentoSalesRuleModelRule $model
* @param string $fieldsetId
* @param string $formName
* @return MagentoFrameworkDataForm
* @throws MagentoFrameworkExceptionLocalizedException
*/
protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'sales_rule_form')
{
if (!$model) {
$id = $this->getRequest()->getParam('id');
$model = $this->ruleFactory->create();
$model->load($id);
}
$conditionsFieldSetId = $model->getConditionsFieldSetId($formName);
$newChildUrl = $this->getUrl(
'catalog_rule/promo_catalog/newConditionHtml/form/' . $conditionsFieldSetId,
['form_namespace' => $formName]
);

/** @var MagentoFrameworkDataForm $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;
}




share























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f228947%2fmagento-2-product-attribute-rule-conditions%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You need replace follow lines in file app/code/Vendor/Rules/Model/Rule.php



    Find this:



    MagentoSalesRuleModelRuleConditionCombineFactory $condCombineFactory,
    MagentoSalesRuleModelRuleConditionProductCombineFactory $condProdCombineF,


    Replace with:



    MagentoCatalogWidgetModelRuleConditionCombineFactory $condCombineFactory,
    MagentoCatalogWidgetModelRuleConditionProductFactory $condProdCombineF,





    share|improve this answer
























    • what is the path for /Rules/Model/Rule.php in Magento Core Files?

      – Verdu
      Jun 7 '18 at 10:58











    • You override rule.php or not.

      – Dhaduk Mitesh
      Jun 7 '18 at 11:42











    • No, not at the moment.

      – Verdu
      Jun 7 '18 at 11:49











    • You want to change in core file first and check it. If working then override it.

      – Dhaduk Mitesh
      Jun 7 '18 at 11:54











    • Yes! so where is the actual file in core to this one app/code/Vendor/Rules/Model/Rule.php ?

      – Verdu
      Jun 8 '18 at 5:57
















    1














    You need replace follow lines in file app/code/Vendor/Rules/Model/Rule.php



    Find this:



    MagentoSalesRuleModelRuleConditionCombineFactory $condCombineFactory,
    MagentoSalesRuleModelRuleConditionProductCombineFactory $condProdCombineF,


    Replace with:



    MagentoCatalogWidgetModelRuleConditionCombineFactory $condCombineFactory,
    MagentoCatalogWidgetModelRuleConditionProductFactory $condProdCombineF,





    share|improve this answer
























    • what is the path for /Rules/Model/Rule.php in Magento Core Files?

      – Verdu
      Jun 7 '18 at 10:58











    • You override rule.php or not.

      – Dhaduk Mitesh
      Jun 7 '18 at 11:42











    • No, not at the moment.

      – Verdu
      Jun 7 '18 at 11:49











    • You want to change in core file first and check it. If working then override it.

      – Dhaduk Mitesh
      Jun 7 '18 at 11:54











    • Yes! so where is the actual file in core to this one app/code/Vendor/Rules/Model/Rule.php ?

      – Verdu
      Jun 8 '18 at 5:57














    1












    1








    1







    You need replace follow lines in file app/code/Vendor/Rules/Model/Rule.php



    Find this:



    MagentoSalesRuleModelRuleConditionCombineFactory $condCombineFactory,
    MagentoSalesRuleModelRuleConditionProductCombineFactory $condProdCombineF,


    Replace with:



    MagentoCatalogWidgetModelRuleConditionCombineFactory $condCombineFactory,
    MagentoCatalogWidgetModelRuleConditionProductFactory $condProdCombineF,





    share|improve this answer













    You need replace follow lines in file app/code/Vendor/Rules/Model/Rule.php



    Find this:



    MagentoSalesRuleModelRuleConditionCombineFactory $condCombineFactory,
    MagentoSalesRuleModelRuleConditionProductCombineFactory $condProdCombineF,


    Replace with:



    MagentoCatalogWidgetModelRuleConditionCombineFactory $condCombineFactory,
    MagentoCatalogWidgetModelRuleConditionProductFactory $condProdCombineF,






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 7 '18 at 7:00









    Dhaduk MiteshDhaduk Mitesh

    662218




    662218













    • what is the path for /Rules/Model/Rule.php in Magento Core Files?

      – Verdu
      Jun 7 '18 at 10:58











    • You override rule.php or not.

      – Dhaduk Mitesh
      Jun 7 '18 at 11:42











    • No, not at the moment.

      – Verdu
      Jun 7 '18 at 11:49











    • You want to change in core file first and check it. If working then override it.

      – Dhaduk Mitesh
      Jun 7 '18 at 11:54











    • Yes! so where is the actual file in core to this one app/code/Vendor/Rules/Model/Rule.php ?

      – Verdu
      Jun 8 '18 at 5:57



















    • what is the path for /Rules/Model/Rule.php in Magento Core Files?

      – Verdu
      Jun 7 '18 at 10:58











    • You override rule.php or not.

      – Dhaduk Mitesh
      Jun 7 '18 at 11:42











    • No, not at the moment.

      – Verdu
      Jun 7 '18 at 11:49











    • You want to change in core file first and check it. If working then override it.

      – Dhaduk Mitesh
      Jun 7 '18 at 11:54











    • Yes! so where is the actual file in core to this one app/code/Vendor/Rules/Model/Rule.php ?

      – Verdu
      Jun 8 '18 at 5:57

















    what is the path for /Rules/Model/Rule.php in Magento Core Files?

    – Verdu
    Jun 7 '18 at 10:58





    what is the path for /Rules/Model/Rule.php in Magento Core Files?

    – Verdu
    Jun 7 '18 at 10:58













    You override rule.php or not.

    – Dhaduk Mitesh
    Jun 7 '18 at 11:42





    You override rule.php or not.

    – Dhaduk Mitesh
    Jun 7 '18 at 11:42













    No, not at the moment.

    – Verdu
    Jun 7 '18 at 11:49





    No, not at the moment.

    – Verdu
    Jun 7 '18 at 11:49













    You want to change in core file first and check it. If working then override it.

    – Dhaduk Mitesh
    Jun 7 '18 at 11:54





    You want to change in core file first and check it. If working then override it.

    – Dhaduk Mitesh
    Jun 7 '18 at 11:54













    Yes! so where is the actual file in core to this one app/code/Vendor/Rules/Model/Rule.php ?

    – Verdu
    Jun 8 '18 at 5:57





    Yes! so where is the actual file in core to this one app/code/Vendor/Rules/Model/Rule.php ?

    – Verdu
    Jun 8 '18 at 5:57













    0














    You are using SalesRule, you need to use CatalogRule.



    You can extends from MagentoBackendBlockWidgetFormGeneric. You need your conditions class with a constructor and method like this:



     /**
    * Constructor
    *
    * @param MagentoBackendBlockTemplateContext $context
    * @param MagentoFrameworkRegistry $registry
    * @param MagentoFrameworkDataFormFactory $formFactory
    * @param MagentoRuleBlockConditions $conditions
    * @param MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset
    * @param array $data
    * @param MagentoSalesRuleModelRuleFactory|null $ruleFactory
    */
    public function __construct(
    MagentoBackendBlockTemplateContext $context,
    MagentoFrameworkRegistry $registry,
    MagentoFrameworkDataFormFactory $formFactory,
    MagentoRuleBlockConditions $conditions,
    MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset,
    array $data = [],
    MagentoCatalogRuleModelRuleFactory $ruleFactory = null
    ) {
    $this->_rendererFieldset = $rendererFieldset;
    $this->_conditions = $conditions;
    $this->ruleFactory = $ruleFactory ?: ObjectManager::getInstance()
    ->get(MagentoCatalogRuleModelRuleFactory::class);
    parent::__construct($context, $registry, $formFactory, $data);
    }

    /**
    * Handles addition of conditions tab to supplied form.
    *
    * @param MagentoSalesRuleModelRule $model
    * @param string $fieldsetId
    * @param string $formName
    * @return MagentoFrameworkDataForm
    * @throws MagentoFrameworkExceptionLocalizedException
    */
    protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'sales_rule_form')
    {
    if (!$model) {
    $id = $this->getRequest()->getParam('id');
    $model = $this->ruleFactory->create();
    $model->load($id);
    }
    $conditionsFieldSetId = $model->getConditionsFieldSetId($formName);
    $newChildUrl = $this->getUrl(
    'catalog_rule/promo_catalog/newConditionHtml/form/' . $conditionsFieldSetId,
    ['form_namespace' => $formName]
    );

    /** @var MagentoFrameworkDataForm $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;
    }




    share




























      0














      You are using SalesRule, you need to use CatalogRule.



      You can extends from MagentoBackendBlockWidgetFormGeneric. You need your conditions class with a constructor and method like this:



       /**
      * Constructor
      *
      * @param MagentoBackendBlockTemplateContext $context
      * @param MagentoFrameworkRegistry $registry
      * @param MagentoFrameworkDataFormFactory $formFactory
      * @param MagentoRuleBlockConditions $conditions
      * @param MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset
      * @param array $data
      * @param MagentoSalesRuleModelRuleFactory|null $ruleFactory
      */
      public function __construct(
      MagentoBackendBlockTemplateContext $context,
      MagentoFrameworkRegistry $registry,
      MagentoFrameworkDataFormFactory $formFactory,
      MagentoRuleBlockConditions $conditions,
      MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset,
      array $data = [],
      MagentoCatalogRuleModelRuleFactory $ruleFactory = null
      ) {
      $this->_rendererFieldset = $rendererFieldset;
      $this->_conditions = $conditions;
      $this->ruleFactory = $ruleFactory ?: ObjectManager::getInstance()
      ->get(MagentoCatalogRuleModelRuleFactory::class);
      parent::__construct($context, $registry, $formFactory, $data);
      }

      /**
      * Handles addition of conditions tab to supplied form.
      *
      * @param MagentoSalesRuleModelRule $model
      * @param string $fieldsetId
      * @param string $formName
      * @return MagentoFrameworkDataForm
      * @throws MagentoFrameworkExceptionLocalizedException
      */
      protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'sales_rule_form')
      {
      if (!$model) {
      $id = $this->getRequest()->getParam('id');
      $model = $this->ruleFactory->create();
      $model->load($id);
      }
      $conditionsFieldSetId = $model->getConditionsFieldSetId($formName);
      $newChildUrl = $this->getUrl(
      'catalog_rule/promo_catalog/newConditionHtml/form/' . $conditionsFieldSetId,
      ['form_namespace' => $formName]
      );

      /** @var MagentoFrameworkDataForm $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;
      }




      share


























        0












        0








        0







        You are using SalesRule, you need to use CatalogRule.



        You can extends from MagentoBackendBlockWidgetFormGeneric. You need your conditions class with a constructor and method like this:



         /**
        * Constructor
        *
        * @param MagentoBackendBlockTemplateContext $context
        * @param MagentoFrameworkRegistry $registry
        * @param MagentoFrameworkDataFormFactory $formFactory
        * @param MagentoRuleBlockConditions $conditions
        * @param MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset
        * @param array $data
        * @param MagentoSalesRuleModelRuleFactory|null $ruleFactory
        */
        public function __construct(
        MagentoBackendBlockTemplateContext $context,
        MagentoFrameworkRegistry $registry,
        MagentoFrameworkDataFormFactory $formFactory,
        MagentoRuleBlockConditions $conditions,
        MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset,
        array $data = [],
        MagentoCatalogRuleModelRuleFactory $ruleFactory = null
        ) {
        $this->_rendererFieldset = $rendererFieldset;
        $this->_conditions = $conditions;
        $this->ruleFactory = $ruleFactory ?: ObjectManager::getInstance()
        ->get(MagentoCatalogRuleModelRuleFactory::class);
        parent::__construct($context, $registry, $formFactory, $data);
        }

        /**
        * Handles addition of conditions tab to supplied form.
        *
        * @param MagentoSalesRuleModelRule $model
        * @param string $fieldsetId
        * @param string $formName
        * @return MagentoFrameworkDataForm
        * @throws MagentoFrameworkExceptionLocalizedException
        */
        protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'sales_rule_form')
        {
        if (!$model) {
        $id = $this->getRequest()->getParam('id');
        $model = $this->ruleFactory->create();
        $model->load($id);
        }
        $conditionsFieldSetId = $model->getConditionsFieldSetId($formName);
        $newChildUrl = $this->getUrl(
        'catalog_rule/promo_catalog/newConditionHtml/form/' . $conditionsFieldSetId,
        ['form_namespace' => $formName]
        );

        /** @var MagentoFrameworkDataForm $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;
        }




        share













        You are using SalesRule, you need to use CatalogRule.



        You can extends from MagentoBackendBlockWidgetFormGeneric. You need your conditions class with a constructor and method like this:



         /**
        * Constructor
        *
        * @param MagentoBackendBlockTemplateContext $context
        * @param MagentoFrameworkRegistry $registry
        * @param MagentoFrameworkDataFormFactory $formFactory
        * @param MagentoRuleBlockConditions $conditions
        * @param MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset
        * @param array $data
        * @param MagentoSalesRuleModelRuleFactory|null $ruleFactory
        */
        public function __construct(
        MagentoBackendBlockTemplateContext $context,
        MagentoFrameworkRegistry $registry,
        MagentoFrameworkDataFormFactory $formFactory,
        MagentoRuleBlockConditions $conditions,
        MagentoBackendBlockWidgetFormRendererFieldset $rendererFieldset,
        array $data = [],
        MagentoCatalogRuleModelRuleFactory $ruleFactory = null
        ) {
        $this->_rendererFieldset = $rendererFieldset;
        $this->_conditions = $conditions;
        $this->ruleFactory = $ruleFactory ?: ObjectManager::getInstance()
        ->get(MagentoCatalogRuleModelRuleFactory::class);
        parent::__construct($context, $registry, $formFactory, $data);
        }

        /**
        * Handles addition of conditions tab to supplied form.
        *
        * @param MagentoSalesRuleModelRule $model
        * @param string $fieldsetId
        * @param string $formName
        * @return MagentoFrameworkDataForm
        * @throws MagentoFrameworkExceptionLocalizedException
        */
        protected function addTabToForm($model, $fieldsetId = 'conditions_fieldset', $formName = 'sales_rule_form')
        {
        if (!$model) {
        $id = $this->getRequest()->getParam('id');
        $model = $this->ruleFactory->create();
        $model->load($id);
        }
        $conditionsFieldSetId = $model->getConditionsFieldSetId($formName);
        $newChildUrl = $this->getUrl(
        'catalog_rule/promo_catalog/newConditionHtml/form/' . $conditionsFieldSetId,
        ['form_namespace' => $formName]
        );

        /** @var MagentoFrameworkDataForm $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;
        }





        share











        share


        share










        answered 3 mins ago









        Miguel Ángel Garrido GutiérrezMiguel Ángel Garrido Gutiérrez

        112




        112






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f228947%2fmagento-2-product-attribute-rule-conditions%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

            How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

            變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...