Magento2 Admin form for Image Upload

I have created a module in magento2 to upload image field. Saving the image hiding the image upload field option in backend

public function execute()     {         /** @var \Magento\Backend\Model\View\Result\Redirect $  resultRedirect */         $  resultRedirect = $  this->resultRedirectFactory->create();         $  data = $  this->getRequest()->getPostValue();         if($  data) {             if(isset($  data['is_active']) && $  data['is_active'] === 'true') {                 $  data['is_active'] = Notification::STATUS_ENABLED;             }             if(empty($  data['notification_id'])){                 $  data['notification_id'] = null;              }              if(isset($  data['image']) && is_array($  data['image'])){                 $  data['image']=$  data['image'][0]['name'];             }              else{                 $  data['image'] = null;             }             /** @var  \Dzinehub\PushNotification\Model\Notification $  notification */             $  model = $  this->notificationFactory->create();              $  id = $  this->getRequest()->getParam('notification_id');              if($  id) {                 try{                     $  model = $  this->notificationRepository->getById($  id);                 } catch(LocalizedException $  e) {                     $  this->messageManager->addErrorMessage(__('Notification no longer exists'));                     return $  resultRedirect->setPath('*/*/');                 }             }              $  model->setData($  data);              /* var_dump($  data);              die;*/                try {                 $  this->notificationRepository->save($  model);                 $  this->messageManager->addSuccessMessage(__('You saved the notification.'));                 $  this->dataPersistor->clear('dzpushnotif');                 if ($  this->getRequest()->getParam('back')) {                     return $  resultRedirect->setPath('*/*/edit', ['notification_id' => $  model->getId()]);                 }                 return $  resultRedirect->setPath('*/*/');             } catch (LocalizedException $  e) {                 $  this->messageManager->addErrorMessage($  e->getMessage());             } catch (\Exception $  e) {                 $  this->messageManager->addExceptionMessage($  e, __('Something went wrong while saving the notification.'));             }              $  this->dataPersistor->set('dzpushnotif', $  data);             return $  resultRedirect->setPath('*/*/edit', ['notification_id' => $  this->getRequest()->getParam('notification_id')]);         }         return $  resultRedirect->setPath('*/*/');         } 

Also, how to move the image from temporary directory using this function moveFileFromTmp. Any help on this issue?

How can I update all products names via sql query in magento2?

Hi I have a list of sku’s of all products at my store , I want to update all the names of products I have on store via sql query with respect to it’s sku .

There is a table name : catalog_product_flat_21 and catalog_product_flat_19 at my database

Just for checking I have updated the column of (name) in these both tables and refresh the caches but still name on site is not update !

Tell me if you have solution of this using sql query , Thanks!

How to add a Custom Image feild in Category Api magento2

