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/AutoCreatePickup.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Cron;

use Extmag\Shiplab\Helper\Manager;
use Extmag\Shiplab\Helper\Pickup;
use Extmag\Shiplab\Model\Label;
use Extmag\Shiplab\Model\ResourceModel\Label\Collection;
use Extmag\Shiplab\Model\ResourceModel\Label\CollectionFactory;
use Exception;
use Magento\Framework\Stdlib\DateTime\DateTime;
use Magento\Framework\Stdlib\DateTime\Timezone;
use Psr\Log\LoggerInterface as Logs;

class AutoCreatePickup
{
    /**
     * @var CollectionFactory
     */
    protected $labelCollectionFactory;
    /**
     * @var Pickup
     */
    protected $pickup;

    /**
     * @var Logs
     */
    protected $log;
    /**
     * @var DateTime
     */
    protected $dateTime;
    /**
     * @var Manager
     */
    protected $manager;
    /**
     * @var Timezone
     */
    protected $timezone;

    /**
     * AutoCreatePickup constructor.
     * @param Pickup $pickup
     * @param CollectionFactory $labelCollectionFactory
     * @param Logs $log
     * @param DateTime $dateTime
     * @param Timezone $timezone
     * @param Manager $manager
     */
    public function __construct(
        Pickup $pickup,
        CollectionFactory $labelCollectionFactory,
        Logs $log,
        DateTime $dateTime,
        Timezone $timezone,
        Manager $manager
    ) {
        $this->labelCollectionFactory = $labelCollectionFactory;
        $this->pickup = $pickup;
        $this->log = $log;
        $this->dateTime = $dateTime;
        $this->manager = $manager;
        $this->timezone = $timezone;
    }

    /**
     * @return void
     * @throws Exception
     */
    public function execute()
    {
        /**
         * @var Collection $labelCollection
         */
        $labelCollection = $this->labelCollectionFactory->create();
        $labelCollection->addFieldToFilter('status', 1);
        $labelCollection->addFieldToFilter('type_direction', 'shipment');
        $labelCollection->addFieldToFilter('is_pickup', 0);
        $labelCollection->addFieldToFilter('track_status', 0);
        $labelCollection->addFieldToFilter(
            'created_time',
            [
                'gt' => $this->dateTime->date(
                    "Y-m-d H:i:s",
                    $this->dateTime->timestamp() - 8 * 86400
                ),
            ]
        );

        if ($labelCollection->count() > 0) {
            $labelsByCarrier = [];
            /**
             * @var Label $label
             */
            foreach ($labelCollection as $label) {
                $labelsByCarrier[$label->getCarrierCode()][] = $label;
            }

            if (!empty($labelsByCarrier)) {
                foreach ($labelsByCarrier as $carrierCode => $labels) {
                    $result = $this->pickup->makeDataAndSavePickup(
                        $carrierCode,
                        $labels,
                        (int)$this->timezone->date()->format("G")
                    );
                    if (!empty($result['error'])) {
                        $this->log->info('Pickup was not created for ' . strtoupper($carrierCode));
                    }
                }
            }
        }
    }
}

Spamworldpro Mini