0

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:

  define([
        'moment',
        'ko',
        'underscore',
        'jquery',
        'mage/translate',
        'mage/calendar'
    ], 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(),
                    observable,
                    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);

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

                ko.utils.registerEventHandler(el, 'change', function () {
=========================================================================
                    //alert(this.value); 
                    // date changed from here. I want to call controller from here
=========================================================================
                    observable(this.value);
                });
            }
        };
    });
0

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;
    else
        return true;
    }
    

Hope this help !!

| improve this answer | |
  • Thanks for your suggestion, There is only lower and upper limit options for time interval. – Vinod Kumar Feb 4 '19 at 5:30
  • yes that you need to customize to add order limit as well – Pankaj Pareek Feb 4 '19 at 5:46
0

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)
    ->group('delivery_slot');

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

| improve this answer | |
  • Thanks for reply, I have added datepicker.js code where date changed. I want to call controller from here so that I can do – Vinod Kumar Feb 4 '19 at 11:08
  • Yes. Onchange of deleivery_date field you can call controller action. Happy to know that it was helped to you. – Shajitha Banu Feb 5 '19 at 5:24

Your Answer

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

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