Commit 674ecee7 by liumengfei

优化批量上传图片接口

parent 36ac22d7
...@@ -21,7 +21,7 @@ interface ProductAttributeMediaGalleryManagementInterface ...@@ -21,7 +21,7 @@ interface ProductAttributeMediaGalleryManagementInterface
* *
* @api * @api
* @param mixed $entry * @param mixed $entry
* @return boolean * @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]
*/ */
public function add( public function add(
$entry $entry
...@@ -44,12 +44,10 @@ interface ProductAttributeMediaGalleryManagementInterface ...@@ -44,12 +44,10 @@ interface ProductAttributeMediaGalleryManagementInterface
); );
/** /**
* Update gallery entry * Retrieve the list of gallery entries associated with given product
* *
* @param string $sku * @param string $sku
* @param \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface $entry * @return \Magento\Catalog\Api\Data\ProductAttributeMediaGalleryEntryInterface[]
* @return bool
* @throws \Magento\Framework\Exception\NoSuchEntityException
* @throws \Magento\Framework\Exception\StateException
*/ */
public function getList($sku);
} }
...@@ -76,9 +76,9 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal ...@@ -76,9 +76,9 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal
if (empty($content)) { if (empty($content)) {
return 0; return 0;
} }
$ids = []; $ids = true;
$sku = $content[0]['sku'];
foreach ($content as $entry){ foreach ($content as $entry){
$sku = $entry['sku'];
$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->setFile($entry['file']);
...@@ -92,18 +92,18 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal ...@@ -92,18 +92,18 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal
$imageContent->setType($entry['content']['type']); $imageContent->setType($entry['content']['type']);
$this->entry->setContent($imageContent); $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)){
$ids[$sku] = ["id"=>(int)$id]; $ids = false;
} }
} }
if (empty($ids)){ if (!$ids){
throw new StateException(__('Batch upload of product images failed')); throw new StateException(__('Batch upload of product images failed'));
} }
return $ids; return $this->getList($sku);
} }
/** /**
* @inheritdoc * @inheritdoc
*/ */
...@@ -152,4 +152,15 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal ...@@ -152,4 +152,15 @@ class GalleryManagement implements \Joshine\Catalog\Api\ProductAttributeMediaGal
throw new StateException(__('The new media gallery entry failed to save.')); throw new StateException(__('The new media gallery entry failed to save.'));
} }
/**
* @inheritdoc
*/
public function getList($sku)
{
/** @var \Magento\Catalog\Model\Product $product */
$product = $this->productRepository->get($sku);
return $product->getMediaGalleryEntries();
}
} }
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