We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Collection.php 2.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
<?php
/**
 *                       ######
 *                       ######
 * ############    ####( ######  #####. ######  ############   ############
 * #############  #####( ######  #####. ######  #############  #############
 *        ######  #####( ######  #####. ######  #####  ######  #####  ######
 * ###### ######  #####( ######  #####. ######  #####  #####   #####  ######
 * ###### ######  #####( ######  #####. ######  #####          #####  ######
 * #############  #############  #############  #############  #####  ######
 *  ############   ############  #############   ############  #####  ######
 *                                      ######
 *                               #############
 *                               ############
 *
 * Adyen Payment module (https://www.adyen.com/)
 *
 * Copyright (c) 2015 Adyen BV (https://www.adyen.com/)
 * See LICENSE.txt for license details.
 *
 * Author: Adyen <magento@adyen.com>
 */

24
namespace Adyen\Payment\Model\ResourceModel\Order\Payment;
25 26 27 28 29 30 31 32 33 34 35 36 37

/**
 * Billing agreements resource collection
 */
class Collection extends \Magento\Framework\Model\ResourceModel\Db\Collection\AbstractCollection
{
    /**
     * Collection initialization
     *
     * @return void
     */
    protected function _construct()
    {
38
        $this->_init(\Adyen\Payment\Model\Order\Payment::class, \Adyen\Payment\Model\ResourceModel\Order\Payment::class);
39 40 41 42 43 44 45 46 47 48
    }

    /**
     * @param integer $paymentId
     * @return array
     */
    public function getTotalAmount($paymentId)
    {
        $connection = $this->getConnection();

49 50 51
        $sumCond = new \Zend_Db_Expr(
            "SUM(adyen_order_payment.{$connection->quoteIdentifier(\Adyen\Payment\Model\Order\Payment::AMOUNT)})"
        );
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84

        $select = $connection->select()->from(
            ['adyen_order_payment' => $this->getTable('adyen_order_payment')],
            ['total_amount' => $sumCond]
        )->where(
            'payment_id = :payment_id'
        );

        return $connection->fetchAll($select, [':payment_id' => $paymentId]);
    }

    /**
     * @param string $paymentId
     * @return $this
     */
    public function addPaymentFilterAscending($paymentId)
    {
        $this->addFieldToFilter('payment_id', $paymentId);
        $this->getSelect()->order(['created_at ASC']);
        return $this;
    }

    /**
     * @param string $paymentId
     * @return $this
     */
    public function addPaymentFilterDescending($paymentId)
    {
        $this->addFieldToFilter('payment_id', $paymentId);
        $this->getSelect()->order(['created_at DESC']);
        return $this;
    }
}