I would like to be able to create a calendar view from the date fields in uc_orders.

I believe the addition of this code would let it happen. Simliar code could be used for the other date fields in the other ubercart submodules to provide same functionality.

Thanks,

Alex

/**
* Implements hook_date_views_fields().
*
* All modules that create custom fields that use the
* 'views_handler_field_date' handler can provide
* additional information here about the type of
* date they create so the date can be used by
* the Date API views date argument and date filter.
*/
function uc_order_date_views_fields($field) {
  $values = array(
    // The type of date: DATE_UNIX, DATE_ISO, DATE_DATETIME.
    'sql_type' => DATE_UNIX,
    // Timezone handling options: 'none', 'site', 'date', 'utc' .
    'tz_handling' => 'site',
    // Needed only for dates that use 'date' tz_handling.
    'timezone_field' => '',
    // Needed only for dates that use 'date' tz_handling.
    'offset_field' => '',
    // Array of "table.field" values for related fields that should be
    // loaded automatically in the Views SQL.
    'related_fields' => array(),
    // Granularity of this date field's db data.
    'granularity' => array('year', 'month', 'day', 'hour', 'minute', 'second'),
  );

  switch ($field) {
    case 'uc_orders.created':
    case 'uc_orders.modified':
      return $values;
  }
}

Comments

longwave’s picture

Component: 3rd party integration » Module integration
Priority: Major » Normal
Status: Active » Needs review
StatusFileSize
new2.46 KB

I think we need an extra hook and also to set 'is date' in the Views data hook to fully integrate with Date here. Please test the attached patch and let me know if this works for you.

alex.neblett’s picture

The patch is definately pushing things in the right direction. Thanks:)

I can now import:

