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/vendor/extmag/shiplab/Cron/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/shiplab/Cron/AutoCreateLabel.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Cron;

use Extmag\Shiplab\Helper\Label;
use Extmag\Shiplab\Helper\LabelFactory;
use Extmag\Shiplab\Model\LabelCron;
use Extmag\Shiplab\Model\LabelCronRepository;
use Extmag\Shiplab\Model\ResourceModel\LabelCron\CollectionFactory as LabelCronCollectionFactory;
use Extmag\Shiplab\Model\Source\CarrierCodes;
use Exception;
use Magento\Framework\Exception\CouldNotDeleteException;
use Psr\Log\LoggerInterface;

class AutoCreateLabel
{
    /**
     * @var LabelFactory
     */
    protected $helperLabel;
    /**
     * @var LabelCronCollectionFactory
     */
    protected $labelCronCollection;
    /**
     * @var LabelCronRepository
     */
    protected $labelCronRepository;

    /**
     * @var LoggerInterface
     */
    protected $log;
    /**
     * @var CarrierCodes
     */
    protected $carrierCodes;

    /**
     * @param LabelFactory               $helperLabel
     * @param LabelCronCollectionFactory $labelCronCollection
     * @param LabelCronRepository        $labelCronRepository
     * @param LoggerInterface            $log
     * @param CarrierCodes               $carrierCodes
     */
    public function __construct(
        LabelFactory $helperLabel,
        LabelCronCollectionFactory $labelCronCollection,
        LabelCronRepository $labelCronRepository,
        LoggerInterface $log,
        CarrierCodes $carrierCodes
    ) {
        $this->helperLabel         = $helperLabel;
        $this->labelCronCollection = $labelCronCollection;
        $this->labelCronRepository = $labelCronRepository;
        $this->log                 = $log;
        $this->carrierCodes        = $carrierCodes;
    }

    /**
     * @return void
     * @throws CouldNotDeleteException
     */
    public function execute()
    {
        /**
         * @var LabelCron[] $labelCronCollection
         */
        $labelCronCollection = $this->labelCronCollection->create()->addFieldToSelect(['entity_id', 'order_id']);
        $existingOrderIds    = [];
        foreach ($labelCronCollection as $item) {
            $existingOrderIds[] = $item->getOrderId();
            $this->labelCronRepository->delete($item);
        }

        if (!empty($existingOrderIds)) {
            $this->makeData(
                array_keys($this->carrierCodes->toArray()),
                $existingOrderIds,
                'order',
                'shipment',
                'automatic'
            );
        }
    }

    /**
     * @param $carrierCodes
     * @param $selected
     * @param $orderSubType
     * @param $route
     * @param $actionType
     * @return void
     */
    protected function makeData($carrierCodes, $selected, $orderSubType, $route, $actionType)
    {
        try {
            if (!is_array($carrierCodes)) {
                $carrierCodes = [$carrierCodes];
            }

            /**
             * @var Label $helperLabel
             */
            foreach ($carrierCodes as $carrierCode) {
                $helperLabel = $this->helperLabel->create();
                $savedLabels = $helperLabel->makeDataAndSaveLabel(
                    $carrierCode,
                    $selected,
                    $orderSubType,
                    $route,
                    $actionType
                );

                if (!empty($savedLabels['error'])) {
                    $this->log->info(
                        __('Labels were not automatic created for %1 shipment(s)', count($savedLabels['error']))
                    );
                }
            }
        } catch (Exception $e) {
            $this->log->error($e->getTraceAsString());
        }
    }
}

Spamworldpro Mini