Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/app/code/Zendesk/Zendesk/Helper/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Zendesk/Zendesk/Helper/AllCustomerOrders.php
<?php
/**
 * @category    ClassyLlama
 * @copyright   Copyright (c) 2020 Classy Llama Studios, LLC
 */

namespace Zendesk\Zendesk\Helper;

use Magento\Framework\App\Helper\Context;
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;

class AllCustomerOrders extends \Magento\Framework\App\Helper\AbstractHelper
{
    /**
     * @var CollectionFactory
     */
    protected $orderCollectionFactory;

    /**
     * AllCustomerOrders constructor.
     * @param Context $context
     * @param CollectionFactory $orderCollectionFactory
     */
    public function __construct(
        Context $context,
        CollectionFactory $orderCollectionFactory
    ) {
        $this->orderCollectionFactory = $orderCollectionFactory;
        parent::__construct($context);
    }

    /**
     * Get all orders for a specific customer ID
     * @param $customerId
     * @return array
     */
    public function getOrderCollection($customerId)
    {
        $customerOrder = $this->orderCollectionFactory->create()
            ->addFieldToFilter('customer_id', $customerId);
        return $customerOrder->getData();
    }

    /**
     * @param $id
     * @return int|void
     */
    public function getTotalNumberOrders($id)
    {
        $orders = $this->getOrderCollection($id);
        return count($orders);
    }

    /**
     * @param $id
     * @return string
     */
    public function getTotalSpent($id)
    {
        $orders = $this->getOrderCollection($id);
        $totalPrice = 0;
        foreach ($orders as $order) {
            $totalPrice += $order['total_paid'] ?? $order['grand_total'];
        }

        return(number_format($totalPrice, 2, '.', ','));
    }
}

Spamworldpro Mini