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/Kaliop/ProductGridSalesCount/Observer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/app/code/Kaliop/ProductGridSalesCount/Observer/CheckoutSuccess.php
<?php
/**
 * Copyright (c) 2020 Kaliop Digital Commerce (https://digitalcommerce.kaliop.com) All Rights Reserved.
 * https://opensource.org/licenses/OSL-3.0  Open Software License (OSL 3.0)
 * Cnc
 * Krzysztof Majkowski <[email protected]>
 */

namespace Kaliop\ProductGridSalesCount\Observer;

use Kaliop\ProductGridSalesCount\Model\Calculator;
use Magento\Framework\Event\ObserverInterface;
use Magento\Framework\Event\Observer;
use Magento\Sales\Model\Order;
use Magento\Sales\Model\OrderFactory;

class CheckoutSuccess implements ObserverInterface
{
    /**
     * @var Calculator
     */
    private $calculator;

    /**
     * @var OrderFactory
     */
    private $orderFactory;

    /**
     * SalesOrderPlaceAfter constructor.
     * @param Calculator $calculator
     * @param OrderFactory $orderFactory
     */
    public function __construct(
        Calculator $calculator,
        OrderFactory $orderFactory
    ) {
        $this->calculator = $calculator;
        $this->orderFactory = $orderFactory;
    }

    /**
     * Observer for sales_order_place_after
     *
     * @param Observer $observer
     * @return void
     */
    public function execute(Observer $observer)
    {
        $event = $observer->getEvent();
        /** @var Order $order */
        $order = $this->orderFactory->create();
        $order->getResource()->load($order, $observer->getData('order_ids')[0]);

        $productIds = [];
        foreach ($order->getAllItems() as $item) {
            $productIds []= $item->getProductId();
        }

        if (count($productIds)) {
            $this->calculator->execute($productIds);
        }
    }
}

Spamworldpro Mini