$view = new view;
$view->name = 'order_calendar';
$view->description = 'A multi-dimensional orders calendar view with back/next navigation.';
$view->tag = 'Order_Calendar';
$view->base_table = 'uc_orders';
$view->human_name = 'Order_Calendar';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'order_calendar';
$handler->display->display_options['link_display'] = 'page_1';
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['access']['perm'] = 'view all orders';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['query']['options']['query_comment'] = FALSE;
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'date_views_pager';
$handler->display->display_options['style_plugin'] = 'calendar_style';
$handler->display->display_options['row_plugin'] = 'calendar_entity';
/* Field: Order: Order ID */
$handler->display->display_options['fields']['order_id']['id'] = 'order_id';
$handler->display->display_options['fields']['order_id']['table'] = 'uc_orders';
$handler->display->display_options['fields']['order_id']['field'] = 'order_id';
/* Field: Order: Creation date */
$handler->display->display_options['fields']['created']['id'] = 'created';
$handler->display->display_options['fields']['created']['table'] = 'uc_orders';
$handler->display->display_options['fields']['created']['field'] = 'created';
$handler->display->display_options['fields']['created']['label'] = '';
$handler->display->display_options['fields']['created']['alter']['alter_text'] = 0;
$handler->display->display_options['fields']['created']['alter']['make_link'] = 0;
$handler->display->display_options['fields']['created']['alter']['absolute'] = 0;
$handler->display->display_options['fields']['created']['alter']['external'] = 0;
$handler->display->display_options['fields']['created']['alter']['replace_spaces'] = 0;
$handler->display->display_options['fields']['created']['alter']['trim_whitespace'] = 0;
$handler->display->display_options['fields']['created']['alter']['nl2br'] = 0;
$handler->display->display_options['fields']['created']['alter']['word_boundary'] = 1;
$handler->display->display_options['fields']['created']['alter']['ellipsis'] = 1;
$handler->display->display_options['fields']['created']['alter']['strip_tags'] = 0;
$handler->display->display_options['fields']['created']['alter']['trim'] = 0;
$handler->display->display_options['fields']['created']['alter']['html'] = 0;
$handler->display->display_options['fields']['created']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['created']['element_default_classes'] = 1;
$handler->display->display_options['fields']['created']['hide_empty'] = 0;
$handler->display->display_options['fields']['created']['empty_zero'] = 0;
$handler->display->display_options['fields']['created']['hide_alter_empty'] = 1;
/* Sort criterion: Order: Creation date */
$handler->display->display_options['sorts']['created']['id'] = 'created';
$handler->display->display_options['sorts']['created']['table'] = 'uc_orders';
$handler->display->display_options['sorts']['created']['field'] = 'created';
/* Contextual filter: Date: Date (uc_orders) */
$handler->display->display_options['arguments']['date_argument']['id'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['table'] = 'uc_orders';
$handler->display->display_options['arguments']['date_argument']['field'] = 'date_argument';
$handler->display->display_options['arguments']['date_argument']['default_action'] = 'default';
$handler->display->display_options['arguments']['date_argument']['default_argument_skip_url'] = 0;
$handler->display->display_options['arguments']['date_argument']['add_delta'] = 'yes';
$handler->display->display_options['arguments']['date_argument']['date_fields'] = array(
  'uc_orders.created' => 'uc_orders.created',
);

/* Display: Month */
$handler = $view->new_display('page', 'Month', 'page');
$handler->display->display_options['path'] = 'calendar_entity';
$translatables['order_calendar'] = array(
  t('Master'),
  t('order_calendar'),
  t('more'),
  t('Apply'),
  t('Reset'),
  t('Sort by'),
  t('Asc'),
  t('Desc'),
  t('Order ID'),
  t('All'),
  t('Month'),
);

But, I get

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /admin/structure/views/view/order_calendar/preview/page/ajax
StatusText: OK
ResponseText: Fatal error: Class name must be a valid object or a string in /srv/www/htdocs/includes/common.inc on line 7618

I believe this is related to the other problem:

If I try to build a view via add new view, when I get to Add contextual filters, uc_orders.created is not there (uc_orders.order_id is there so we know the problem is related to the field and not the table).

I think you almost have it.

Thanks again,

Alex

alex.neblett’s picture

I forgot to mention that prior to your patch I was unable to import the view due to the contextual filter and that the second issue was present.

Thanks,

Alex

longwave’s picture

The order date fields are not currently implemented as contextual filters (arguments), so that's why they don't show up. That should just need a few lines adding to uc_order.views.inc I think.

longwave’s picture

Status: Needs review » Needs work
alex.neblett’s picture

I just updated to the latest commit versions of Calendar and Date API. Karen S. has been busy:) I like the updated views from templates function - very cool - I can now create my view from a template.

My created date order now appears. But I am getting a new message:

An AJAX HTTP error occurred.
HTTP Result Code: 200
Debugging information follows.
Path: /admin/structure/views/view/calendar_uc_orders_modified_/preview/page_1/ajax
StatusText: OK
ResponseText: Fatal error: Cannot access empty property in /srv/www/htdocs/sites/all/modules/calendar/includes/calendar_plugin_row.inc on line 352

It comes down to the line

$this->title = $entity->{$this->title_field};

It looks like between you and Karen S. things are moving forward rapidly.

Thanks again,

Alex

alex.neblett’s picture

Karen S. informs me that the error is coming from this bit of code:

<?php
      if (!empty($info['label callback'])) {
        $function = $info['label callback'];
        $this->title = $function($this->id);
      }
      else {
        $this->title_field = $info['entity keys']['label'];
        $this->title = $entity->{$this->title_field};
      }
?>

She goes on to say that "Entities are supposed to provide either a 'label' or a 'label callback' (this is the equivalent of the node title). It looks like the uc entity has done neither, so the code can't figure out what to do. This information would be in ubercarts hook_entity_info()."

Hopefully, adding this to your patch completes the task.

Thanks again,

Alex

alex.neblett’s picture

More progress:)

It turns out that 'entity keys' was missing 'lablel' in uc_order/uc_orders.module so I added them in resulting in:

/**
 * Implements hook_entity_info().
 */
