Magento 2 image not uploading in edit form

Magento 2 image not uploading in edit form

  • DataProvider of UI Component:

    Loyalty\PointsMall\Model\ResourceModel\Products\DataProvider
    loyalty_pointsMall_products_edit_data_source
    earning_rule_id
    id
    
        
            
        
    

  • DataProvider.php
public function getData()
{
    if($this->request->getParams('id')){
        $collcetion = $this->productsFactory->create();
        $collcetion->load($this->request->getParams('id'));
        $this->_loadedData[$collcetion->getId()] = $collcetion->getData();
    }
    return $this->_loadedData;
}
  • Change function getData() as follow:
public function getData()
{
    if($this->request->getParams('id')){
        $collcetion = $this->productsFactory->create();
        $collcetion->load($this->request->getParams('id'));
        $productData = $collcetion->getData();
        if (isset($productData['image'])) {
            unset($productData['image']);
            $productData['image'][0]['name'] = $collcetion->getData('image');
            $productData['image'][0]['url'] = $this->imageHelper->getBaseUrl().$collcetion->getData('image');
        }
        $this->_loadedData[$collcetion->getId()] = $productData;
    }
    return $this->_loadedData;
}

After do that, it will be work.

Magento 2 image not uploading in edit form_第1张图片
Magento 2 image not uploading in edit form


More Information, Please Subscribe My Wechat Public Platform Or View My Blog : https://www.abmbio.xin

20180117_81914.jpg

你可能感兴趣的:(Magento 2 image not uploading in edit form)