Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Mapping video data for product gallery #75

Merged
merged 2 commits into from
Feb 22, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion src/adapters/magento/product.js
Original file line number Diff line number Diff line change
@@ -268,7 +268,8 @@ class ProductAdapter extends AbstractMagentoAdapter {
image: mediaItem.file,
pos: mediaItem.position,
typ: mediaItem.media_type,
lab: mediaItem.label
lab: mediaItem.label,
vid: this.computeVideoData(mediaItem)
})
}
}
@@ -549,6 +550,45 @@ class ProductAdapter extends AbstractMagentoAdapter {
});
}

/**
* Process video data to provide the proper
* provider and attributes.
* Currently supports YouTube and Vimeo
*
* @param {Object} mediaItem
*/
computeVideoData(mediaItem) {
let videoData = null;

if (mediaItem.extension_attributes && mediaItem.extension_attributes.video_content) {
let videoId = null,
type = null,
youtubeRegex = /^(?:https?:\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/,
vimeoRegex = new RegExp(['https?:\\/\\/(?:www\\.|player\\.)?vimeo.com\\/(?:channels\\/(?:\\w+\\/)',
'?|groups\\/([^\\/]*)\\/videos\\/|album\\/(\\d+)\\/video\\/|video\\/|)(\\d+)(?:$|\\/|\\?)'
].join(''));

if (mediaItem.extension_attributes.video_content.video_url.match(youtubeRegex)) {
videoId = RegExp.$1
type = 'youtube'
} else if (mediaItem.extension_attributes.video_content.video_url.match(vimeoRegex)) {
videoId = RegExp.$3
type = 'vimeo'
}

videoData = {
url: mediaItem.extension_attributes.video_content.video_url,
title: mediaItem.extension_attributes.video_content.video_title,
desc: mediaItem.extension_attributes.video_content.video_description,
meta: mediaItem.extension_attributes.video_content.video_metadata,
id: videoId,
type: type
}
}

return videoData;
}

/**
* We're transorming the data structure of item to be compliant with Smile.fr Elastic Search Suite
* @param {object} item document to be updated in elastic search