diff --git a/AdobeStockAsset/Model/AppendAttributes.php b/AdobeStockAsset/Model/AppendAttributes.php
new file mode 100644
index 000000000000..1cc75d07bec3
--- /dev/null
+++ b/AdobeStockAsset/Model/AppendAttributes.php
@@ -0,0 +1,125 @@
+resourceConnection = $resourceConnection;
+ $this->attributeValueFactory = $attributeValueFactory;
+ $this->loadByIds = $loadByIds;
+ }
+
+ /**
+ * Add additional asset attributes
+ *
+ * @param SearchResultInterface $searchResult
+ * @return SearchResultInterface
+ */
+ public function execute(SearchResultInterface $searchResult): SearchResultInterface
+ {
+ $items = $searchResult->getItems();
+
+ if (empty($items)) {
+ return $searchResult;
+ }
+
+ $ids = array_map(
+ function ($item) {
+ return $item->getId();
+ },
+ $items
+ );
+
+ $assets = $this->loadByIds->execute($ids);
+
+ foreach ($items as $key => $item) {
+ if (!isset($assets[$item->getId()])) {
+ $this->addAttributes(
+ $item,
+ [
+ self::ATTRIBUTE_CODE_IS_DOWNLOADED => 0,
+ self::ATTRIBUTE_CODE_PATH => ''
+ ]
+ );
+ continue;
+ }
+
+ $this->addAttributes(
+ $item,
+ [
+ self::ATTRIBUTE_CODE_IS_DOWNLOADED => 1,
+ self::ATTRIBUTE_CODE_PATH => $assets[$item->getId()]->getPath()
+ ]
+ );
+ }
+
+ return $searchResult;
+ }
+
+ /**
+ * Add attributes to document
+ *
+ * @param DocumentInterface $document
+ * @param array $attributes [code => value]
+ * @return DocumentInterface
+ */
+ private function addAttributes(DocumentInterface $document, array $attributes): DocumentInterface
+ {
+ $customAttributes = $document->getCustomAttributes();
+
+ foreach ($attributes as $code => $value) {
+ $attribute = $this->attributeValueFactory->create();
+ $attribute->setAttributeCode($code);
+ $attribute->setValue($value);
+ $customAttributes[$code] = $attribute;
+ }
+
+ $document->setCustomAttributes($customAttributes);
+
+ return $document;
+ }
+}
diff --git a/AdobeStockAsset/Model/GetAssetList.php b/AdobeStockAsset/Model/GetAssetList.php
index 7a0b4d4acd82..248472442eca 100644
--- a/AdobeStockAsset/Model/GetAssetList.php
+++ b/AdobeStockAsset/Model/GetAssetList.php
@@ -22,6 +22,11 @@
*/
class GetAssetList implements GetAssetListInterface
{
+ /**
+ * @var AppendAttributes
+ */
+ private $appendAttributes;
+
/**
* @var ClientInterface
*/
@@ -40,17 +45,20 @@ class GetAssetList implements GetAssetListInterface
/**
* GetAssetList constructor.
* @param ClientInterface $client
- * @param UrlInterface $url
+ * @param UrlInterface $url
* @param LoggerInterface $log
+ * @param AppendAttributes $appendAttributes
*/
public function __construct(
ClientInterface $client,
UrlInterface $url,
- LoggerInterface $log
+ LoggerInterface $log,
+ AppendAttributes $appendAttributes
) {
$this->client = $client;
$this->url = $url;
$this->log = $log;
+ $this->appendAttributes = $appendAttributes;
}
/**
@@ -59,7 +67,10 @@ public function __construct(
public function execute(SearchCriteriaInterface $searchCriteria): SearchResultInterface
{
try {
- return $this->client->search($searchCriteria);
+ $searchResult = $this->client->search($searchCriteria);
+ $this->appendAttributes->execute($searchResult);
+
+ return $searchResult;
} catch (AuthenticationException $exception) {
throw new LocalizedException(
__(
diff --git a/AdobeStockAsset/Model/ResourceModel/Asset/Command/Save.php b/AdobeStockAsset/Model/ResourceModel/Asset/Command/Save.php
index 71e64d833be1..26a2b078219c 100644
--- a/AdobeStockAsset/Model/ResourceModel/Asset/Command/Save.php
+++ b/AdobeStockAsset/Model/ResourceModel/Asset/Command/Save.php
@@ -43,14 +43,14 @@ public function __construct(
}
/**
- * Multiple save category
+ * Save asset
*
- * @param AssetInterface $assets
+ * @param AssetInterface $asset
* @return void
*/
- public function execute(AssetInterface $assets): void
+ public function execute(AssetInterface $asset): void
{
- $data = $this->hydrator->extract($assets);
+ $data = $this->hydrator->extract($asset);
$tableName = $this->resourceConnection->getTableName(
AssetResourceModel::ADOBE_STOCK_ASSET_TABLE_NAME
);
diff --git a/AdobeStockAsset/Model/ResourceModel/Asset/LoadByIds.php b/AdobeStockAsset/Model/ResourceModel/Asset/LoadByIds.php
new file mode 100644
index 000000000000..43a5b313ef5e
--- /dev/null
+++ b/AdobeStockAsset/Model/ResourceModel/Asset/LoadByIds.php
@@ -0,0 +1,74 @@
+factory = $factory;
+ $this->resourceConnection = $resourceConnection;
+ $this->hydrator = $hydrate;
+ }
+
+ /**
+ * Load assets by ids
+ *
+ * @param \int[] $ids
+ * @return AssetInterface[]
+ */
+ public function execute(array $ids): array
+ {
+ $connection = $this->resourceConnection->getConnection();
+ $select = $connection->select()
+ ->from(AssetResourceModel::ADOBE_STOCK_ASSET_TABLE_NAME)
+ ->where('id in (?)', $ids);
+ $data = $connection->fetchAssoc($select);
+
+ $assets = [];
+
+ foreach ($data as $id => $assetData) {
+ $asset = $this->factory->create();
+ $assets[$id] = $this->hydrator->hydrate($asset, $assetData);
+ }
+
+ return $assets;
+ }
+}
diff --git a/AdobeStockAsset/etc/di.xml b/AdobeStockAsset/etc/di.xml
index 2916ddeebaf9..decbdacfee01 100644
--- a/AdobeStockAsset/etc/di.xml
+++ b/AdobeStockAsset/etc/di.xml
@@ -69,4 +69,14 @@
+