簡體   English   中英

如何使用 php 將 Mailchimp API 3.0 的“購物車”和“購物車行”添加到自定義商店?

[英]How to add “cart” and “cart lines” of Mailchimp API 3.0 to custom store using php?

我們正在將 Mailchimp API 3(電子商務)集成到自定義商店,並且在執行“購物車”和“購物車行”時遇到了一些問題。

  1. 使用 php 在 Mailchimp 上添加購物車的正確方法是什么? 我想我缺少一些身體參數。
  2. 另外,為什么 Mailchimp 在添加購物車(使用 addStoreCart 函數)時需要“購物車行”(購物車行項目的數組)並在創建購物車行時需要 cart_id(使用 addCartLineItem 函數)?

這是我到目前為止所做的。 我正在使用composer require mailchimp/marketing package 將我的自定義應用程序連接到 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/

該錯誤在 postman 上並不特別

[客戶錯誤-POST https://US17.api.MAILCOM.MAILCHIMP.COM/3.0/ecommerce/commerce/stores/25/2/11/11/11/11/11/400 Z.400 Z.400 Z.400 Z.400 Z.400] 400.400 Z. .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",
        "product_variant_id" => "1",
        "quantity" => 1,
        "price" => 640,
    ],
],
"tax_total" => "0",

]);

暫無
暫無

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

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