403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/boxberry.delivery/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /home/bitrix/ext_www/rospirotorg.ru/bitrix/modules/boxberry.delivery/handler.php
<?php

namespace Sale\Handlers\Delivery;

use Bitrix\Main\ORM\Data\UpdateResult;
use Bitrix\Main\Page\Asset;
use Bitrix\Main\Result;
use Bitrix\Main\SystemException;
use Bitrix\Sale\Delivery\CalculationResult;
use Bitrix\Sale\Delivery\Services\Base;
use Bitrix\Sale\Delivery\Services\Manager;
use Bitrix\Sale\Delivery\Services\Table;
use Bitrix\Sale\Shipment;
use Bitrix\Main\Localization\Loc;
use Boxberry\Bitrix\Helpers\Delivery;
use Boxberry\Bitrix\Helpers\Extensions;
use Boxberry\Bitrix\Helpers\Options;

Loc::loadMessages(__FILE__);

class BoxberryHandler extends Base
{
    protected $handlerCode = 'BOXBERRY';
    protected static $isCalculatePriceImmediately = true;
    protected static $whetherAdminExtraServicesShow = false;
    protected static $canHasProfiles = true;

    public function __construct(array $initParams)
    {
        parent::__construct($initParams);
    }

    public static function getClassTitle(): string
    {
        return Loc::getMessage('CLASS_TITLE');
    }

    public static function getClassDescription(): string
    {
        return Loc::getMessage('CLASS_DESCRIPTION');
    }

    public function getCode(): string
    {
        return 'Boxberry';
    }

    public function isCalculatePriceImmediately(): bool
    {
        return self::$isCalculatePriceImmediately;
    }

    public static function whetherAdminExtraServicesShow(): bool
    {
        return self::$whetherAdminExtraServicesShow;
    }

    protected function getConfigStructure(): array
    {
        return Options::getConfigStructureForHandler();
    }

    public static function canHasProfiles(): bool
    {
        return self::$canHasProfiles;
    }

    public function isActive(): bool
    {
        return $this->active;
    }

    /**
     * @throws SystemException
     */
    protected function calculateConcrete(Shipment $shipment): CalculationResult
    {
        throw new SystemException(Loc::getMessage('NO_CALCULATE_IN_HANDLER_EXCEPTION'));
    }

    public function getAdminMessage(): array
    {
        return [];
    }

    public function execAdminAction(): Result
    {
        $result = new Result();
        Extensions::initService();

        return $result;
    }

    public static function getChildrenClassNames(): array
    {
        return [
            BoxberryProfile::class,
        ];

    }

    public function getProfilesList(): array
    {
        return [
            BoxberryProfile::class => BoxberryProfile::getClassTitle(),
        ];
    }

    /**
     * @param array $fields
     * @return Result
     */
    public static function onBeforeAdd(array &$fields = array()): Result
    {
        $fields['LOGOTIP'] = Options::getLogoId();
        return new Result();
    }

    public static function onAfterAdd($serviceId, array $fields = array()): bool
    {
        if ($serviceId <= 0) {
            return false;
        }

        $fields['ID'] = $serviceId;
        $srv = new self($fields);
        $profile = $srv->getProfileDefaultParams($fields);
        $typeNames = [
            '1' => Loc::getMessage('SELF_PICKUP'),
            '2' => Loc::getMessage('COURIER'),
        ];

        foreach ($typeNames as $type => $name) {
            $profile['NAME'] = $name;
            $result = Manager::add($profile);

            if (!$result->isSuccess()) {
                return false;
            }

            if (!self::setDeliveryType($result->getId(), $type)->isSuccess()) {
                return false;
            }

        }

        return true;

    }

    private function getProfileDefaultParams(array $fields): array
    {
        $active = $fields['ACTIVE'] ?? ($this->active ? 'Y' : 'N');
        $sort = $fields['SORT'] ?? $this->sort;

        return [
            'CODE' => '',
            'PARENT_ID' => $this->id,
            'NAME' => $fields['NAME'],
            'ACTIVE' => $active,
            'SORT' => $sort,
            'LOGOTIP' => Options::getLogoId(),
            'DESCRIPTION' => $fields['DESCRIPTION'],
            'CLASS_NAME' => '\\' . BoxberryProfile::class,
            'CURRENCY' => $this->currency,
            'CONFIG' => Options::getConfigStructureForProfile()

        ];
    }

    private static function setDeliveryType($serviceId, $deliveryType = '1'): UpdateResult
    {
        try {
            $query = Table::query()
                ->setSelect(['ID', 'CONFIG'])
                ->where('ID', $serviceId)
                ->where('ACTIVE', 'Y')
                ->where('CLASS_NAME', Delivery::BB_PROFILE_CLASS_NAME)
                ->setLimit(1)
                ->exec()
                ->fetch();

            if (!$query) {
                return new UpdateResult();
            }

            $config = self::makeConfigArray($query);
            $config['CONFIG']['TYPE']['PROFILE_TYPE'] = (string)$deliveryType;

            return Table::update($serviceId, $config);
        } catch (\Exception $e) {
            return new UpdateResult();
        }

    }

    private static function makeConfigArray($inputArray): array
    {
        $result = [];

        foreach ($inputArray as $key => $value) {
            if ($key === 'ITEMS') {
                foreach ($value as $itemKey => $itemValue) {
                    $result[$itemKey] = (string)$itemValue['DEFAULT'];
                }
            } else if (is_array($value)) {
                $result[$key] = self::makeConfigArray($value);
            }
        }

        return $result;
    }

}

Youez - 2016 - github.com/yon3zu
LinuXploit