Commit 674ecee7 by liumengfei

优化批量上传图片接口

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