0

友人、私は e コマース Web サイトを開発しています (Codeigniter を使用)。

お客様が商品の数量を入力して「購入する」をクリックすると、「数量」フィールドの商品のみがカートに入れられます。手伝って頂けますか?

HTML:

<form>
<ul class="products-list">
    <li class="product">
        <input type="hidden" class="product_id" value="1">
        <span class="product-name">Product 1</span>
        <span class="product-value">$ 100</span> 
        <span>Qnt. <input type="text" class="quantity"></span> 
    </li>
        <li class="product">
        <input type="hidden" class="product_id" value="2">
        <span class="product-name">Product 2</span>
        <span class="product-value">$ 100</span> 
        <span>Qnt. <input type="text" class="quantity"></span> 
    </li>
</ul>
<button>Buy</button>
</form>


jQuery:

$.ajax({
    url: '/cart/add/'+product_id+'/'+quantity,
    type: 'GET',
    success: function( data ){
        if ( data != false ) {
            window.location.reload();
        }
    }
});


私のPHPコード:

public function addItem( $product_id, $quantity){ 
    $product = $this->Produto_model->getById($product_id); 
    $this->carrinho->setItem($product, $quantity); 
    echo json_encode($this->carrinho); 
}  
4

1 に答える 1