美文网首页
Magento 2 image not uploading in

Magento 2 image not uploading in

作者: 葡萄月令 | 来源:发表于2018-05-20 13:47 被阅读10次

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.

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

      本文链接:https://www.haomeiwen.com/subject/hiftjftx.html