Commit fe6802e3 by liumengfei

优化批量上传产品图片接口

parent 94b8b160
...@@ -74,7 +74,7 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal ...@@ -74,7 +74,7 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal
public function add($content) public function add($content)
{ {
if (empty($content)) { if (empty($content)) {
return 0; throw new StateException(__("request update date is null ,so failed"));
} }
$ids = []; $ids = [];
$sku = $content[0]['sku']; $sku = $content[0]['sku'];
...@@ -85,17 +85,10 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal ...@@ -85,17 +85,10 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal
} }
$this->entry->setMediaType($entry['media_type']); $this->entry->setMediaType($entry['media_type']);
$this->entry->setDisabled($entry['disabled']); $this->entry->setDisabled($entry['disabled']);
$this->entry->setFile($entry['file']);
$this->entry->setPosition($entry['position']); $this->entry->setPosition($entry['position']);
$this->entry->setLabel($entry['label']); $this->entry->setLabel($entry['label']);
$this->entry->setTypes($entry['types']); $this->entry->setTypes($entry['types']);
$imageContent = new ImageContent();
$imageContent->setBase64EncodedData($entry['content']['base64_encoded_data']);
$imageContent->setName($entry['content']['name']);
$imageContent->setType($entry['content']['type']);
$this->entry->setContent($imageContent);
if ($entry_id){ if ($entry_id){
$this->entry->setId($entry_id); $this->entry->setId($entry_id);
$result = $this->update($sku,$this->entry); $result = $this->update($sku,$this->entry);
...@@ -105,6 +98,12 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal ...@@ -105,6 +98,12 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal
throw new StateException(__("$entry_id update failed")); throw new StateException(__("$entry_id update failed"));
} }
}else{ }else{
$this->entry->setFile($entry['file']);
$imageContent = new ImageContent();
$imageContent->setBase64EncodedData($entry['content']['base64_encoded_data']);
$imageContent->setName($entry['content']['name']);
$imageContent->setType($entry['content']['type']);
$this->entry->setContent($imageContent);
$id = $this->create($sku,$this->entry); $id = $this->create($sku,$this->entry);
} }
if (is_numeric((int)$id)){ if (is_numeric((int)$id)){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment