<p>I'm pretty sure this issue is caused because the model is being passed to the event without being populated first (it only has the EXACT details that are manually populated when the record is created, not the additional functions). </p>

<p>I was able to use <code>$chargeModel-&gt;planAmount</code> just fine, and I was actually able to re-look up the model based on the passed model id, which properly populated the model before passing it back.</p>

CC BY-SA 3.0
2017-12-12T22:10:59.960Z
2017-12-12T22:10:59.960Z
Natalie
<p>I'm using the onCharge event to populate a separate purchases table that I can query elsewhere (combining both stripe and my other Paypal payments system). </p>

<p>The onCharge event is mostly working, but it's not populating the $chargeModel->amount. </p>

<p>It's also not populating the $chargeModel->userId if a new user is being registered (it only populates if there was a previously existing user). </p>

<p>Any idea why the charge model wouldn't have all of its information during the onCharge event? </p>

<p>Here's what I have in my plugin: </p>

<pre><code>craft()-&gt;on('charge.onCharge', function(Event $event) {    
    // Adding New Charges to Purchases Table
    craft()-&gt;purchases_newPurchase-&gt;addChargePurchase($event-&gt;params['charge']);
});
</code></pre>

<events><plugin-charge>
Charge Model "amount" and "userId" not always populated
# Charge Model "amount" and "userId" not always populated

(Asked by: username_0 on 2017-12-11)

I'm using the onCharge event to populate a separate purchases table that I can query elsewhere (combining both stripe and my other Paypal payments system). 
The onCharge event is mostly working, but it's not populating the $chargeModel->amount. 
It's also not populating the $chargeModel->userId if a new user is being registered (it only populates if there was a previously existing user). 
Any idea why the charge model wouldn't have all of its information during the onCharge event? 
Here's what I have in my plugin: 
craft()->on('charge.onCharge', function(Event $event) {    
    // Adding New Charges to Purchases Table
    craft()->purchases_newPurchase->addChargePurchase($event->params['charge']);
});

**Tags:** events, plugin-charge


---

## 1 answers

### Answer by username_0 on 2017-12-12. Score: 2

I'm pretty sure this issue is caused because the model is being passed to the event without being populated first (it only has the EXACT details that are manually populated when the record is created, not the additional functions).

I was able to use `$chargeModel->planAmount` just fine, and I was actually able to re-look up the model based on the passed model id, which properly populated the model before passing it back.


---

