簡體   English   中英

根據用戶添加到購物車的數量,為每個包含特定數量的產品添加數量字段

[英]Add quantity field with each product which contain particular quatity as per user added product into the cart

我在“添加到購物車”按鈕附近添加了一個數量框,用於添加到購物車中的特定產品。 最初為零。 當用戶/客戶將產品添加到購物車時,其尺寸應增加一個。

文件template/module/feature.tpl

<button class="product-btn-add" type="button" onclick="cart.minus('<?php echo $product['product_id']; ?>');pq_minus( $(this).parent() );">
    <span class="hidden-sm">-</span>
</button>
<input class="product-quantity-input" type="text"  text-align="center" value="0" size="1" readonly="true">
<button class="product-btn-add" type="button" onclick="cart.add('<?php echo $product['product_id']; ?>');pq_plus( $(this).parent() ); ">
    <span class="hidden-sm">+</span>
</button>

common.js

function pq_setQuantity( $input, add ) {
    var val = pq_getQuantity( $input );
    val += 1 * ( add ? 1 : -1 );
    if( val < 1 )
        val = 0;
    input.attr('value', val.toString()).val( val.toString() );
}               

function pq_getQuantity( $input ) { 
    var val = parseInt( $input.val() );
    if( typeof val == 'NaN' || val < 1 )
        val = 0;
    return val;
}

function pq_plus( $item ) {
    pq_setQuantity( $item.find('.product-quantity-input'), true );
}

function pq_minus( $item ) {
    pq_setQuantity( $item.find('.product-quantity-input'), false );
}

當我刷新頁面時,數量文本輸入框變為零

在此處輸入圖片說明 我在刷新之前和之后添加了兩張圖片 在此處輸入圖片說明

您可以從購物車類system/library/cart.php獲取購物車信息

嘗試print_r($this->cart->getProducts());

在這里,您可以找到product_id和相關的購物車added quantity 現在,您可以將關聯的添加數量傳遞到視圖文件表單控制器。

祝好運

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM