Question

My case: I have the mass action for a selected products to make some math operations with a prices. At first step I have the "Change prices" action and the selecting on it gives me the mass actions with needed operation (+,-, * and so on).

$operations = Mage::getSingleton('op/operations')->getOptionArray();

    array_unshift($operations, [
        'label' => '',
        'value' => ''
        ]);

    $this->getMassactionBlock()->addItem('Change price', array(
    'label' => Mage::helper('op')->__('Change price'),
    'url' => $this->getUrl('*/*/massPrices', array(
        '_current' => true
    )),
    'additional' => array(
        'visibility' => array(
            'name' => 'operations',
            'type' => 'select',
            'class' => 'required-entry',
            'label' => Mage::helper('op')->__('Change price'),
            'values' => $operations
        )
    )
));

But in order to make some math operations I need to get argument for user's input. To do this I try to repeat getMassactionBlockfrom previous step with new label and type=text. yes, it really gives me text input, but I'd like to get only after the second mass action (with math operations) will be selected.

Thx for help.

Was it helpful?

Solution

I'd suggest redirecting to a landing page with a form for price adjustment input before you head to the massPricesAction.

What I mean is, you can go

$this->getMassactionBlock()->addItem('Change price', array(
'label' => Mage::helper('op')->__('Change price'),
'url' => $this->getUrl('*/*/inputMassPriceAdjustment', array(
    '_current' => true
)),

in your massaction, then you set up a custom page in your controller, like

public function inputMassPriceAdjustmentAction() {

if (!$this->_validateFormKey()) {
        $this->_redirect('*/*/');
        return;
    }

if($this->getRequest()->isPost()) {
    $params = $this->getRequest()->getPost();
    if(isset($params['product_ids']) && !empty($params['product_ids'])) {
        $this->loadLayout();
        $this->getLayout()->getBlock('price_adjustment_form')->setProductIds($params['product_ids']);
        $this->renderLayout();
    }
}
else {
    $this->_redirect('*/*/');
        return;
}
}

finally you can set up your form, collect the price adjustment input (and maybe other data you might want to change) and post the whole shebang to your original massPricesAction(). You might want to put the product_ids into hidden fields temporarily.

Hope this helps ;)

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top