sibling->display($this->sibling->module_file, 'views/templates/admin/config/specificdates.tpl'); } /** * Render list of existing specific dates */ public function renderList() { $id_carrier = (int)Tools::getValue('id_carrier'); $id_shop = (int)Context::getContext()->shop->id; $ddw_specificdates_model = new DDWSpecificDateModel(); $specificdates = $ddw_specificdates_model->getAll($id_carrier, $id_shop); Context::getContext()->smarty->assign(array( 'module_config_url' => $this->module_config_url, 'specificdates' => $specificdates )); return $this->sibling->display($this->sibling->module_file, 'views/templates/admin/config/specificdates_list.tpl'); } /** * Render the settings popup form * @return mixed */ public function renderEditForm() { $id_ddw_specificdate = (int)Tools::getValue('id'); $id_carrier = (int)Tools::getValue('id_carrier'); $id_shop = (int)Tools::getValue('id_shop'); $cutofftime = ''; $timeslots = array(); if ($id_ddw_specificdate > 0) { $ddw_specificdate_model = new DDWSpecificDateModel($id_ddw_specificdate); $ddw_timeslots = new DDWTimeslotModel(); $timeslots = $ddw_timeslots->getTimeSlotsForSpecificDate($id_ddw_specificdate, Tools::getValue('id_carrier'), Context::getContext()->shop->id); $cutofftime = sprintf('%02d', $ddw_specificdate_model->cutofftime_hours) . ':' . sprintf('%02d', $ddw_specificdate_model->cutofftime_minutes); } else { $ddw_specificdate_model = new DDWSpecificDateModel(); } $fields_form = array(); $fields_form[0]['form'] = array( 'input' => array( array( 'type' => 'hidden', 'name' => 'id_ddw' ), array( 'type' => 'hidden', 'name' => 'id_carrier' ), array( 'type' => 'hidden', 'name' => 'ddw_timeslots' ), array( 'type' => 'hidden', 'name' => 'id_shop' ), array( 'type' => 'hidden', 'name' => 'id' ), array( 'type' => 'html', 'label' => $this->sibling->l('Date', $this->route), 'name' => 'start_date', 'desc' => $this->sibling->l('Choose the date these settings will applied to', $this->route), 'html_content' => $this->renderDateFieldIcon('start_date', $ddw_specificdate_model->start_date) ), array( 'type' => 'switch', 'label' => $this->sibling->l('Day Enabled?', $this->route), 'name' => 'weekday_enabled', 'desc' => $this->sibling->l('Select if this date is available for delivery', $this->route), 'values' => array( array( 'id' => 'weekday_enabled_on', 'value' => 1, 'label' => $this->trans('Yes', array(), 'Admin.Global'), ), array( 'id' => 'weekday_enabled_off', 'value' => 0, 'label' => $this->trans('No', array(), 'Admin.Global'), ), ), ), array( 'type' => 'switch', 'label' => $this->sibling->l('Override main Preparation days settings?', $this->route), 'name' => 'minmax_enabled', 'desc' => $this->sibling->l('This option will allow you override some of the general settings', $this->route), 'values' => array( array( 'id' => 'minmax_enabled_on', 'value' => 1, 'label' => $this->trans('Yes', array(), 'Admin.Global'), ), array( 'id' => 'minmax_enabled_off', 'value' => 0, 'label' => $this->trans('No', array(), 'Admin.Global'), ) ), ), array( 'type' => 'text', 'label' => $this->sibling->l('Order Preparation Days', $this->route), 'name' => 'min_days', 'desc' => $this->sibling->l('Number of days it will take before the order can be delivered from the current day. 0 days is same day delivery, 1 is next day etc', $this->route), 'suffix' => $this->sibling->l('days', $this->route), 'size' => 4, 'class' => 'fixed-width-xl', ), array( 'type' => 'text', 'label' => $this->sibling->l('Maximum Days', $this->route), 'name' => 'max_days', 'desc' => $this->sibling->l('All dates in the calendar after this number of days (from the current day) will be disabled', $this->route), 'suffix' => $this->sibling->l('days', $this->route), 'size' => 4, 'class' => 'fixed-width-xl', ), array( 'type' => 'text', 'label' => $this->sibling->l('Order Preparation Time', $this->route), 'name' => 'timeslots_prep_minutes', 'desc' => $this->sibling->l('For same day delivery, time it takes you to prepare an order for delivery. Time slots within this period will be unavailable to the customer.', $this->route), 'prefix' => $this->renderIcon('alarm_on'), 'suffix' => $this->sibling->l('minutes', $this->route), 'size' => 4, 'class' => 'fixed-width-xl', ), array( 'type' => 'switch', 'label' => $this->sibling->l('Cut off time enabled?', $this->route), 'name' => 'weekday_cutofftime_enabled', 'values' => array( array( 'id' => 'weekday_cutofftime_enabled_on', 'value' => 1, 'label' => $this->trans('Yes', array(), 'Admin.Global'), ), array( 'id' => 'weekday_cutofftime_enabled_off', 'value' => 0, 'label' => $this->trans('No', array(), 'Admin.Global'), ), ), ), array( 'type' => 'html', 'label' => $this->sibling->l('Cut off time', $this->route), 'name' => 'weekday_cutofftime', 'desc' => $this->sibling->l('Cut off time or deadline after which the order preparation day rolls over to the next available day', $this->route), 'html_content' => $this->renderTimeFieldIcon('weekday_cutofftime', $cutofftime) ), array( 'type' => 'text', 'label' => $this->sibling->l('Order Preparation Days after cut off time', $this->route), 'name' => 'min_days_postcutoff', 'desc' => $this->sibling->l('Number of days before the delivery can be made after the cut off time has passed', $this->route), 'suffix' => $this->sibling->l('days', $this->route), 'size' => 4, 'class' => 'fixed-width-xl', ), array( 'type' => 'text', 'label' => $this->sibling->l('Order Limit for the day', $this->route), 'name' => 'day_order_limit', 'desc' => $this->sibling->l('This date wil become unavailable after this many orders have been placed', $this->route), 'suffix' => $this->sibling->l('orders', $this->route), 'size' => 4, 'class' => 'fixed-width-xl', ), array( 'type' => 'html', 'name' => 'timeslots', 'label' => $this->sibling->l('Timeslots', $this->route), 'html_content' => $this->renderFieldButton($this->sibling->l('Edit Timeslots for this weekday', $this->route), 'edit-timeslots', '#edit-timeslots', 'icon-list', 'btn-secondary'), 'desc' => $this->sibling->l('Manage time slots for the customer to select for this week day', $this->route), ) ), 'submit' => array( 'title' => $this->sibling->l('Save', $this->route), 'class' => 'btn btn-ddw-date-save pull-right' ) ); $helper = new HelperForm(); $this->setupHelperConfigForm($helper, $this->route, 'process'); $helper->fields_value['id'] = $id_ddw_specificdate; $helper->fields_value['id_carrier'] = $id_carrier; $helper->fields_value['id_shop'] = $id_shop; if ((int)$ddw_specificdate_model->id_ddw_specificdate > 0) { $helper->fields_value['weekday_enabled'] = $ddw_specificdate_model->enabled; } else { $helper->fields_value['weekday_enabled'] = 0; } $helper->fields_value['min_days'] = $ddw_specificdate_model->min_days; $helper->fields_value['max_days'] = $ddw_specificdate_model->max_days; $helper->fields_value['timeslots_prep_minutes'] = $ddw_specificdate_model->timeslots_prep_minutes; $helper->fields_value['minmax_enabled'] = $ddw_specificdate_model->minmax_enabled; $helper->fields_value['weekday_cutofftime_enabled'] = $ddw_specificdate_model->cutofftime_enabled; $helper->fields_value['min_days_postcutoff'] = $ddw_specificdate_model->min_days_postcutoff; $helper->fields_value['day_order_limit'] = $ddw_specificdate_model->order_limit; Context::getContext()->smarty->assign(array( 'model' => 'specificdate', 'form' => $helper->generateForm($fields_form), 'id_carrier' => $id_carrier, 'ddw_timeslots' => $timeslots, )); return $this->sibling->display($this->sibling->module_file, 'views/templates/admin/config/datepopup_edit.tpl'); } /** * Save the settings and the timeslots for the specific date */ public function processForm() { $id_ddw_specificdate = (int)Tools::getValue('id'); $id_carrier = (int)Tools::getValue('id_carrier'); $id_shop = (int)Tools::getValue('id_shop'); if ($id_ddw_specificdate == 0) { $ddw_specificdate = new DDWSpecificDateModel(); //delete any sopecific dates with the same date $ddw_specificdate->loadByDate(Tools::getValue('start_date'), $id_carrier, $id_shop); if (!empty($ddw_specificdate->id_ddw_specificdate)) { DDWTimeslotModel::deleteAllBySpecificDate($ddw_specificdate->id_ddw_specificdate); $ddw_specificdate->delete(); $ddw_specificdate = new DDWSpecificDateModel(); } } else { $ddw_specificdate = new DDWSpecificDateModel($id_ddw_specificdate); } $cutofftime_parts = explode(':', Tools::getValue('weekday_cutofftime')); $cutofftime_hours = $cutofftime_parts[0]; $cutofftime_minutes = $cutofftime_parts[1]; if (empty($ddw_specificdate->id_carrier)) { $ddw_specificdate->id_carrier = $id_carrier; } if (empty($ddw_specificdate->id_shop)) { $ddw_specificdate->id_shop = $id_shop; } if (Tools::getValue('start_date') == '') { //@todo: display error return false; } $ddw_specificdate->enabled = (int)Tools::getValue('weekday_enabled'); $ddw_specificdate->start_date = pSQL(Tools::getValue('start_date')); $ddw_specificdate->end_date = $ddw_specificdate->start_date; $ddw_specificdate->minmax_enabled = (int)Tools::getValue('minmax_enabled'); $ddw_specificdate->min_days = Tools::getValue('min_days'); $ddw_specificdate->max_days = Tools::getValue('max_days'); $ddw_specificdate->timeslots_prep_minutes = (int)Tools::getValue('timeslots_prep_minutes'); $ddw_specificdate->cutofftime_enabled = (int)Tools::getValue('weekday_cutofftime_enabled'); $ddw_specificdate->cutofftime_hours = (int)$cutofftime_hours; $ddw_specificdate->cutofftime_minutes = (int)$cutofftime_minutes; $ddw_specificdate->min_days_postcutoff = (int)Tools::getValue('min_days_postcutoff'); $ddw_specificdate->order_limit = (int)Tools::getValue('day_order_limit'); if ($ddw_specificdate->save()) { DDWTimeslotModel::deleteAllByCarrier($id_carrier, $id_shop, '', $ddw_specificdate->id); $timeslots = json_decode(Tools::getValue('ddw_timeslots')); $i = 0; if (is_array($timeslots)) { foreach ($timeslots as $timeslot) { $ddw_timeslot = new DDWTimeslotModel(); $ddw_timeslot->id_weekday = -1; $ddw_timeslot->id_ddw_specificdate = $ddw_specificdate->id; $ddw_timeslot->id_carrier = $id_carrier; $ddw_timeslot->id_shop = $id_shop; $ddw_timeslot->time_start = DDWTimeslotModel::formatHumanTime($timeslot->time_start); $ddw_timeslot->time_end = DDWTimeslotModel::formatHumanTime($timeslot->time_end); $ddw_timeslot->order_limit = $timeslot->order_limit; $ddw_timeslot->position = $i; $ddw_timeslot->enabled = (int)$timeslot->enabled; $ddw_timeslot->add(false); $i++; } } } $json_return = array('id' => $ddw_specificdate->id); print json_encode($json_return); die; } /** * Delete a specific date completely including related timeslots */ public function processDelete() { $id_ddw_specificdate = (int)Tools::getValue('id_ddw_specificdate'); if ($id_ddw_specificdate <= 0) { return false; } DDWTimeslotModel::deleteAllBySpecificDate(Tools::getValue('id_ddw_specificdate')); $ddw_specificdate_model = new DDWSpecificDateModel((int)Tools::getValue('id_ddw_specificdate')); $ddw_specificdate_model->delete(); } public function route() { switch (Tools::getValue('action')) { case 'render': die($this->render()); case 'renderlist': die($this->renderList()); case 'rendereditform': die($this->renderEditForm()); case 'processform': die($this->processForm()); case 'processdelete': die($this->processDelete()); } } }