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/Model/ResourceModel/CarrierMethods/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/extmag/shiplab/Model/ResourceModel/CarrierMethods/Collection.php
<?php
/**
 * Copyright © Extmag. All rights reserved.
 */

namespace Extmag\Shiplab\Model\ResourceModel\CarrierMethods;

use Extmag\Shiplab\Model\Source\CarrierCodes;
use Magento\Framework\Data\OptionSourceInterface;
use Magento\Framework\Message\ManagerInterface;
use Magento\Framework\ObjectManagerInterface;

class Collection implements OptionSourceInterface
{
    /**
     * @var CarrierCodes
     */
    protected $carrierCodes;
    /**
     * @var ObjectManagerInterface
     */
    protected $objectManager;
    /**
     * @var ManagerInterface
     */
    protected $messageManager;

    /**
     * @param CarrierCodes $carrierCodes
     * @param ObjectManagerInterface $objectManager
     * @param ManagerInterface $messageManager
     */
    public function __construct(
        CarrierCodes $carrierCodes,
        ObjectManagerInterface $objectManager,
        ManagerInterface $messageManager
    ) {
        $this->carrierCodes = $carrierCodes;
        $this->objectManager = $objectManager;
        $this->messageManager = $messageManager;
    }

    /**
     * Convert collection items to select options array
     *
     * @return array
     */
    public function toOptionArray()
    {
        $carriers = $this->carrierCodes->getCarriers();
        $options = [];
        foreach ($carriers as $carrierCode => $data) {
            if (!empty($data['service_codes_class'])) {
                $shippingMethods = $this->objectManager->get($data['service_codes_class'])->toOptionArray();
                foreach ($shippingMethods as $shippingMethod) {
                    foreach ($shippingMethod['value'] as $key => $item) {
                        $shippingMethod['value'][$key]['title'] = $item['label'];
                        $shippingMethod['value'][$key]['value'] = (string)$item['value'];
                    }

                    $options[] = $shippingMethod + [
                            'carrier_methods_type' => 'specific',
                            'carrier' => $carrierCode,
                            'title' => $shippingMethod['label'],
                        ];
                }
            } else {
                $this->messageManager
                    ->addWarningMessage("service_codes_class is not defined for carrier " . $carrierCode);
            }
        }

        return $options;
    }
}

Spamworldpro Mini