3

I need to create an addnametoselect function (like in customer collection) for filtering purpose in the custom collection filter by the fields in custom Table on DB in magento2. Please, anyone, help me.

  • please anyone help me.. this will be more helpful to me... I'm a opencart dev and too beginner in Magento2 – Ask Bytes Sep 23 '18 at 13:05
  • @Amit Bera ji please help me.. – Ask Bytes Sep 23 '18 at 13:06
  • Please provide file name on which you want to implement addnametoselect function? – Amit Bera Sep 23 '18 at 16:14
  • agentcollection sir.. @AmitBera – Ask Bytes Sep 24 '18 at 5:48
  • I am asking about fields name on your want to build addnametoselect on the agent module.In Magento customer collection addnametoselect build on firstname, last name, middle name, prefix, SO, for your collection which fields will be used. – Amit Bera Sep 24 '18 at 5:51
1

try this below:

  public function addnametoselect($collection, $valueToFilter, $condition = 'eq')
        {
            if ($condition == 'eq') {
                $collection->addFieldToFilter('name', $valueToFilter);
            } else {
                $collection->addFieldToFilter('name', ['like' => "%$valueToFilter%"]);
            }

        }
  • MY ACTUAL NEED: I need to get fields by like below public function addNameToSelect() { $fields = []; $agentAccount = $this->_fieldsetConfig->getFieldset('agent_account'); foreach ($customerAccount as $code => $field) { if (isset($field['email'])) {$fields[$code] = $code; } } $this->addExpressionAttributeToSelect('name', $nameExpr, $fields); return $this; } On this, how to get the getFieldset i don't have agent_account in my custom module what is that mean.? – Ask Bytes Sep 24 '18 at 7:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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