0

I need to merge the guest cart items into customer active cart using end point API but as per my code its throwing the following error.

Array
(
    [message] => Cannot assign customer to the given cart. Customer already has active cart.
)

I am explaining my code below.

$adminUrl1='http://example.com/index.php/rest/V1/integration/customer/token';
    $ch1 = curl_init();
    $data1 = array("username" => 'abc@gmail', "password" => 'Oditek123@');
    $data_string1 = json_encode($data1);                       
    $ch1 = curl_init($adminUrl1); 
    curl_setopt($ch1, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
    curl_setopt($ch1, CURLOPT_POSTFIELDS, $data_string1);                                                                  
    curl_setopt($ch1, CURLOPT_RETURNTRANSFER, true);                                                                      
    curl_setopt($ch1, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json',                                                                                
        'Content-Length: ' . strlen($data_string1))                                                                       
    );       
    $token1 = curl_exec($ch1);

$quoteUrl ='http://example.com/index.php/rest/V1/guest-carts/z5546670365f8d78882b03ea9b1f8e08';
    $data_string2=array("customerId"=>84,"storeId"=>1);
    $chQuote = curl_init($quoteUrl);
    curl_setopt($chQuote, CURLOPT_CUSTOMREQUEST, "PUT"); 
    curl_setopt($chQuote, CURLOPT_POSTFIELDS, json_encode($data_string2));
    curl_setopt($chQuote, CURLOPT_HTTPHEADER, array("Content-Type: application/json", "Authorization: Bearer " . json_decode($token1)));
    curl_setopt($chQuote, CURLOPT_RETURNTRANSFER, true);
    $array = json_decode(curl_exec($chQuote),TRUE);
    print_r($array);exit;

Here I need to transfer all guest cart items into customer active cart after customer login. Please help me to resolve this issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.