0

I am using amasty one step checkout extension in which delivery date option available. It has delivery time range option only in admin. When I enabled this option then delivery date and time are showing on checkout page fine.

Time interval is of 1 hour. I want to change it to 2 hour.

for example:

9-11

11-13

13-15

I have tried but not getting success.

delivery date and time code is:

public function __construct(
        ScopeConfigInterface $scopeConfig
    ) {
        $this->scopeConfig = $scopeConfig;
    }

    public function getDeliveryDays()
    {
        $days = $this->scopeConfig->getValue(
            'amasty_checkout/delivery_date/available_days', ScopeInterface::SCOPE_STORE
        );

        if (!$days)
            return [];

        $days = explode(',', $days);

        foreach ($days as &$day) {
            $day = (int)$day;
        }

        return $days;
    }

    public function getDeliveryHours()
    {
        $hoursSetting = trim($this->scopeConfig->getValue(
            'amasty_checkout/delivery_date/available_hours', ScopeInterface::SCOPE_STORE
        ));

        $hours = [];

        $intervals = preg_split('#\s*,\s*#', $hoursSetting, -1, PREG_SPLIT_NO_EMPTY);

        foreach ($intervals as $interval) {
            if (preg_match('#(?P<lower>\d+)(\s*-\s*(?P<upper>\d+))?#', $interval, $matches)) {
                $lower = (int)$matches['lower'];
                if ($lower > 23) {
                    continue;
                }

                if (isset($matches['upper'])) {
                    $upper = (int)$matches['upper'];
                    if ($upper > 24) {
                        continue;
                    }

                    $upper--;

                    if ($lower > $upper) {
                        continue;
                    }
                } else {
                    $upper = $lower;
                }

                $hours = array_merge($hours, range($lower, $upper));
            }
        }

        if (!$hours) {
            $hours = range(0, 23);
        }
        else {
            $hours = array_unique($hours);
            asort($hours);
        }

        $options = [[
                        'value' => '-1',
                        'label' => ' ',
                    ]];

        foreach ($hours as $hour) {
            $options [] = [
                'value' => $hour,
                'label' => $hour . ':00 - ' . (($hour) + 1) . ':00',
            ];
        }

        return $options;
    }
  • 'label' => $hour . ':00 - ' . (($hour) + 1) . ':00', have you tried changing that + 1 to ( + 2 ) – fmsthird Feb 1 at 12:54
  • tried. after that result is: 9-11, 10-12, 11-13, 12-14 – Vinod Kumar Feb 1 at 13:11
  • issue fixed using while loop. – Vinod Kumar Feb 1 at 13:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.