In my category api http://127.0.0.1/magento/rest/V1/categories returns response like below

            .......................{             "id": 140,             "parent_id": 2,             "name": "Grocery",             "is_active": true,             "position": 1,             "level": 2,             "product_count": 343,             "children_data": [             {...................... 

I need to add a thumbnail field into this result like

        ......................{         "id": 140,         "parent_id": 2,         "name": "Grocery",         "is_active": true,         "position": 1,         "level": 2,         "product_count": 343,         "thumbnail":example/image/file.png          "children_data": [         {...................... 

Currently i have the image in my category collection and i need to add new attributes in my api response using ‘extension attributes’

How to Receive XML Post Data in Magento2?

I want to receive and validate xml object from third party application in Magento2.

How I can write custom endpoint and response for this.

Xml payload:

<myitems> <item>  <info1></info1>  <info2></info2>  <info3></info3>  <info4></info4> </item> <item>  <info1></info1>  <info2></info2>  <info3></info3>  <info4></info4> </item> </myitems> 

If anybody can share tips to write custom api in Magento2 to handle xml post and response.

How to override comment field in system.xml in magento2?

I have override system.xml file.

My label is overridden but comment field is not overridden. It’s still take from core file. Any help should be appreciated. Thanks.

Core system.xml file code

<?xml version="1.0"?>   <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../Magento/Config/etc/system_file.xsd"> <system>     <tab id="lsc" translate="label" sortOrder="100">         <label>SLI Systems LSC</label>     </tab>     <section id="sli_feed_generation" translate="label" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">         <class>separator-top</class>         <label>Feed Generation</label>         <tab>lsc</tab>         <resource>Sli_Feed::config_feed</resource>          <group id="general" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">             <label>General</label>             <field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Enabled</label>                 <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>             </field>             <field id="log_level" translate="label comment" type="select" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Log Level</label>                 <comment>Please set to "Debug" if SLI support is required.</comment>                 <source_model>SLI\Feed\Model\Config\Source\Log</source_model>             </field>             <field id="version" translate="label" type="label" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Version</label>                 <frontend_model>SLI\Feed\Block\System\Config\Version</frontend_model>             </field>         </group>          <group id="feed" translate="label" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">             <label>Feed Settings</label>             <field id="advanced_pricing" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Advanced Pricing</label>                 <comment>Enable if need advanced prices from: Catalog Price Rules, Group or Tiered Pricing.</comment>                 <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>             </field>             <field id="include_out_of_stock" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Include Out of Stock Items</label>                 <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>             </field>             <field id="generate" translate="label comment" type="button" sortOrder="2" showInDefault="1" showInWebsite="0" showInStore="0">                 <label>Generate Feed</label>                 <frontend_model>SLI\Feed\Block\System\Config\Generate</frontend_model>                 <comment>Manually generates feed. If FTP is enabled, also sends the feed.</comment>             </field>         </group>          <group id="ftp" translate="label" type="text" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">             <label>FTP Settings</label>             <field id="enabled" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Enabled</label>                 <source_model>Magento\Config\Model\Config\Source\Yesno</source_model>             </field>             <field id="user" translate="label comment" type="text" sortOrder="2" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>FTP User</label>                 <comment>Provided by SLI.</comment>                 <depends>                     <field id="enabled">1</field>                 </depends>             </field>             <field id="password" translate="label comment" type="obscure" sortOrder="3" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>FTP Password</label>                 <backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>                 <comment>Provided by SLI.</comment>                 <depends>                     <field id="enabled">1</field>                 </depends>             </field>             <field id="host" translate="label comment" type="text" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>FTP Host</label>                 <comment>Provided by SLI.</comment>                 <depends>                     <field id="enabled">1</field>                 </depends>             </field>             <field id="upload_path" translate="label comment" type="text" sortOrder="5" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>FTP Upload Path</label>                 <comment>Provided by SLI.</comment>                 <depends>                     <field id="enabled">1</field>                 </depends>             </field>         </group>          <group id="product" translate="label" type="select" sortOrder="4" showInDefault="1" showInWebsite="1" showInStore="1">             <label>Product Attributes</label>             <field id="attributes_select" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">                 <label>Attributes to include</label>                  <frontend_model>SLI\Feed\Block\System\Config\Form\Field\FeedAttributesConfig</frontend_model>                 <backend_model>Magento\Config\Model\Config\Backend\Serialized\ArraySerialized</backend_model>                  <comment>                     <![CDATA[                     The following attributes are automatically added to the feed: <br />                     <ul style="margin-left: 2em;">                         <li><small>attribute_set_id</small></li>                         <li><small>categories</small></li>                         <li><small>child_ids</small></li>                         <li><small>created_at</small></li>                         <li><small>entity_id</small></li>                         <li><small>final_price</small></li>                         <li><small>has_options</small></li>                         <li><small>is_salable</small></li>                         <li><small>is_virtual</small></li>                         <li><small>max_price</small></li>                         <li><small>min_price</small></li>                         <li><small>minimal_price</small></li>                         <li><small>name</small></li>                         <li><small>price</small></li>                         <li><small>special_from_date</small></li>                         <li><small>special_price</small></li>                         <li><small>special_to_date</small></li>                         <li><small>request_path</small></li>                         <li><small>required_options</small></li>                         <li><small>sku</small></li>                         <li><small>tax_class_id</small></li>                         <li><small>tier_price</small></li>                         <li><small>type_id</small></li>                         <li><small>updated_at</small></li>                         <li><small>url_key</small></li>                         <li><small>visibility</small></li>                         <li><small>image</small></li>                     </ul>                     ]]>                 </comment>             </field>         </group>     </section> </system> 

my custom system.xml code

   <?xml version="1.0" encoding="UTF-8"?>   <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd"> <system>     <section id="sli_feed_generation" >         <group id="product">             <label>Product Attributes AData</label>             <field id="attributes_select" translate="label" type="select" sortOrder="1" showInDefault="1" showInWebsite="1" showInStore="1">                 <comment>                     <![CDATA[                     The following attributes are automatically added to the feed: <br />                     <ul style="margin-left: 2em;">                         <li><small>attribute_set_id</small></li>                         <li><small>categories</small></li>                      </ul>                     ]]>                 </comment>             </field>         </group>     </section> </system> 

please see: enter image description here

module.xml

 <?xml version="1.0"?>   <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd"> <module name="Tatva_SLIFeed" setup_version="0.0.1">     <sequence>         <module name="SLI_Feed" />     </sequence> </module> 

Magento2: How can I create a validation for telephone inputs inside Magento Admin?

I have to create a validation for the telephone inputs in Magento Admin. I need to set a min of characters like 8 and a max of 15. I’m currently using 2.2.8 version.

I tried to set the validation by admin using telephone attribute, but it didn’t work. It inserts a class for validation but doesn’t validate at all.