OrderGridUpdater.php 1.26 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Signifyd\Model\SalesOrderGrid;

use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Sales\Model\ResourceModel\GridInterface;

/**
 * Perfoms sales order grid updating operations.
 *
 * Serves order grid updates in both synchronous and asynchronous modes.
 */
class OrderGridUpdater
{
    /**
     * @var ScopeConfigInterface
     */
    private $globalConfig;

    /**
     * @var GridInterface
     */
    private $entityGrid;

    /**
     * @param GridInterface $entityGrid
     * @param ScopeConfigInterface $globalConfig
     */
    public function __construct(
        GridInterface $entityGrid,
        ScopeConfigInterface $globalConfig
    ) {
        $this->globalConfig = $globalConfig;
        $this->entityGrid = $entityGrid;
    }

    /**
     * Handles synchronous updating order entity in grid.
     *
     * Works only if asynchronous grid indexing is disabled
     * in global settings.
     *
     * @param int $orderId
     * @return void
     */
    public function update($orderId)
    {
        if (!$this->globalConfig->getValue('dev/grid/async_indexing')) {
            $this->entityGrid->refresh($orderId);
        }
    }
}