Skip to content

Commit

Permalink
Add product Recommendation method
Browse files Browse the repository at this point in the history
Co-authored-by: Dmytro Kushnir <[email protected]>
  • Loading branch information
dmytrokushnir-gl and dmytro-kushnir committed Jan 18, 2022
1 parent 3e1fd9f commit 2b9c245
Show file tree
Hide file tree
Showing 6 changed files with 618 additions and 8 deletions.
185 changes: 178 additions & 7 deletions docs/ProductResource.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ <h4 class="name" id="ProductResource"><span class="type-signature"></span>new Pr

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line16">line 16</a>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line17">line 17</a>
</li></ul></dd>


Expand Down Expand Up @@ -250,7 +250,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line50">line 50</a>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line51">line 51</a>
</li></ul></dd>


Expand Down Expand Up @@ -431,7 +431,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line32">line 32</a>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line33">line 33</a>
</li></ul></dd>


Expand Down Expand Up @@ -600,7 +600,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line87">line 87</a>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line88">line 88</a>
</li></ul></dd>


Expand Down Expand Up @@ -769,7 +769,7 @@ <h5>Parameters:</h5>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line69">line 69</a>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line70">line 70</a>
</li></ul></dd>


Expand Down Expand Up @@ -1134,7 +1134,7 @@ <h6>Properties</h6>

<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line110">line 110</a>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line111">line 111</a>
</li></ul></dd>


Expand Down Expand Up @@ -1197,6 +1197,177 @@ <h5>Example</h5>








<h4 class="name" id="fetchRecommendations"><span class="type-signature"></span>fetchRecommendations<span class="signature">(productId)</span><span class="type-signature"> &rarr; {Promise|Array.&lt;GraphModel>}</span></h4>






<div class="description">
<p>Find recommended products related to a given productId.
To learn more about how recommendations are generated, see https://shopify.dev/themes/product-merchandising/recommendations.</p>
</div>









<h5>Parameters:</h5>


<table class="params">
<thead>
<tr>

<th>Name</th>


<th>Type</th>





<th class="last">Description</th>
</tr>
</thead>

<tbody>


<tr>

<td class="name"><code>productId</code></td>


<td class="type">


<span class="param-type">String</span>



</td>





<td class="description last"><p>The id of the product to fetch.</p></td>
</tr>


</tbody>
</table>






<dl class="details">


























<dt class="tag-source">Source:</dt>
<dd class="tag-source"><ul class="dummy"><li>
<a href="product-resource.js.html">product-resource.js</a>, <a href="product-resource.js.html#line136">line 136</a>
</li></ul></dd>







</dl>















<h5>Returns:</h5>


<div class="param-desc">
<p>A promise resolving with an array of <code>GraphModel</code>s of the products.</p>
</div>



<dl>
<dt>
Type
</dt>
<dd>

<span class="param-type">Promise</span>
|

<span class="param-type">Array.&lt;GraphModel></span>


</dd>
</dl>






<h5>Example</h5>

<pre class="prettyprint"><code>const productId 'Xk9lM2JkNzFmNzIQ4NTIY4ZDFi9DaGVja291dC9lM2JkN==';
client.product.fetchProductRecommendations(productId).then((products) => {
// Do something with the products
});</code></pre>







Expand All @@ -1218,7 +1389,7 @@ <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="ImageH
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Mon Aug 30 2021 17:03:36 GMT-0400 (Eastern Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Tue Jan 18 2022 10:11:11 GMT+0200 (Eastern European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
22 changes: 21 additions & 1 deletion docs/product-resource.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ <h1 class="page-title">Source: product-resource.js</h1>
import productNodesQuery from './graphql/productNodesQuery.graphql';
import productConnectionQuery from './graphql/productConnectionQuery.graphql';
import productByHandleQuery from './graphql/productByHandleQuery.graphql';
import productRecommendationsQuery from './graphql/productRecommendations.graphql';

/**
* The JS Buy SDK product resource
Expand Down Expand Up @@ -146,6 +147,25 @@ <h1 class="page-title">Source: product-resource.js</h1>
.then(defaultResolver('products'))
.then(paginateProductConnectionsAndResolve(this.graphQLClient));
}

/**
* Find recommended products related to a given product_id. To learn more about how recommendations are generated, see Showing product recommendations on product pages.
*
* @example
* const productId 'Xk9lM2JkNzFmNzIQ4NTIY4ZDFi9DaGVja291dC9lM2JkN==';
* client.product.fetchProductRecommendations(productId).then((products) => {
* // Do something with the products
* });
*
* @param {String} productId The base64 encoded id of the product to fetch
* @return {Promise|GraphModel[]} A promise resolving with an array of `GraphModel`s of the products.
*/
fetchRecommendations(productId) {
return this.graphQLClient
.send(productRecommendationsQuery, {productId})
.then(defaultResolver('productRecommendations'))
.then(paginateProductConnectionsAndResolve(this.graphQLClient));
}
}

export default ProductResource;
Expand All @@ -165,7 +185,7 @@ <h2><a href="index.html">Home</a></h2><h3>Namespaces</h3><ul><li><a href="ImageH
<br class="clear">

<footer>
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Mon Aug 30 2021 17:03:36 GMT-0400 (Eastern Daylight Time)
Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 3.6.3</a> on Mon Jan 17 2022 10:23:04 GMT+0200 (Eastern European Standard Time)
</footer>

<script> prettyPrint(); </script>
Expand Down
Loading

0 comments on commit 2b9c245

Please sign in to comment.