私は支払うためにストライプに送られる請求書を持っています。
thanks.htmlが表示されたら、請求書セクションの請求書支払いドロップダウン・フィールドをcharge.onChargeフックを使用して「いいえ」から「はい」に変更します。
私は成功しなかったので、次の(そしてバリエーション)を試しました。
{
craft()->on('charge.onCharge', function(Event $event) {
craft()->on('entries.onSaveEntry', function(Event $event ){
//Is the entry in the section 'invoices'?
if ($event->params['entry']->section == 'invoices') {
//Replace values
$event->params['entry']->getContent()->invoicePaid = 'Yes';
}
});
});
}
どこが間違っているのですか、これについてもっと良い方法がありますか?
現在の例では、実際にエントリを保存していません。 onSaveEntry
イベントリスナーを設定するだけです。エントリを保存するには、[saveEntry]
[1]メソッドを使用して実際にエントリを保存する必要があります。
アップデート:あなたの設定が何であるか正確にはわかりませんが、以下のバリエーションがあなたのために働くはずです。
-
In the CMS, add a field called ‘invoiceID’, which you will use
to store the invoice entryId to the charge (or ‘invoiceEntryId’ or
whatever you want to call it). -
Add the ‘invoiceId’ field to the charge field layout in
charge->settings->fields. -
In the charge form, add the ‘invoiceId’ field to your form (this
assumes that you are making the charge from the invoice entry page,
otherwise you will need to use a reference to the invoice entry id
through whatever relationship you have set up):<input type="hidden" name="fields[invoiceId]" value="{{ entry.id }}"/>
-
In your plugin, add the onCharge event to grab the ‘invoiceId’
from the charge event, then retrieve, update, and save the
entry.craft()->on('charge.onCharge', function(Event $event) { //get the charge model $charge = $event->params['charge']; //retrieve the invoiceId (aka entryId) saved on the charge model $entryId = $charge->invoiceId; //uncomment to test, if needed //LogicPlugin::log('Invoice ID: '.$charge->invoiceId, LogLevel::Info); //get the invoice entry from the invoiceId $entry = craft()->entries->getEntryById($entryId); //update the invoicePaid field (in this case I'm using a switch) $entry->getContent()->invoicePaid = '1'; //save the entry $success = craft()->entries->saveEntry($entry); //log errors if (!$success) { LogicPlugin::log('Couldn’t save the entry "'.$entry->title.'"', LogLevel::Error); } });