2017-07-10 18 views
0

に存在しないポップアップ:私は以下のコードを使用していますカートに製品を追加すると、製品がカート

addproduct(itemId) { 
       this.showLoading = true 
       this.$http.post('/shampoo', {'item': itemId}).then((response) => { 
        swal({ 
         title: "Success!", 
         text: "Product added to your basket!", 
         type: "success", 
         timer: 1500, 
         showConfirmButton: false 
        }) 
        this.showLoading = false 
       }, (response) => { 


        this.showLoading = false 
       }) 

ノー製品のために、彼ら後、カートにあったポップアップフォームを作成しました買い物カゴに追加ボタンをクリックすると、商品がカートに置かれた後、別の商品を追加してポップアップを表示する必要がある場合はポップアップ表示されます。商品がカートに入っていればポップアップが欲しくない。

ここにポップアップフォームのコードがあります。 show(){ this.showLoading = true;あなたがカートに追加]をクリックすると

  $(".loading").css('display', 'block'); 
      $('#products').modal("hide"); 

      // 
      let code = $('input[name=code]').val(); 

      if(code) { 
       this.$http.post('/codee', { code: code}).then((response) => { 
        // $('#basic-form').submit(); 
      }, (response) => { 
        swal({ 
         title: "Error!", 
         text: "Sorry this Code is invalid!", 
         type: "error", 
         timer: 2500, 
         showConfirmButton: false 
        }) 

        $(".loading").css('display', 'none'); 

        this.showLoading = false 
        $('input[name=code]').val('') 
       }) 

答えて

0

、サーバー側では、アイテムが猫やないことを示す項目IDがカートにあるかどうかを確認し、いずれかにフラグを返却する必要があります。私はこのコードがポップアップを担当していると仮定します。

swal({ 
title: "Error!", 
text: "Sorry this Code is invalid!", 
type: "error", 
timer: 2500, 
showConfirmButton: false 
}) 

サーバーから返された値をチェックする必要があります。アイテムが既に存在することを示すフラグが返された場合はfalseを返します。それはポップアップコードに達するのをブロックするでしょう。 if文にポップコードをラップすることもできます。例:

if(response.flag === 1){ 
    return false; 
    // your pop up code goes here 
} 

or 

if(response.flag === 0){ 
    // your pop up code goes here 
} 

// flag can assume 0 => Added but does not exist, 1=> added but already 
// exist. ect 
// while the actual data will be stored in response.data 

しかし、私はあなたがこれを実装している理由が不思議です。ユーザーがカートに追加をクリックすると、カートに既に存在する場合は同じアイテムの数を増やすことになっています