1

I have a UI grid form in the admin, that allows the admin to edit the data in a grid. The grid is listing data from a custom table multivendor_pickupinstore with structure below:

id
seller_id
order_id
product_type
pickup_date
created_at
status

Now in the edit form I need to add the drop-down to choose the seller. The data is in another table multivendor_user with columns as below:

is_vendor
userstatus
user_id
priority
storeurl
storetitle
email
name 

What I have done so far is create the form with all the input fields. please see the field component in the form.xml file,

 <!-- This field has data type 'select' and standard 'input' form element and looks like input -->
 <field name="seller_id">
 <argument name="data" xsi:type="array">
 <item name="options" xsi:type="object">[Vendor]\[Module]\Model\Select\Source\Options</item>
 <item name="config" xsi:type="array">
 <item name="componentType" xsi:type="string">field</item>
 <item name="formElement" xsi:type="string">select</item>
 <item name="label" xsi:type="string">Seller</item>
 <item name="visible" xsi:type="boolean">true</item>
 <item name="dataType" xsi:type="string">text</item>
 <item name="source" xsi:type="string">p_pickups</item>
 </item>
 </argument>
 </field> 

I understand that the model [Vendor]\[Module]\Model\Select\Source\Options can be used to return the required option array. I have the model [Vendor2]\[Module2]\Model\Sellers that can be used to return the seller collection (table multivendor_user). But I am not able to get data from custom table. Could someone please help me with this. Thank you in advance.

asked Dec 13, 2019 at 9:16

1 Answer 1

0

After trying few methods I managed to get the options as below:

namespace [Vendor]\[Module]\Model\Select\Source;
use Magento\Framework\Option\ArrayInterface;
class Options implements ArrayInterface
{
 protected $options;
 public function __construct(
 [Vendor2]\[Module2]\Model\SellersFactory $sellersFactory
 ) {
 $this->sellersFactory = $sellersFactory;
 }
 public function toOptionArray()
 {
 $sellerModel = $this->sellersFactory->create()->getCollection()
 ->addFieldToSelect( array('user_id','storetitle','name') );
 $options = array( 'label' => 'Please select', 'value' => '' );
 if( $sellerModel->getSize() ){
 foreach ( $sellerModel as $seller) {
 $options[] = array( 
 'label' => ucfirst( $seller->getData('storetitle') ) ,
 'value' => $seller->getData('user_id')
 );
 }
 }
 return $options;
 }
} 

Not sure if this is the best method though. Please share if there is a better way. Thank you

answered Dec 13, 2019 at 12:41

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.