Skip to content
This repository has been archived by the owner on Dec 3, 2020. It is now read-only.

Commit

Permalink
Fix #154: Parse Open Graph price string to a number
Browse files Browse the repository at this point in the history
Since the propTypes check for 'extractedProduct' object expects a number data type for the 'price' key's value, this patch parses the price string extracted via Open Graph into a number using the same 'parsePrice' function used by the other two extraction methods (Fathom and CSS Selectors).
  • Loading branch information
biancadanforth committed Oct 11, 2018
1 parent 644b70c commit 1b7919c
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/extraction/open_graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,35 @@
* Product extraction via Open Graph tags.
*/

import {parsePrice} from 'commerce/extraction/utils';

const OPEN_GRAPH_PROPERTY_VALUES = {
title: 'og:title',
image: 'og:image',
price: 'og:price:amount',
};

/** How product information is extracted depends on the feature */
const FEATURE_DEFAULTS = {
getValueFromElement(element) {
return element.getAttribute('content');
},
};
const PRODUCT_FEATURES = {
image: {
...FEATURE_DEFAULTS,
},
title: {
...FEATURE_DEFAULTS,
},
price: {
...FEATURE_DEFAULTS,
getValueFromElement(element) {
return parsePrice([element.getAttribute('content')]);
},
},
};

/**
* Returns any product information available on the page from Open Graph <meta>
* tags.
Expand All @@ -26,7 +49,7 @@ export default function extractProduct() {
return null;
}

extractedProduct[feature] = metaEle.getAttribute('content');
extractedProduct[feature] = PRODUCT_FEATURES[feature].getValueFromElement(metaEle);
}

return extractedProduct;
Expand Down

0 comments on commit 1b7919c

Please sign in to comment.