Magento 2 image not uploading in edit form
- DataProvider of UI Component:
<argument name="dataProvider" xsi:type="configurableObject"><argument name="class" xsi:type="string">Loyalty\PointsMall\Model\ResourceModel\Products\DataProvider</argument><argument name="name" xsi:type="string">loyalty_pointsMall_products_edit_data_source</argument><argument name="primaryFieldName" xsi:type="string">earning_rule_id</argument><argument name="requestFieldName" xsi:type="string">id</argument><argument name="data" xsi:type="array"><item name="config" xsi:type="array"><item name="submit_url" xsi:type="url" path="*/*/save"/></item></argument></argument>
- 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.
标签
热门文章
- 1 Magento ver. 2.2.0-dev - A technical prob... 16582
- 2 ECS git pull 代码很慢的问题 14715
- 3 玩客云监工客户端 13207
- 4 Magento 2 UI Form Validation 13124
- 5 Codeigniter SSL 强制重定向至https访问 13008
- 6 magento2 完整卸载模块的正确姿势 12642
- 7 Magento fix 500 12283
- 8 Magento index is locked by another reinde... 10741
- 9 Ubuntu删除日志文件 9014
- 10 Magento 2安装ElasticSearch 6.x搜索引擎-Ub... 8624
微信公众号
