I'm creating a Magento module in which there is a section with a form for placing new purchase orders. In this form I would like to add a grid containing products from the database, just like the 'Please Select Products to Add' in the new order section of Magento (see image). Place new order product selection

This product selection grid should be added in my personal form on the same page as the other fieldsets. The product selection should be at the red arrow and the selected products need te be added to the section with the blue arrow (see image below).Add new purchase order form

The question now is where (and partially how) do I create this grid and add it to my form, and add the selected products to a section of the same form?

I recently build a module in which i could generate some pdf quotation also by selecting customers and products. I came across the following documentation which might be usefull to you. This uses magento product selector widget to add lines to you own module. I think its what your looking for. I haven't tested it yet but i am adding it to my module. Maybe it can be your solution. Let me know how it works if youre going to try it.

http://andreitara.com/2012/02/using-magento-product-chooser-widget-in-youre-own-module/

  • Thank you for the swift reply. I'll see if I can implement this in my own module. – AJKwak2017 Jul 22 '15 at 13:25
  • I'm trying to implement this, and so far I've been able to add the button and de files. Yet, when I click the button, it doesn't load any product chooser. It says loading for a while and then returns to normal. Have you come across a solution for this? – AJKwak2017 Jul 22 '15 at 13:42
  • Could you pls help me @ magento.stackexchange.com/q/196004/57334 – zus Oct 5 '17 at 12:29

@AJKwak2017 I also tried the code from AndreiTara and got the same problem as you was, but now it is solved.

The js file need to be update according to this file (https://github.com/andrei-tara/magento-product-selector).

In your admin form you will need to use it this way

public function getProductChooserURL() {
    return 'getProductChooser(\'' . Mage::getUrl(
                    'adminhtml/promo_widget/chooser/attribute/sku/form/rule_conditions_fieldset', array('_secure' => Mage::app()->getStore()->isAdminUrlSecure())
            ) . '?isAjax=true\'); return false;';
}
protected function _prepareForm() {
    $form = new Varien_Data_Form();
    $this->setForm($form);
    $fieldset = $form->addFieldset('productsselector_form', array('legend' => Mage::helper('productsselector')->__('Item information')));
    // Add product SKU text preview
    $fieldset->addField('product_sku', 'text', array(
        'label' => 'Product(s)',
        'name' => 'product_sku',
        'required' => true,
        'class' => 'rule_conditions_fieldset',
        'readonly' => true,
        'onclick' => $this->getProductChooserURL(),           
    ));
    $fieldset->addField('trigger', 'button', array(
        'value' => 'choose ...',
        'name' => 'trigger',
        'style' => 'width:100px;',
        'onclick' => $this->getProductChooserURL(),
    ));
     $fieldset->addFieldset('product_chooser', array('legend' => ('')));
    if (Mage::getSingleton('adminhtml/session')->getProductsselectorData()) {
        $form->setValues(Mage::getSingleton('adminhtml/session')->getProductsselectorData());
        Mage::getSingleton('adminhtml/session')->setProductsselectorData(null);
    } elseif (Mage::registry('productsselector_data')) {
        $form->setValues(Mage::registry('productsselector_data')->getData());
    }
    return parent::_prepareForm();
}

I tried and it works for me now.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.