Skip to content
Permalink
Browse files

added add to wishlist button

  • Loading branch information...
saumitra1993 committed Mar 6, 2019
1 parent 8f249f4 commit ffda26ce8f559f54497e125c50e34dcb662dd945
@@ -27,5 +27,42 @@
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
<script src="https://swymdev.azureedge.net/code/swym-notepad-v2-shopify.js" ></script>
<script>
var swappName = ("Wishlist" || "Wishlist");
var swymJSObject = {
pid: "m3AjodV+Ur7mQyrPWfXYOYjUzDjIkJFpJ3Q4vZ3i7ao=",
interface: "/apps/swym" + swappName + "/interfaces/interfaceStore.php?appname=" + swappName
};
window.swymPageLoad = function(){
window.SwymProductVariants = window.SwymProductVariants || {};
window.SwymHasCartItems = 0 > 0;
window.SwymPageData = {}, window.SwymProductInfo = {};
var unknown = {et: 0};
window.SwymPageData = unknown;
};
window.swymJSShopifyLoad = function(){
if(window.swymPageLoad) swymPageLoad();
if(!window._swat) {
(function (s, w, r, e, l, a, y) {
r['SwymRetailerConfig'] = s;
r[s] = r[s] || function (k, v) {
r[s][k] = v;
};
})('_swrc', '', window);
_swrc('RetailerId', swymJSObject.pid);
_swrc('Callback', function(){initSwymShopify();});
}else if(window._swat.postLoader){
_swrc = window._swat.postLoader;
_swrc('RetailerId', swymJSObject.pid);
_swrc('Callback', function(){initSwymShopify();});
}else{
initSwymShopify();
}
}
if(!window._SwymPreventAutoLoad) {
swymJSShopifyLoad();
}
</script>
</body>
</html>
@@ -16,6 +16,7 @@ class App extends Component {

this.handleCartClose = this.handleCartClose.bind(this);
this.addVariantToCart = this.addVariantToCart.bind(this);
this.addVariantToWishlist = this.addVariantToWishlist.bind(this);
this.updateQuantityInCart = this.updateQuantityInCart.bind(this);
this.removeLineItemInCart = this.removeLineItemInCart.bind(this);
}
@@ -78,6 +79,7 @@ class App extends Component {
node {
id
title
handle
options {
name
values
@@ -89,6 +91,7 @@ class App extends Component {
}
edges {
node {
id
title
selectedOptions {
name
@@ -125,6 +128,30 @@ class App extends Component {
});
}

getVariantObj(product, variantId){
return product.variants.filter(function(variant){
return (variant.id === variantId);
})[0];
}


addVariantToWishlist(product, variantId, callback){
var selectedVariant = this.getVariantObj(product, variantId);
var evtMap = {
empi: product.id,
epi: variantId,
pr: selectedVariant.price,
iu: selectedVariant.image.src,
du: "https://hello-again-saumitra.myshopify.com/" + product.handle,
dt: product.title,
uri: "https://hello-again-saumitra.myshopify.com/" + product.handle + "?variant=" + variantId
};
window._swat.addToWishList(evtMap, function(resp){
console.log(resp);
callback(resp);
});
}

addVariantToCart(variantId, quantity){
this.setState({
isCartOpen: true,
@@ -286,6 +313,7 @@ class App extends Component {
<Products
products={this.state.products}
addVariantToCart={this.addVariantToCart}
addVariantToWishlist={this.addVariantToWishlist}
/>
<Cart
checkout={this.state.checkout}
@@ -5,10 +5,13 @@ class Product extends Component {
constructor(props) {
super(props);

this.state = {};
this.state = {
addedToWishlist: false
};

this.handleOptionChange = this.handleOptionChange.bind(this);
this.handleQuantityChange = this.handleQuantityChange.bind(this);
this.handleAddedToWishlist = this.handleAddedToWishlist.bind(this);
this.findImage = this.findImage.bind(this);
}

@@ -53,6 +56,12 @@ class Product extends Component {
});
}

handleAddedToWishlist(resp){
this.setState({
addedToWishlist: true
});
}

render() {
let variantImage = this.state.selectedVariantImage || this.props.product.images[0].src
let variant = this.state.selectedVariant || this.props.product.variants[0]
@@ -77,6 +86,9 @@ class Product extends Component {
<input min="1" type="number" defaultValue={variantQuantity} onChange={this.handleQuantityChange}></input>
</label>
<button className="Product__buy button" onClick={() => this.props.addVariantToCart(variant.id, variantQuantity)}>Add to Cart</button>
<button style={{marginLeft: "5px"}} className="Product__buy button" onClick={() => this.props.addVariantToWishlist(this.props.product, variant.id, this.handleAddedToWishlist)}>
{this.state.addedToWishlist ? "Added to wishlist" : "Add to Wishlist"}
</button>
</div>
);
}
@@ -7,6 +7,7 @@ class Products extends Component {
return (
<Product
addVariantToCart={this.props.addVariantToCart}
addVariantToWishlist={this.props.addVariantToWishlist}
checkout={this.props.checkout}
key={product.id.toString()}
product={product}
@@ -6,10 +6,10 @@ import typeBundle from './types';
import '../../shared/app.css';

export const client = new Client(typeBundle, {
url: 'https://graphql.myshopify.com/api/graphql',
url: 'https://hello-again-saumitra.myshopify.com/api/graphql',
fetcherOptions: {
headers: {
'X-Shopify-Storefront-Access-Token': 'dd4d4dc146542ba7763305d71d1b3d38'
'X-Shopify-Storefront-Access-Token': '64376fe3df39d2b6dd6aec5aa0781ed0'
}
}
});

0 comments on commit ffda26c

Please sign in to comment.
You can’t perform that action at this time.