cancel
Showing results for 
Search instead for 
Did you mean: 

Allow easy selection of products/categories/customers/... in custom backend forms

0 Kudos

Allow easy selection of products/categories/customers/... in custom backend forms

Feature request from bgalileo, posted on GitHub Jan 14, 2015

In Magento 1, there is no easy way to add a user-friendly product, category or customer selection widget to a custom form. There are ways to add the product, category, cms page and cms block chooser widgets to your form, but the process is neither well-documented nor obvious, and a customer chooser widget simply doesn't exist.

Since you often need to link information with specific customers, products or categories in custom modules, it should be easy to add a form element which allows the user to select one or multiple product/category/user IDs via the corresponding grids, which are then submitted together with the form.

10 Comments
apiuser
New Member
Status changed to: Investigating
 
apiuser
New Member

Comment from bgalileo, posted on GitHub Jan 14, 2015

Ideally, there would be an easy way to load any grid in a lightbox, let the user select one or multiple entries and then save the selected IDs in a hidden form element, but I don't know whether that's feasible.

apiuser
New Member

Comment from verklov, posted on GitHub Jan 22, 2015

@bgalileo, could you please provide some specific use case for us? We can hardly understand what are your steps and what you expect to achieve. Thank you!

apiuser
New Member

Comment from bgalileo, posted on GitHub Jan 25, 2015

Scenario: I'm writing a module which allows defining customer-specific prices for products. So I needed to create a backend form where backend users select a customer, select a product and enter a price. To achieve that, I had to:

  • Create two subclasses of Mage_Adminhtml_Block_Widget_Grid which load the appropriate collections and set a rowClickCallback on those grids.
  • Create to more actions in my controller for those two grids.
  • Create a phtml file and add some JS to it which handles the row clicks.

If you want to enable backend users to change the selected product/customer later, even more custom JS is required.

I think that such a common task shouldn't require that much manual work. Instead, there should be an easier way to add a product/customer/… selector to a Mage_Adminhtml_Block_Widget_Form, like the following module provides: https://github.com/Jarlssen/Jarlssen_ChooserWidget

apiuser
New Member

Comment from verklov, posted on GitHub Jan 26, 2015

Got your point @bgalileo. Thank you for the clarification and additional information provided! We created the ticket for this improvement in the product backlog and will process it according to the priorities.

Internal ticket: MAGETWO-33049

apiuser
New Member

Comment from quynhvv, posted on GitHub Feb 17, 2016

Hi guys, How we can make a chooser button in a custom form in back-end to choose the categories?

apiuser
New Member

Comment from nobuttsalex, posted on GitHub Apr 27, 2016

Yes I am wanting to do the same, need to create a widget where multiple categories can be selected. I want to include the same category selector that is on the create product form. It must be possible to do it with the functionality that is already in M2 but cannot find how to use it. m2categoriesselector

apiuser
New Member

Comment from GianniPDF, posted on GitHub Jun 10, 2016

@nobuttsalex I managed to de that with $categories = $fieldsetData->addField( 'categories', 'Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Category', [ 'name' => 'categories', 'label' => __('Categories'), 'required' => TRUE, ] );

and adding < css src="Magento_Catalog::catalog/category-selector.css"/ > to your layout.

but having troubles trying to add the SKU Chooser like the one in Cart price rules

team23
Senior Member

Any updates on this one?

I'm trying to do a "Select Product..." like on the Catalog Product Link Widget.

iowebgr
Contributor

Did you guys manage to load the product chooser in a form? I'm trying to do the same but having javascript error

 

$productChooser = $fieldset->addField(
'product_id',
'label',
[
'label' => __('Product'),
'title' => __("Product"),
'required' => false,
'class' => 'widget-option',
'visible' => '1',
'name' => 'product_id',
'value' => $banner ? 'product/' . $banner->getProductId() : ''
]
);
/** @var Chooser $chooser */
$chooser = $subject->getLayout()->createBlock(
Chooser::class
);
$configChooser = [
'button' => [
'open' => __('Select Products'),
'type' => Chooser::class,
]
];

$chooser->setConfig($configChooser);
$chooser->setFieldsetId('base_fieldset');
$chooser->prepareElementHtml($productChooser);

 

And on the backend form it shows

 

https://prnt.sc/YKsv-v8tDqjf 

 

But unfortunately when I click on the Select Products button I get an error

 

Uncaught TypeError: can't access property "value", this.getElement() is null
    getElementValue https://sandbox.example.com/static/adminhtml/Magento/backend/en_US/mage/adminhtml/wysiwyg/widget.js:683
    choose https://sandbox.example.com/static/adminhtml/Magento/backend/en_US/mage/adminhtml/wysiwyg/widget.js:620
    onclick https://sandbox.example.com/admin_nology/bannerslideradmin/banner/edit/banner_id/593/:1
2 widget.js:683:25
    getElementValue https://sandbox.example.com/static/adminhtml/Magento/backend/en_US/mage/adminhtml/wysiwyg/widget.js:683
    choose https://sandbox.example.com/static/adminhtml/Magento/backend/en_US/mage/adminhtml/wysiwyg/widget.js:620
    onclick https://sandbox.example.com/admin_nology/bannerslideradmin/banner/edit/banner_id/593/:1