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

Commit

Permalink
Merge pull request #79 from DivanteLtd/develop
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
patzick committed Mar 4, 2019
2 parents 07f3376 + d14a271 commit 349c190
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `elasticsearch.apiVesion` with default = 5.6 added to the config

## [1.8.0] - 2019.02.08
### Added
- Video data mapper @rain2go [#75](https://github.com/DivanteLtd/mage2vuestorefront/pull/75)

## [1.8.0]
### Added
- Setting `configurable_options.label` from the attribute meta descriptor. **Note:** When You modify any configurable attribute label in Magento You should reindex all products now
- Configurable parent refresh sync - enabled in the `productsdelta` and `productsworker` modes and in `products --sku=<singleSku>`. This mode is refreshing the configurable parent product for the simple child which requires update. Its' required to start the `clis.js productsworker` (example call: `test_product_worker.sh`) for processing these parent updates,
Expand Down
20 changes: 15 additions & 5 deletions src/adapters/magento/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const util = require('util');
const request = require('request');
const _slugify = require('../../helpers/slugify')

const _normalizeExtendedData = function (result, generateUrlKey = true) {
const _normalizeExtendedData = function (result, generateUrlKey = true, config = null) {
if (result.custom_attributes) {
for (let customAttribute of result.custom_attributes) { // map custom attributes directly to document root scope
result[customAttribute.attribute_code] = customAttribute.value;
Expand All @@ -16,7 +16,12 @@ const _normalizeExtendedData = function (result, generateUrlKey = true) {
if (generateUrlKey) {
result.url_key = _slugify(result.name) + '-' + result.id;
}
result.slug = result.url_key;
result.slug = result.url_key
if (config.seo.useUrlDispatcher) {
result.url_path = config.seo.categoryUrlPathMapper(result)
} else {
result.url_path = result.url_key;
}
return result
}

Expand Down Expand Up @@ -51,13 +56,14 @@ class CategoryAdapter extends AbstractMagentoAdapter {
}

_addSingleCategoryData(item, result) {
item = Object.assign(item, _normalizeExtendedData(result, this.generateUniqueUrlKeys));
item = Object.assign(item, _normalizeExtendedData(result, this.generateUniqueUrlKeys, this.config));
}

_extendSingleCategory(rootId, catToExtend) {
const generateUniqueUrlKeys = this.generateUniqueUrlKeys
const config = this.config
return this.api.categories.getSingle(catToExtend.id).then(function(result) {
Object.assign(catToExtend, _normalizeExtendedData(result, generateUniqueUrlKeys))
Object.assign(catToExtend, _normalizeExtendedData(result, generateUniqueUrlKeys, config))
logger.info(`Subcategory data extended for ${rootId}, children object ${catToExtend.id}`)
}).catch(function(err) {
logger.error(err)
Expand Down Expand Up @@ -87,7 +93,11 @@ class CategoryAdapter extends AbstractMagentoAdapter {
item.url_key = _slugify(item.name) + '-' + item.id
}
item.slug = item.url_key;

if (this.config.seo.useUrlDispatcher) {
item.url_path = this.config.seo.categoryUrlPathMapper(item)
} else {
item.url_path = item.url_key;
}

if (this.extendedCategories) {

Expand Down
51 changes: 49 additions & 2 deletions src/adapters/magento/product.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const _ = require('lodash')
const request = require('request');
const HTTP_RETRIES = 3
let kue = require('kue');
const _slugify = require('../../helpers/slugify')

/*
* serial executes Promises sequentially.
Expand Down Expand Up @@ -230,6 +231,7 @@ class ProductAdapter extends AbstractMagentoAdapter {
for (let customAttribute of item.custom_attributes) { // map custom attributes directly to document root scope
item[customAttribute.attribute_code] = customAttribute.value;
}
item.slug = _slugify(item.name + '-' + item.id)
item.custom_attributes = null;

return new Promise((done, reject) => {
Expand Down Expand Up @@ -268,7 +270,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)
})
}
}
Expand Down Expand Up @@ -497,7 +500,9 @@ class ProductAdapter extends AbstractMagentoAdapter {
if (cat != null) {
resolve({
category_id: cat.id,
name: cat.name
name: cat.name,
slug: cat.slug,
path: cat.url_path
})
} else {
resolve({
Expand All @@ -512,6 +517,9 @@ class ProductAdapter extends AbstractMagentoAdapter {
Promise.all(catPromises).then((values) => {
if(this.category_sync) // TODO: refactor the code above to not get cache categorylinks when no category_sync required
item.category = values; // here we get configurable options
if (this.config.seo.useUrlDispatcher) {
item.url_path = this.config.seo.productUrlPathMapper(item)
}
resolve(item)
});
}
Expand Down Expand Up @@ -542,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
Expand Down
23 changes: 23 additions & 0 deletions src/config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
const _slugify = require('./helpers/slugify')

module.exports = {

seo: {
useUrlDispatcher: JSON.parse(process.env.SEO_USE_URL_DISPATCHER || false),
productUrlPathMapper: (product) => {
let destPath = ''
if (product.category && product.category.length > 0) {
const firstCat = product.category[0]
destPath = (firstCat.path ? (firstCat.path) : _slugify(firstCat.name)) + '/' + (product.slug ? product.slug : _slugify(product.name + '-' + product.id))
} else {
destPath = (product.slug ? product.slug : _slugify(product.name + '-' + product.id))
}
destPath += '.html'
console.log('Dest. product path = ', destPath)
return destPath
},
categoryUrlPathMapper: (category) => {
const destSlug = (category.url_path ? category.url_path + '/': '') + category.url_key
console.log('Dest. cat path = ', destSlug)
return destSlug
},
},

magento: {
url: process.env.MAGENTO_URL || 'http://magento2.demo-1.divante.pl/rest/',
consumerKey: process.env.MAGENTO_CONSUMER_KEY || 'alva6h6hku9qxrpfe02c2jalopx7od1q',
Expand Down
1 change: 1 addition & 0 deletions src/test_fullreindex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export MAGENTO_CONSUMER_KEY=byv3730rhoulpopcq64don8ukb8lf2gq
export MAGENTO_CONSUMER_SECRET=u9q4fcobv7vfx9td80oupa6uhexc27rb
export MAGENTO_ACCESS_TOKEN=040xx3qy7s0j28o3q0exrfop579cy20m
export MAGENTO_ACCESS_TOKEN_SECRET=7qunl3p505rubmr7u1ijt7odyialnih9
export SEO_USE_URL_DISPATCHER=1

echo 'Default store - in our case United States / en'
export MAGENTO_URL=http://demo-magento2.vuestorefront.io/rest
Expand Down
1 change: 1 addition & 0 deletions src/test_multistore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export MAGENTO_CONSUMER_KEY=byv3730rhoulpopcq64don8ukb8lf2gq
export MAGENTO_CONSUMER_SECRET=u9q4fcobv7vfx9td80oupa6uhexc27rb
export MAGENTO_ACCESS_TOKEN=040xx3qy7s0j28o3q0exrfop579cy20m
export MAGENTO_ACCESS_TOKEN_SECRET=7qunl3p505rubmr7u1ijt7odyialnih9
export SEO_USE_URL_DISPATCHER=1

echo 'German store - de'
export MAGENTO_URL=http://demo-magento2.vuestorefront.io/rest/de
Expand Down

0 comments on commit 349c190

Please sign in to comment.