Opencart add product options to opencart

前端 未结 1 1326
没有蜡笔的小新
没有蜡笔的小新 2021-01-24 12:06

My cart appears to be working except the product options. When I click add cart button then the item gets added, but no options are added with it. I really don\'t understand why

1条回答
  •  情歌与酒
    2021-01-24 12:38

    First Option($key=>value) where you have passed $key => 13 which should be valid key

    in array of Option($key=>$Value) where $key represents product_option_id and $value represents Product_option_value_id of product_option_value table so these should be valid which is assigned dynamically when you assign option to product rather than static id.

    **Second** Just use the default method of opencart, this will handle other input type as well

    $('#button-cart').bind('click', function() {
        $.ajax({
            url: 'index.php?route=checkout/cart/add',
            type: 'post',
            data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea'),
            dataType: 'json',
            success: function(json) {
                $('.success, .warning, .attention, information, .error').remove();
    
                if (json['error']) {
                    if (json['error']['option']) {
                        for (i in json['error']['option']) {
                            $('#option-' + i).after('' + json['error']['option'][i] + '');
                        }
                    }
    
                    if (json['error']['profile']) {
                        $('select[name="profile_id"]').after('' + json['error']['profile'] + '');
                    }
                } 
    
                if (json['success']) {
                    $('#notification').html('');
    
                    $('.success').fadeIn('slow');
    
                    $('#cart-total').html(json['total']);
    
                    $('html, body').animate({ scrollTop: 0 }, 'slow'); 
                }   
            }
        });
    });
    

    0 讨论(0)
提交回复
热议问题