I am using delivery date extension which date & time options. Time options has 2 hours difference in each interval. I want to set order limit within time interval.

For example:

Time Interval:

9-11, 11-13, 13-15, 15-17

I want to set limit to maximum 10 orders within one time interval.

After 10 orders that specific time interval must be disabled.

How can I do this task? can anyone help to do this?

datepicker.js is used to change date. How can I call controller to add my php code or condition for this. Here is the datepicker.js code:

    ], function (moment, ko, _, $, $t) {
        'use strict';

        var defaults = {
            dateFormat: 'mm\/dd\/yyyy',
            showsTime: false,
            timeFormat: null,
            buttonImage: null,
            buttonImageOnly: null,
            buttonText: $t('Select Date')

        ko.bindingHandlers.amastydatepicker = {

            init: function (el, valueAccessor) {

                var config = valueAccessor(),
                    options = {};

                _.extend(options, defaults);

                if (typeof config === 'object') {
                    observable = config.storage;

                    _.extend(options, config.options);
                } else {
                    observable = config;

                var date = moment(observable(), config.elem.pickerDateTimeFormat);

                observable() && $(el).datepicker('setDate', date.format('YYYY-MM-DD'));

                ko.utils.registerEventHandler(el, 'change', function () {
                    // date changed from here. I want to call controller from here

2 Answers 2


To achieve Order Limit functionality for each delivery Slot you can use the below approach:

  1. In your delivery date extension where you have date & time options, you can create one more field as order limit. So each delivery slot can have different limit.

  2. In sales_order table you must have delivery date and time field. So before displaying "delivery slots" on checkout you need to add one more check to mark delivery slot enable or disable in checkout. like below function:

    public function checkOrderLimit($date, $time, $maxCount)
    $cancelled = 'canceled';
    $closed  = 'closed';
    $connection = $this->getConnection();
    $select     = $connection->select()
        ->from($this->resource->getTableName('sales_order'), 'COUNT(entity_id)')
        ->where('delivery_slot_realtime=?', $time)
        ->where('delivery_date=?', $date)
        ->where('state!=?', $cancelled)
        ->where('state!=?', $closed);
    $totalOrderCount = (int) $connection->fetchOne($select);
    if ($totalOrderCount >= $maxCount)
        return false;
        return true;

Hope this help !!

  • Thanks for your suggestion, There is only lower and upper limit options for time interval. Feb 4, 2019 at 5:30
  • yes that you need to customize to add order limit as well Feb 4, 2019 at 5:46

Since the Question is related to logic, need more detail about how the extension works as a flow.

Once the delivery date was chosen, try to trigger an Ajax action, where filter the orders with the delivery date

$connection = $this->getConnection();
$select     = $connection->select()
    ->from($this->resource->getTableName('sales_order'), 'COUNT(entity_id)')
    ->where('delivery_date=?', $date)
    ->where('state!=?', $cancelled)
    ->where('state!=?', $closed)

Based on the count, you can disable the unavailable slot at the Ajax ends time.

  • Thanks for reply, I have added datepicker.js code where date changed. I want to call controller from here so that I can do Feb 4, 2019 at 11:08
  • Yes. Onchange of deleivery_date field you can call controller action. Happy to know that it was helped to you. Feb 5, 2019 at 5:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.