更新woocommerce应用中有关数量变化的购物车项目自定义数据

时间:2018-08-13 07:58:12

标签: php wordpress angular woocommerce ionic3

我正在使用woocommerce应用程序,并且使用woo-mstoreapp-mobile-app我已将名为“ line_donation”的自定义字段添加到各个购物车项目中。现在,我想在移动应用程序的购物车页面中将line_donation的总计显示为total_donation在产品合计上方。我不知道该怎么做。

 <ion-row>
                        <ion-col width-75>
                            <ion-label>{{"Total Donation" | translate}} </ion-label>
                        </ion-col>
                        <ion-col width-25 text-right>
                            <ion-label>{{total_donation | currency:values.currency:symbol:'1.2-2'}} </ion-label>
                        </ion-col>
                    </ion-row>

enter image description here 购物车

deleteFromCart(id, key) {
        this.service.deleteFromCart(id, key)
            .then((results) => this.handleCart(results));

    }
    addToCart(id, key) {
        this.service.addToCart(id, key)
            .then((results) => this.handleCart(results));
    }

    updateCart(results) {
        this.service.loadCart()
            .then((results) => this.handleCart(results));
    }

cart-service.ts

 addToCart(id, key) {

        this.presentLoading(this.values.lan.WaitTitle);

        var params = new URLSearchParams();
        if (this.values.cartItem[key].quantity != undefined && this.values.cartItem[key].quantity == 0) {
            this.values.cartItem[key].quantity = 0
        }
        else {
            this.values.cartItem[key].quantity += 1
        };
        if (this.values.cart[id] != undefined && this.values.cart[id] == 0) {
            this.values.cart[id] = 0
        }
        else {
            this.values.cart[id] += 1
        };

        this.global.total_donation=this.global.total_donation + this.values.cartItem[key].line_donation ; 

        params.set('cart[' + key + '][qty]', this.values.cartItem[key].quantity);
        params.set('_wpnonce', this.values.cartNonce);
        params.set('_wp_http_referer', this.config.url + '/wp-admin/admin-ajax.php?action=mstoreapp-cart');
        params.set('update_cart', 'Update Cart');
        return new Promise(resolve => {
            this.http.post(this.config.url + '/cart/', params, this.config.options).map(res => res.json())
                .subscribe(data => {
                   this.dismissLoading();
                    this.cart = data;
                    this.values.updateCart(this.cart);
                    resolve(this.cart);

                });

        });

      }

0 个答案:

没有答案