2

Magento has a widget where I can select a product. I need to embed it into my form. To be more clear I will provide screenshot: enter image description here

From this widget I need only product id. I can see that I need something like this:

<id_path translate="label">
    <visible>1</visible>
    <required>1</required>
    <label>Product</label>
    <type>label</type>
    <helper_block>
        <type>adminhtml/catalog_product_widget_chooser</type>
        <data>
            <button translate="open">
                <open>Select Product...</open>
            </button>
        </data>
    </helper_block>
    <sort_order>10</sort_order>
</id_path>

But didn't found yet how to use it. I will be appreciate for any help.

2 Answers 2

4

I assume that you are creating an own widget - the following does not apply for plain admin forms.

You simply put that snipped in the <parameters> section of your widget configuration (`widget.xml').

When the user chooses a product, the parameter id_path would be set in your widget.

Inside of your widget block you can get this parameter like this:

$this->getData('id_path');

The ID path contains stuff like 'product/123' - you probably only want the product id:

list($dummy, $productId) = explode("/", $this->getData('id_path'))
1
  • list didn'T work as expected - i had to list(, $productId) = explode("/",$this->getData('id_path'));
    – Barbarossa
    Jul 23, 2014 at 15:42
3

This is what I was looking for:

$product1Link = $fieldset->addField('product1_link', 'label', array(
        'name' => 'product1_link',
        'label' => Mage::helper('abc_productbundles')->__('Product 1'),
        'class' => 'widget-option',
        'value' => $model->getProduct1Link(),
        'required' => true,
    ));

$model->unsProduct1Link();
$helperBlock = $this->getLayout()->createBlock('adminhtml/catalog_product_widget_chooser');
if ($helperBlock instanceof Varien_Object) {
    $helperBlock->setConfig($this->getChooserConfig())
        ->setFieldsetId($fieldset->getId())
        ->setTranslationHelper(Mage::helper('abc_productbundles'))
        ->prepareElementHtml($product1Link);
}
4
  • $this->getChooserConfig() is its your defined method or magento? Jul 17, 2014 at 6:16
  • Magento method as I remember Jul 17, 2014 at 6:36
  • I'm trying the same but the button appears to be too small and without any label. Jul 17, 2014 at 6:56
  • @MohammadFaisal you need to implement the method yourself, and it returns the button text. See the improved answer
    – Erfan
    Sep 1, 2014 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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