如何使用PHP将Mailchimp API 3.0的“购物车”和“购物车行”添加到自定义存储中?

问题描述

我们正在将Mailchimp API 3(电子商务)集成到自定义商店中,并且在进行“购物车”和“购物车线”方面存在一些问题。

  1. 使用PHP在Mailchimp上添加购物车的正确方法是什么?我想我缺少一些身体参数。
  2. 为什么,Mailchimp为什么在添加购物车时(使用addStoreCart函数)需要“购物车行”(购物车行项目的数组),而在创建购物车行时(使用addCartLineItem函数)需要cart_id?

这是我到目前为止所做的。我正在使用composer require mailchimp/marketing软件包将我的自定义应用程序连接到mailchimp。


namespace App\Http\Controllers\MailChimp;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use \MailchimpMarketing;

class CartController extends Controller
{
    public function store(Request $request)
    {

        $client = new MailchimpMarketing\apiclient();
        $client->setConfig([
            'apiKey' => env('MAILCHIMP_API_KEY'),'server' => env('MAILCHIMP_SERVER')
        ]);
        /*ADD CART TO STORE */
        $response = $client->ecommerce->addStoreCart(env('MAILCHIMP_STORE_ID'),[
            "id" => "1","currency_code" => "USD","order_total" => 0,"customer" => ["id" => "17"],"lines" => [[]],]);
        print_r($response);
    }
}

我们正在关注:https://mailchimp.com/developer/api/marketing/ecommerce-carts/

错误在邮递员上并不特殊

[客户端错误-POST https://us17.api.mailchimp.com/3.0/ecommerce/stores/2/carts导致400错误的请求...] [1] [1]:https://i.stack.imgur.com/RFL4n.png

谢谢!

解决方法

$response = $mailchimp->ecommerce->addStoreCart("store_id",[
"id" => "3","customer" => ["id" => "1"],"currency_code" => "USD","order_total" => 1247,"lines" => [
    [
        "id" => "1","product_id" => "10709","product_variant_id" => "1","quantity" => 1,"price" => 607,],[
        "id" => "2","product_id" => "10712","price" => 640,"tax_total" => "0",

]);