<p>Your error is in this bit:</p>
<pre class="lang-php prettyprint-override"><code>        // @var LineItem $lineItem
        $lineItem = $event-&gt;lineItem;
</code></pre>
<p>Looking at the event in question:</p>
<p><a href="https://craftcms.com/docs/commerce/3.x/events.html#beforecapturetransaction" rel="nofollow noreferrer">https://craftcms.com/docs/commerce/3.x/events.html#beforecapturetransaction</a></p>
<p>...this shows that you get a <code>Transaction</code> model supplied in this event:</p>
<p><a href="https://docs.craftcms.com/commerce/api/v3/craft-commerce-models-transaction.html#public-properties" rel="nofollow noreferrer">https://docs.craftcms.com/commerce/api/v3/craft-commerce-models-transaction.html#public-properties</a></p>
<p>...note that model gives you direct access to the related <code>order</code> element:</p>
<p><a href="https://docs.craftcms.com/commerce/api/v3/craft-commerce-elements-order.html" rel="nofollow noreferrer">https://docs.craftcms.com/commerce/api/v3/craft-commerce-elements-order.html</a></p>
<p>...from which you can then retrieve all the line items (and products etc associated with them), by looping over <code>order.lineItems</code></p>

CC BY-SA 4.0
2020-10-29T21:40:47.807Z
2020-10-30T22:49:17.197Z
2020-10-30T22:49:17.197Z
Jeremy Daalder
<p>I'm looking to fetch all line items and send it as a POST request to an endpoint. I've had a look through the class references but can't seem to find a way to get all the line items that are currently active.</p>
<pre><code>Event::on(
  Payments::class,
  Payments::EVENT_BEFORE_CAPTURE_TRANSACTION,
  function(TransactionEvent $event) {

        $transaction = $event-&gt;transaction;
        // @var LineItem $lineItem
        $lineItem = $event-&gt;lineItem;

        $client = new \Guzzle\Http\Client([
            // You can set any number of default request options.
            'Authorization'  =&gt; 'qdaiciDiyMaTjxMt, 74026b3dc2c6db6a30a73e71cdb138b1e1b5eb7a97ced46689e2d28db1050875',
        ]);


        // Add Cart Data to an Array
        $order_data = array(
            'product_id' =&gt; $lineItem-&gt;id,
            'quantity' =&gt; $lineItem-&gt;quantity
        );
...
</code></pre>

<plugin-craftcommerce>
Get All Line Items Checkout Event
# Get All Line Items Checkout Event

(Asked by: username_0 on 2020-10-29)

I'm looking to fetch all line items and send it as a POST request to an endpoint. I've had a look through the class references but can't seem to find a way to get all the line items that are currently active.
Event::on(
  Payments::class,
  Payments::EVENT_BEFORE_CAPTURE_TRANSACTION,
  function(TransactionEvent $event) {

        $transaction = $event->transaction;
        // @var LineItem $lineItem
        $lineItem = $event->lineItem;

        $client = new \Guzzle\Http\Client([
            // You can set any number of default request options.
            'Authorization'  => 'qdaiciDiyMaTjxMt, 74026b3dc2c6db6a30a73e71cdb138b1e1b5eb7a97ced46689e2d28db1050875',
        ]);


        // Add Cart Data to an Array
        $order_data = array(
            'product_id' => $lineItem->id,
            'quantity' => $lineItem->quantity
        );
...

**Tags:** plugin-craftcommerce


---

## 1 answers

### Answer by username_1 on 2020-10-29. Score: 2 | Accepted answer

Your error is in this bit:
        // @var LineItem $lineItem
        $lineItem = $event->lineItem;

Looking at the event in question:
https://craftcms.com/docs/commerce/3.x/events.html#beforecapturetransaction
...this shows that you get a Transaction model supplied in this event:
https://docs.craftcms.com/commerce/api/v3/craft-commerce-models-transaction.html#public-properties
...note that model gives you direct access to the related order element:
https://docs.craftcms.com/commerce/api/v3/craft-commerce-elements-order.html
...from which you can then retrieve all the line items (and products etc associated with them), by looping over order.lineItems


---

