Skip to content

Refactor code create cron Magento 2.4.3 to 2.4.7

Old Code:

<?php
/**
 * Copyright © All rights reserved.
 * See COPYING.txt for license details.
 */

namespace ModuleCoordCron;

class GenerateShipping
{
    protected PsrLogLoggerInterface $logger;

    /**
     * @var ModuleCoordModelShipmentGeneration
     */
    private ModuleCoordModelShipmentGeneration $shipment;

    /**
     * Constructor
     *
     * @param PsrLogLoggerInterface $logger
     * @param ModuleCoordModelShipmentGeneration $shipmentGeneration
     */
    public function __construct(
        PsrLogLoggerInterface $logger,
        ModuleCoordModelShipmentGeneration $shipmentGeneration
    ) {
        $this->logger = $logger;
        $this->shipment = $shipmentGeneration;
    }

    /**
     * Execute the cron
     *
     * @return void
     * @throws Exception
     */
    public function execute()
    {
        $this->logger->info("Cronjob GenerateShipping is executed.");
        $this->shipment->ordersToShip();
    }
}