Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 无法将产品添加到购物车错误prestashop AJAX_Json_Ajax_Prestashop_Prestashop 1.5 - Fatal编程技术网

Json 无法将产品添加到购物车错误prestashop AJAX

Json 无法将产品添加到购物车错误prestashop AJAX,json,ajax,prestashop,prestashop-1.5,Json,Ajax,Prestashop,Prestashop 1.5,我的网站在本周初之前一直运行良好,每当客户尝试添加产品时,都会出现此错误 无法将产品添加到购物车 textStatus:'parsererror' ErrorRown:'SyntaxError:JSON.parse:JSON数据第1行第3列的JSON数据后出现意外的非空白字符' 答复正文: 45b { “产品”:[…]0 但是如果我将其替换为www.domain.com.au,AJAX不会抛出任何错误 我这里几乎没有什么猜测,但我没有解决办法; 我能想到的是,我需要删除空白,但我不知道在哪里。我

我的网站在本周初之前一直运行良好,每当客户尝试添加产品时,都会出现此错误

无法将产品添加到购物车

textStatus:'parsererror'

ErrorRown:'SyntaxError:JSON.parse:JSON数据第1行第3列的JSON数据后出现意外的非空白字符'

答复正文:

45b

{ “产品”:[…]0

但是如果我将其替换为www.domain.com.au,AJAX不会抛出任何错误

我这里几乎没有什么猜测,但我没有解决办法; 我能想到的是,我需要删除空白,但我不知道在哪里。我放在我的blockcart.php中的代码导致了它

全球$smarty

$smarty->assign('customerDefaultGroup',Customer::getDefaultGroupId(Context::getContext()->Customer->id))

但我试着把这些注释掉,它仍然让我犯错误。 所以现在,我禁用了AJAX,但客户开始抱怨,他们每次添加产品时都会被引导到购物车

我不知道这是否有关联,每次我访问网站时,我的标题上都有随机字符

帮助

按照我的ajax-cart.js添加函数

// add a product in the cart via ajax
    add : function(idProduct, idCombination, addedFromProductPage, callerElement, quantity, whishlist){
        if (addedFromProductPage && !checkCustomizations())
        {
            alert(fieldRequired);
            return ;
        }
        emptyCustomizations();
        //disabled the button when adding to not double add if user double click
        if (addedFromProductPage)
        {
            $('#add_to_cart input').attr('disabled', true).removeClass('exclusive').addClass('exclusive_disabled');
            $('.filled').removeClass('filled');
        }
        else
            $(callerElement).attr('disabled', true);

        if ($('#cart_block_list').hasClass('collapsed'))
            this.expand();
        //send the ajax request to the server
        $.ajax({
            type: 'POST',
            headers: { "cache-control": "no-cache" },
            url: baseUri + '?rand=' + new Date().getTime(),
            async: true,
            cache: false,
            dataType : "json",
            data: 'controller=cart&add=1&ajax=true&qty=' + ((quantity && quantity != null) ? quantity : '1') + '&id_product=' + idProduct + '&token=' + static_token + ( (parseInt(idCombination) && idCombination != null) ? '&ipa=' + parseInt(idCombination): ''),

            success: function(jsonData,textStatus,jqXHR)
            {
                // add appliance to whishlist module
                if (whishlist && !jsonData.errors)
                    WishlistAddProductCart(whishlist[0], idProduct, idCombination, whishlist[1]);

                // add the picture to the cart
                var $element = $(callerElement).parent().parent().find('a.product_image img,a.product_img_link img');
                if (!$element.length)
                    $element = $('#bigpic');
                var $picture = $element.clone();
                var pictureOffsetOriginal = $element.offset();

                if ($picture.size())
                    $picture.css({'position': 'absolute', 'top': pictureOffsetOriginal.top, 'left': pictureOffsetOriginal.left});

                var pictureOffset = $picture.offset();
                if ($('#cart_block')[0] && $('#cart_block').offset().top && $('#cart_block').offset().left)
                    var cartBlockOffset = $('#cart_block').offset();
                else
                    var cartBlockOffset = $('#shopping_cart').offset();

                // Check if the block cart is activated for the animation
                if (cartBlockOffset != undefined && $picture.size())
                {
                    $picture.appendTo('body');
                    $picture.css({ 'position': 'absolute', 'top': $picture.css('top'), 'left': $picture.css('left'), 'z-index': 4242 })
                    .animate({ 'width': $element.attr('width')*0.66, 'height': $element.attr('height')*0.66, 'opacity': 0.2, 'top': cartBlockOffset.top + 30, 'left': cartBlockOffset.left + 15 }, 1000)
                    .fadeOut(100, function() {
                        ajaxCart.updateCartInformation(jsonData, addedFromProductPage);
                    });
                }
                else
                    ajaxCart.updateCartInformation(jsonData, addedFromProductPage);
            },
            error: function(XMLHttpRequest, textStatus, errorThrown)
            {
                document.write("Impossible to add the product to the cart.\n\ntextStatus: '" + textStatus + "'\nerrorThrown: '" + errorThrown + "'\nresponseText:\n" + XMLHttpRequest.responseText);
                //reactive the button when adding has finished
                if (addedFromProductPage)
                    $('#add_to_cart input').removeAttr('disabled').addClass('exclusive').removeClass('exclusive_disabled');
                else
                    $(callerElement).removeAttr('disabled');
            }
        });
    },
我的ajax-cart.js自定义以检查最小数量

var href = $(this).attr('href').split('=');
            if(typeof href[4] === "undefined")
            { qty = href[3];} //array position changed to 3 after URL rewrite enabled.
            else{ qty = href[4];}
我的blockcart-jsan.tpl代码

{ldelim}
"products": [
{if $products}
{foreach from=$products item=product name='products'}
{assign var='productId' value=$product.id_product}
{assign var='productAttributeId' value=$product.id_product_attribute}
    {ldelim}
        "id":            {$product.id_product},
        "link":          "{$link->getProductLink($product.id_product, $product.link_rewrite, $product.category, null, null, $product.id_shop, $product.id_product_attribute)|addslashes|replace:'\\\'':'\''}",
        "quantity":      {$product.cart_quantity},
        "priceByLine":   "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
        "name":          "{$product.name|html_entity_decode:2:'UTF-8'|escape:'htmlall'|truncate:15:'...':true}",
        "price":         "{if $priceDisplay == $smarty.const.PS_TAX_EXC}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total}{else}{displayWtPrice|html_entity_decode:2:'UTF-8' p=$product.total_wt}{/if}",
        "price_float":   "{$product.total}",
        "idCombination": {if isset($product.attributes_small)}{$productAttributeId}{else}0{/if},
        "idAddressDelivery": {if isset($product.id_address_delivery)}{$product.id_address_delivery}{else}0{/if},
        "is_gift" : {if isset($product.is_gift) && $product.is_gift}1{else}0{/if},
{if isset($product.attributes_small)}
        "hasAttributes": true,
        "attributes":    "{$product.attributes_small|addslashes|replace:'\\\'':'\''}",
{else}
        "hasAttributes": false,
{/if}
        "hasCustomizedDatas": {if isset($customizedDatas.$productId.$productAttributeId)}true{else}false{/if},
        "customizedDatas":[
        {if isset($customizedDatas.$productId.$productAttributeId[$product.id_address_delivery])}
        {foreach from=$customizedDatas.$productId.$productAttributeId[$product.id_address_delivery] key='id_customization' item='customization' name='customizedDatas'}{ldelim}
{* This empty line was made in purpose (product addition debug), please leave it here *}
            "customizationId":  {$id_customization},
            "quantity":         "{$customization.quantity}",
            "datas": [
                {foreach from=$customization.datas key='type' item='datas' name='customization'}
                {ldelim}
                    "type": "{$type}",
                    "datas":
                    [
                    {foreach from=$datas key='index' item='data' name='datas'}
                        {ldelim}
                        "index":            {$index},
                        "value":            "{$data.value|addslashes|replace: '\\\'':'\''}",
                        "truncatedValue":   "{$data.value|truncate:28:'...'|addslashes|replace: '\\\'':'\''}"
                        {rdelim}{if !$smarty.foreach.datas.last},{/if}
                    {/foreach}]
                {rdelim}{if !$smarty.foreach.customization.last},{/if}
                {/foreach}
            ]
        {rdelim}{if !$smarty.foreach.customizedDatas.last},{/if}
        {/foreach}
        {/if}
        ]
    {rdelim}{if !$smarty.foreach.products.last},{/if}
{/foreach}{/if}
],
"discounts": [
{if $discounts}{foreach from=$discounts item=discount name='discounts'}
    {ldelim}
        "id":              "{$discount.id_discount}",
        "name":            "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}",
        "description":     "{$discount.description|addslashes|replace:'\\\'':'\''}",
        "nameDescription": "{$discount.name|cat:' : '|cat:$discount.description|truncate:18:'...'|addslashes|replace:'\\\'':'\''}",
        "code":            "{$discount.code}",
        "link":            "{$link->getPageLink("$order_process", true, NULL, "deleteDiscount={$discount.id_discount}")}",
        "price":           "{if $priceDisplay == 1}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_tax_exc}{else}{convertPrice|html_entity_decode:2:'UTF-8' price=$discount.value_real}{/if}",
        "price_float":     "{if $priceDisplay == 1}{$discount.value_tax_exc}{else}{$discount.value_real}{/if}"
    {rdelim}
    {if !$smarty.foreach.discounts.last},{/if}
{/foreach}{/if}
],
"shippingCost": "{$shipping_cost|html_entity_decode:2:'UTF-8'}",
"shippingCostFloat": "{$shipping_cost_float|html_entity_decode:2:'UTF-8'}",
{if isset($tax_cost)}
"taxCost": "{$tax_cost|html_entity_decode:2:'UTF-8'}",
{/if}
"wrappingCost": "{$wrapping_cost|html_entity_decode:2:'UTF-8'}",
"nbTotalProducts": "{$nb_total_products}",
"total": "{$total|html_entity_decode:2:'UTF-8'}",
"productTotal": "{$product_total|html_entity_decode:2:'UTF-8'}",
{if isset($errors) && $errors}
"hasError" : true,
"errors" : [
{foreach from=$errors key=k item=error name='errors'}
    "{$error|addslashes|html_entity_decode:2:'UTF-8'}"
    {if !$smarty.foreach.errors.last},{/if}
{/foreach}
]
{else}
"hasError" : false
{/if}
{rdelim}

请提供指向您网站的链接。如果您不希望它在robot上清晰显示,请按如下方式发布:“www----我的---网站-----com”。如果我能在您的标题中看到这些额外字符,我可能会有一个解决方案。>{“产品”:[…}0看起来您有额外的零(0)在json数据之后,您确定没有忘记注释/删除类似于
echo Customer::getDefaultGroupId()的内容吗
或例如,在template
customerDefaultGroup
@FlorianLeMatre网站是www--.--kdtrading--.--com.au您需要强制刷新以生成随机数。谢谢!@SergiiP您可能会去某个地方,我记得我在回显customerDefaultGroup之前做了测试,但我只是检查了我的代码,没问题。如果(!isset($groups[0])$groups=FALSE;$smarty->assign($customerGroups',$groups);$defaultGroupId=Customer::getDefaultGroupId((int)$id\u Customer);$customerDefaultGroup=new Group($defaultGroupId);$smarty->assign($customerdefaultgroupgroup',$customerdefaultgroupgroup)}我刚刚意识到Firefox和Chrome抛出的错误是不同的。在Chrome中,无法将产品添加到购物车中。textStatus:“parsererror”errorhorn:“SyntaxError:“意外令牌c”responseText:9ce不过,responseText并不总是相同的。它将抛出此随机数字和字符,字母表将作为“意外标记”拾取。请提供指向您网站的链接。如果您不希望它在robot上清晰显示,请按如下方式发布:“www----我的---site----com”。如果我能在标题中看到这些额外的字符,我可能会有一个解决方案。>{“产品”:[…}0看起来json数据后面有一个附加零(0),您确定没有忘记注释/删除类似于
echo Customer::getDefaultGroupId()的内容吗
或例如,在template
customerDefaultGroup
@FlorianLeMatre网站是www--.--kdtrading--.--com.au您需要强制刷新以生成随机数。谢谢!@SergiiP您可能会去某个地方,我记得我在回显customerDefaultGroup之前做了测试,但我只是检查了我的代码,没问题。如果(!isset($groups[0])$groups=FALSE;$smarty->assign($customerGroups',$groups);$defaultGroupId=Customer::getDefaultGroupId((int)$id\u Customer);$customerDefaultGroup=new Group($defaultGroupId);$smarty->assign($customerdefaultgroupgroup',$customerdefaultgroupgroup)}我刚刚意识到Firefox和Chrome抛出的错误是不同的。在Chrome中,无法将产品添加到购物车中。textStatus:“parsererror”errorhorn:“SyntaxError:“意外令牌c”responseText:9ce不过,responseText并不总是相同的。它会抛出这些随机数字和字符,字母表将作为“意外标记”被拾取