PowerShell から WooCommerce に簡単に接続する方法をお探しですか? CData ADO.NET Provider for WooCommerce は、PowerShell スクリプトの優位性を使い、シンプルで簡単に使えるADO.NET インターフェース を提供します。PowerShell スクリプトで、ADO.NET オブジェクトを使って簡単にWooCommerce に接続して、同期、自動化、ダウンロードなどが可能!
CData ADO.NET Provider for WooCommerce は、ADO.NET 標準インターフェースへ統合し、PowerShell のような. NET アプリケーションからWooCommerce API へのデータ連携を可能にします。このプロバイダーは、WooCommerce の認証および相互作用を簡単にします。このチュートリアルでは、PowerShell から直接SQL クエリを実行するための、いくつかの一般的なADO.NET オブジェクトの使い方を説明します。
クエリの実行
次の3つのステップに従って create、read、update、およびdelete (CRUD) のデータ連携コマンドを PowerShell からリアルタイムWooCommerce に実行:
-
プロバイダーのアセンブリをロード:
[Reflection.Assembly]::LoadFile("C:\Program Files\CData\CData ADO.NET Provider for WooCommerce\lib\System.Data.CData.WooCommerce.dll")
-
WooCommerce に接続:
WooCommerce supports the following authentication methods: one-legged OAuth1.0 Authentication and standard OAuth2.0 Authentication.
Connecting using one-legged OAuth 1.0 Authentication
Specify the following properties (NOTE: the below credentials are generated from WooCommerce settings page and should not be confused with the credentials generated by using WordPress OAuth2.0 plugin):
- ConsumerKey
- ConsumerSecret
Connecting using WordPress OAuth 2.0 Authentication
$constr = "Url=https://example.com/; ConsumerKey=ck_ec52c76185c088ecaa3145287c8acba55a6f59ad; ConsumerSecret=cs_9fde14bf57126156701a7563fc87575713c355e5; " $conn= New-Object System.Data.CData.WooCommerce.WooCommerceConnection($constr) $conn.Open()
-
WooCommerceDataAdapter のインスタンスを生成してSQL クエリを実行し、結果を出力:
$sql="SELECT ParentId, Total from Orders" $da= New-Object System.Data.CData.WooCommerce.WooCommerceDataAdapter($sql, $conn) $dt= New-Object System.Data.DataTable $da.Fill($dt) $dt.Rows | foreach { Write-Host $_.parentid $_.total }
WooCommerce データの更新
$cmd = New-Object System.Data.CData.WooCommerceCommand("UPDATE Orders SET ParentId='3' WHERE Id = @myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.WooCommerceParameter("myId","10456255-0015501366"))
$cmd.ExecuteNonQuery()
WooCommerce へのデータの挿入
$cmd = New-Object System.Data.CData.WooCommerceCommand("UPDATE Orders SET ParentId='3' WHERE Id = @myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.WooCommerceParameter("myId","10456255-0015501366"))
$cmd.ExecuteNonQuery()
WooCommerce データの削除
$cmd = New-Object System.Data.CData.WooCommerceCommand("UPDATE Orders SET ParentId='3' WHERE Id = @myId", $conn)
$cmd.Parameters.Add(new System.Data.CData.WooCommerceParameter("myId","10456255-0015501366"))
$cmd.ExecuteNonQuery()
CodeProject