function uc_order_entity_info() {
  return array(
    'uc_order' => array(
      'label' => t('Order'),
      'controller class' => 'UcOrderController',
      'base table' => 'uc_orders',
      'fieldable' => TRUE,
      'entity keys' => array(
        'id' => 'order_id',
        'label' => t('Order'),
      ),
      'bundles' => array(
        'uc_order' => array(
          'label' => t('Order'),
          'admin' => array(
            'path' => 'admin/store/settings/orders',
            'access arguments' => array('administer store'),
          ),
        ),
      ),
      'view modes' => array(
        'view' => array(
          'label' => t('Admin view'),
        ),
        'customer' => array(
          'label' => t('Customer view'),
        ),
      ),
      'uri callback' => 'uc_order_uri',
      // Entity API callbacks
      'access callback'   => 'uc_order_order_entity_access',
      'creation callback' => 'uc_order_new',
      'save callback'     => 'uc_order_save',
      'delete callback'   => 'uc_order_delete',
    ),
    'uc_order_product' => array(
      'label' => t('Order product'),
      'base table' => 'uc_order_products',
      'controller class' => 'UcOrderProductController',
      'metadata controller class' => 'UcOrderProductMetadataController',
      'entity keys' => array(
        'id' => 'order_product_id',
        'label' => t('Order product'),
      ),
      'bundles' => array(
        'uc_order_product' => array(
          'label' => t('Order product'),
        ),
      ),
      'view modes' => array(
        'full' => array(
          'label' => t('Normal view'),
        ),
        'cart' => array(
          'label' => t('Cart view'),
        ),
      ),
      // Entity API callbacks
      'access callback' => 'uc_order_order_product_access',
      'save callback'   => 'uc_order_product_entity_save',
      'delete callback' => 'uc_order_product_delete',
    ),
  );
}

This leads to a new error message:

Fatal error: Call to undefined function uc_order_uri() in /srv/www/htdocs/sites/all/modules/calendar/includes/calendar_plugin_row.inc on line 357 

This comes from 'uri callback' => 'uc_order_uri' above so now I am off to trace this down.

Thanks,

Alex

alex.neblett’s picture

I have resolved the issue by adding the missing function to uc_order/uc_orders.module

function uc_order_uri($order) {
  return array(
    'path' => 'node/' . $order->order_id,
  );
}

I am now able to render calendars:) But, I am still not doing one or more thing right. Above the calendar, the below message repeats once per item listed on the calendar.

Notice: Undefined property: stdClass::$Order in calendar_plugin_row->render() (line 352 of /srv/www/htdocs/sites/all/modules/calendar/includes/calendar_plugin_row.inc).

This comes back to:

        $this->title_field = $info['entity keys']['label'];
        $this->title = $entity->{$this->title_field};

letting me know that my hack for the ['entity keys']['label'] may have gotten me a calendar, but is not right.

If we fix this, the issue is wrapped up and Ubercart 3 is just that much better.

Thanks,

Alex

alex.neblett’s picture

Priority: Normal » Major
Status: Needs work » Needs review
StatusFileSize
new3.21 KB

Attached is a diff against the latest git.

It works for me aside from the below warning:

Notice: Undefined property: stdClass::$Order in calendar_plugin_row->render() (line 352 of /srv/www/htdocs/sites/all/modules/calendar/includes/calendar_plugin_row.inc).

Thanks,

Alex

longwave’s picture

Priority: Major » Normal
Status: Needs review » Needs work

Thanks for the updated patch.

+    'path' => 'node/' . $order->order_id,

This doesn't make sense; this should probably use the 'admin/store/orders/' prefix, but I wonder if we can/should do any permission checking here.

alex.neblett’s picture

Yeah. I was wondering what to put in there... and was not even sure it was used...

On another note, I took in the latest updates to ubercart, calendar, date and views and now the warning message is gone:)

Thanks,

Alex

alex.neblett’s picture

Status: Needs work » Needs review
StatusFileSize
new3.21 KB

Here is the revised version of the patch.

Please consider commiting it. I have been working with it for a few weeks now without issue.

Thanks again,

Alex

longwave’s picture

Status: Needs review » Fixed

Thanks for working on this! Committed #13 with some fixes to uc_order_uri().

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.