如何解决添加产品后,如何在不刷新购物车页面的情况下自动查看更新的购物车?
我尝试了几种方法,但是每次成功将产品添加到购物车中,但购物车本身都没有更新时,我现在已经三天了才能完成此任务,请记住我对此是完全陌生的,并且我已经对更改的方法和某种代码进行了大量研究,但是我对如何实现这一点完全迷失了。我正在使用Shopify,唯一要实现的是添加新产品时产品购物车会更新,它确实可以处理数量(当您在购物车页面上并简单地更改数量时,然后自动更新而不刷新)
如果您缺少一些代码,请直接说出来,以便我轻松更新。
我尝试过的代码:
theme.UpdateRefresh = (function() {
var refresh = document.getElementsByClassName('.product-form .product-form-product-template');
var test = ('[data-product-form]');
$('btn product-form__cart-submit').click(function() {
location.reload();
});
function update()
{
url: '/cart/add'
dataType: 'json'
}
return { update:update}
}) ();
_addItemToCart(theme.js)
_addItemToCart: function(data) {
var params = {
url: '/cart/add.js',data: $(data).serialize(),dataType: 'json'
};
$.post(params)
.done(
function(item) {
this._hideErrorMessage();
this._setupCartPopup(item); //cartpop met additem
this.theme.UpdateRefresh.update();
}.bind(this)
)
.fail(
function(response) {
this.$previouslyFocusedElement.focus();
var errorMessage = response.responseJSON
? response.responseJSON.description
: theme.strings.cartError;
this._showErrorMessage(errorMessage);
this._handleButtonLoadingState(false);
}.bind(this)
);
},
Shopify(product-template.liquid)
<div class="product-form__controls-group product-form__controls-group--submit">
<div class="product-form__item product-form__item--submit
{%- if section.settings.enable_payment_button %} product-form__item--payment-button {%- endif -%}
{%- if product.has_only_default_variant %} product-form__item--no-variants {%- endif -%}">
<button type="submit" name="add"
{% unless current_variant.available %} aria-disabled="true"{% endunless %}
aria-label="{% unless current_variant.available %}{{ 'products.product.sold_out' | t }}{% else %}{{ 'products.product.add_to_cart' | t }}{% endunless %}"
class="btn product-form__cart-submit{% if section.settings.enable_payment_button %} btn--secondary-accent{% endif %}"
data-add-to-cart>
<span data-add-to-cart-text>
{% unless current_variant.available %}
{{ 'products.product.sold_out' | t }}
{% else %}
{{ 'products.product.add_to_cart' | t }}
{% endunless %}
</span>
</button>
</div>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。