Shopify购买按钮-使图像可点击



我使用Shopify上的购买按钮,我已经嵌入了一个集合,点击购买按钮打开了模式,这很好。我试图使它,使图像也是可点击的,也应该打开模态。

我已经走到一半了,事实上我可以使用ui.openCart()打开购物车,但我不知道如何访问模态,我尝试了以下方法,但无济于事。

function ShopifyBuyInit() {
var client = ShopifyBuy.buildClient({
domain: 'harrisons-respiratory-protection.myshopify.com',
storefrontAccessToken: '5548f7e9e0a419188135d4caa368d998',
});
ShopifyBuy.UI.onReady(client).then(function (ui) {
ui.createComponent('collection', {
id: '<?php echo $catID; ?>',
node: document.getElementById('collection-component-<?php echo $divID; ?>'),
moneyFormat: '%C2%A3%7B%7Bamount%7D%7D',
options: {
"product": {
"events": {
afterInit: function (component) {
var elem = $('img', component.node);
$(elem).click(function() {
e.stopPropagation();
ui.openModal();
});

}
},
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "calc(25% - 20px)",
"margin-left": "20px",
"margin-bottom": "50px",
"width": "calc(25% - 20px)"
},
"img": {
"height": "calc(100% - 15px)",
"position": "absolute",
"left": "0",
"right": "0",
"top": "0"
},
"imgWrapper": {
"padding-top": "calc(75% + 15px)",
"position": "relative",
"height": "0"
}
},
"title": {
"font-size": "20px",
"color": "#555555",
"min-height": "<?php echo $three != '' ? $three : '50px'; $three = ''; ?>"
},
"button": {
"font-weight": "bold",
":hover": {
"background-color": "#48b5dd"
},
"background-color": "#50c9f6",
":focus": {
"background-color": "#48b5dd"
},
"border-radius": "4px",
"padding-left": "47px",
"padding-right": "47px"
},
"price": {
"font-size": "16px",
"color": "#555555"
},
"compareAt": {
"font-size": "13.6px",
"color": "#555555"
},
"unitPrice": {
"font-size": "13.6px",
"color": "#555555"
}
},
"buttonDestination": "modal",
"contents": {
"options": false
},
"text": {
"button": "VIEW PRODUCT"
}
},
"productSet": {
"styles": {
"products": {
"@media (min-width: 601px)": {
"margin-left": "-20px",
"text-align" : "left"
}
}
}
},
"modalProduct": {
"contents": {
"img": false,
"imgWithCarousel": true,
"button": false,
"buttonWithQuantity": true
},
"styles": {
"product": {
"@media (min-width: 601px)": {
"max-width": "100%",
"margin-left": "0px",
"margin-bottom": "0px"
}
},
"button": {
"font-weight": "bold",
":hover": {
"background-color": "#48b5dd"
},
"background-color": "#50c9f6",
":focus": {
"background-color": "#48b5dd"
},
"border-radius": "4px",
"padding-left": "47px",
"padding-right": "47px"
},
"title": {
"color": "#555555"
},
"price": {
"color": "#555555"
},
"compareAt": {
"color": "#555555"
},
"quantityInput": {
"-moz-appearance": "textfield"
},
"close": {
"outline": "0"
},
"unitPrice": {
"color": "#555555"
},
"description": {
"color": "#555555"
}
},
"text": {
"button": "BUY NOW"
}
},
"cart": {
"styles": {
"button": {
"font-weight": "bold",
":hover": {
"background-color": "#48b5dd"
},
"background-color": "#50c9f6",
":focus": {
"background-color": "#48b5dd"
},
"border-radius": "4px"
}
},
"text": {
"total": "Subtotal",
"button": "Checkout"
}
},
"toggle": {
"styles": {
"toggle": {
"font-weight": "bold",
"background-color": "#50c9f6",
":hover": {
"background-color": "#48b5dd"
},
":focus": {
"background-color": "#48b5dd"
}
}
}
}
},
});
});

好的,那么在检查脚本代码并进行一些研究之后,这里是根据您的需要修改行为的代码,您需要修改之前的beforeInit

"events": {
beforeInit: function (product) {
Object.defineProperty(product, "isButton", {
get: function () {
return true;
}
});
Object.defineProperty(product, "options", {
get: function () {
return this.config[this.typeKey];
}
});
var actualOnButtonClick = product.onButtonClick;
product.onButtonClick = function (event, target) {
event.stopImmediatePropagation();
this.options.buttonDestination = "modal";
actualOnButtonClick.call(this, event, target);
};
}
},

相关内容

  • 没有找到相关文章