This repository has been archived by the owner on Jun 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from afirlejczyk/feature/sync-reviews
Review sync
- Loading branch information
Showing
7 changed files
with
172 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"id": 0, | ||
"title": "string", | ||
"detail": "string", | ||
"nickname": "string", | ||
"ratings": [{ | ||
"id": 0, | ||
"review_id": 0, | ||
"attribute_code": "string", | ||
"value": 0 | ||
}], | ||
"customer_id": null, | ||
"review_entity": "product", | ||
"review_type": 0, | ||
"review_status": 0, | ||
"created_at": "string", | ||
"entity_pk_value": 0, | ||
"stores": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const util = require('util'); | ||
|
||
module.exports = function (restClient) { | ||
var module = {}; | ||
|
||
module.getByProductSku = function (sku) { | ||
const endpointUrl = util.format('/products/%s/review', encodeURIComponent(sku)); | ||
return restClient.get(endpointUrl); | ||
}; | ||
|
||
module.list = function(searchCriteria) { | ||
const query = 'searchCriteria=' + searchCriteria; | ||
const endpointUrl = util.format('/reviews/?%s', query); | ||
return restClient.get(endpointUrl); | ||
}; | ||
|
||
module.create = function (reviewData) { | ||
return restClient.post('/reviews', {review: reviewData}) | ||
} | ||
|
||
module.delete = function (reviewId) { | ||
var endpointUrl = util.format('/reviews/%d', reviewId); | ||
return restClient.delete(endpointUrl); | ||
} | ||
|
||
return module; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
'use strict'; | ||
|
||
let AbstractMagentoAdapter = require('./abstract'); | ||
const CacheKeys = require('./cache_keys'); | ||
const util = require('util'); | ||
|
||
class ReviewAdapter extends AbstractMagentoAdapter { | ||
constructor(config) { | ||
super(config); | ||
this.use_paging = false; | ||
} | ||
|
||
getEntityType() { | ||
return 'review'; | ||
} | ||
|
||
getName() { | ||
return 'adapters/magento/ReviewAdapter'; | ||
} | ||
|
||
getSourceData(context) { | ||
if (this.use_paging) { | ||
return this.api.reviews.list('&searchCriteria[currentPage]=' + this.page + '&searchCriteria[pageSize]=' + this.page_size + (query ? '&' + query : '')).catch(function (err) { | ||
throw new Error(err); | ||
}); | ||
} | ||
|
||
return this.api.reviews.list().catch(function (err) { | ||
throw new Error(err); | ||
}); | ||
} | ||
|
||
/** | ||
* Regarding Magento2 api docs and reality | ||
* we do have an exception here that items aren't listed straight | ||
* in the response but under "items" key */ | ||
prepareItems(items) { | ||
if (!items) { | ||
return items; | ||
} | ||
|
||
if (items.total_count) { | ||
this.total_count = items.total_count; | ||
} | ||
|
||
if (this.use_paging) { | ||
this.page_count = this.total_count / this.page_size; | ||
} | ||
|
||
if (items.items) { | ||
items = items.items; // this is an exceptional behavior for Magento2 api for lists | ||
} | ||
|
||
return items; | ||
} | ||
|
||
isFederated() { | ||
return false; | ||
} | ||
|
||
preProcessItem(item) { | ||
logger.debug(item); | ||
// | ||
return new Promise((function (done, reject) { | ||
if (item) { | ||
item.product_id = item.entity_pk_value; | ||
|
||
delete item.entity_pk_value; | ||
delete item.ratings; | ||
|
||
logger.debug(util.format('Review %s', item.id)); | ||
} | ||
|
||
return done(item); | ||
}).bind(this)); | ||
} | ||
|
||
/** | ||
* 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 | ||
*/ | ||
normalizeDocumentFormat(item) { | ||
return item; | ||
} | ||
} | ||
|
||
module.exports = ReviewAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters