3

$actionsSelect = $observer->getForm()->getElement('simple_action');

Magento 2.0.x variable $actionsSelect is working

on new ver magento 2.1:
variable $actionsSelect use var_dump() is return Null.

public function execute(\Magento\Framework\Event\Observer $observer)
{
    $actionsSelect = $observer->getForm()->getElement('simple_action');
    if ($actionsSelect){
        $vals = $actionsSelect->getValues();
        $vals[] = [
            'value' => 'freegift_items',
            'label' => __('Free gifts with products'),

        ];
        $vals[] = [
            'value' => 'freegift_cart',
            'label' => __('Free gifts for the whole cart'),
        ];
        $vals[] = [
            'value' => 'freegift_product',
            'label' => __('Free gift with same product'),
        ];
        $vals[] = [
            'value' => 'freegift_spent',
            'label' => __('Free gifts with amount $X spent'),
        ];

        $actionsSelect->setValues($vals);

        $fldSet = $observer->getForm()->getElement('action_fieldset');
        $fldSet->addField('freegift_type', 'select', [
            'name'      => 'freegiftrule[type]',
            'label'     => __('Type'),
            'values'    => [
                0 => __('All SKUs Below'),
                1 => __('One of the SKUs Below')
            ],
        ],
            'discount_amount'
        );
        $fldSet->addField('freegift_sku', 'text', [
            'name'  => 'freegiftrule[sku]',
            'label' => __('SKUs as Free gift'),
            'note'  => __('Comma separated list of the SKUs'),
        ],
            'freegift_type'
        );
    }
}
Chirag Prajapati
  • 135
  • 2
  • 11
Shadow
  • 103
  • 1
  • 1
  • 8

0 Answers0