drupal commerce Доставка .

Главные вкладки

Аватар пользователя qqqarmani qqqarmani 6 ноября 2012 в 21:16

Привет всем.
У меня есть вопрос.
Делаю модуль доставкы Нова почта.
Как вернуть даные о полях с модуля в админку.

<?php

/**
 * file
 * Defines an example shipping method for testing and development.
 */

/**
 * Implements hook_commerce_shipping_method_info().
 */

function commerce_shipping_example_commerce_shipping_method_info() {
  $shipping_methods = array();

  $shipping_methods['example_shipping_method'] = array(
    'title' => t('Example shipping method'),
    'description' => t('Defines a single flat rate service with a couple of service details.'),
  );

  return $shipping_methods;
}

/**
 * Implements hook_commerce_shipping_service_info().
 */

function commerce_shipping_example_commerce_shipping_service_info() {
  $shipping_services = array();

  $shipping_services['example_shipping_service'] = array(
    'title' => t('Example shipping service'),
    'description' => t('A $20 flat rate service with express delivery available for an additional $15.'),
    'display_title' => t('Shipping'),
    'shipping_method' => 'example_shipping_method',
    'price_component' => 'shipping',
    'callbacks' => array(
      'rate' => 'commerce_shipping_example_service_rate',
      'details_form' => 'commerce_shipping_example_service_details_form',
      'details_form_validate' => 'commerce_shipping_example_service_details_form_validate',
      'details_form_submit' => 'commerce_shipping_example_service_details_form_submit',
    ),
  );

  return $shipping_services;
}

/**
 * Shipping service callback: returns a base price array for a shipping service
 * calculated for the given order.
 */

function commerce_shipping_example_service_rate($shipping_service, $order) {
  return array(
    'amount' => 2000,
    'currency_code' => 'USD',
    'data' => array(),
  );
}

/**
 * Shipping service callback: returns the example shipping service details form.
 */

function commerce_shipping_example_service_details_form($pane_form, $pane_values, $checkout_pane, $order, $shipping_service) {
  $form = array();

  $pane_values['service_details'] += array(
    'comment_new_post' => '',
        'name' => '',
        'name2' => '',
        'city_ucraine' => '',
        'city_city' => '',
    'express' => '',
       
  );
 
  $form['city_city'] = array(
  '#type' => 'select',
  '#title' => 'citi city',
  '#default_value' => $pane_values['service_details']['city_ucraine'],
  '#options' => array(
  '-any-' => 'any',
    'abc' => 'abc',
        '#required' => TRUE,
  )
);

  $form['city_ucraine'] = array(
    '#type' => 'textfield',
    '#title' => t('city_ucraine'),
    '#description' => t('This is a demonstration field coded to fail validation for single character values.'),
    '#default_value' => $pane_values['service_details']['city_ucraine'],
    '#required' => TRUE,
  );
 
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('This is a demonstration field coded to fail validation for single character values.'),
    '#default_value' => $pane_values['service_details']['name'],
    '#required' => TRUE,
  );
 $form['name2'] = array(
    '#type' => 'textfield',
    '#title' => t('Name2'),
    '#description' => t('This is a demonstration field coded to fail validation for single character values.'),
    '#default_value' => $pane_values['service_details']['name2'],
    '#required' => TRUE,
  );
 
 
 
   $form['comment_new_post'] = array(
    '#type' => 'textarea',
    '#title' => t('comment_new_post'),
    '#description' => t('This is a demonstration field coded to fail validation for single character values.'),
    '#default_value' => $pane_values['service_details']['comment_new_post'],
    '#required' => FALSE,
  );
 

  return $form;
}

/**
 * Shipping service callback: validates the example shipping service details.
 */

function commerce_shipping_example_service_details_form_validate($details_form, $details_values, $shipping_service, $order, $form_parents) {
  if (strlen($details_values['name']) < 2) {
    form_set_error(implode('][', array_merge($form_parents, array('name'))), t('You must enter a name two or more characters long.'));

    // Even though the form error is enough to stop the submission of the form,
    // it's not enough to stop it from a Commerce standpoint because of the
    // combined validation / submission going on per-pane in the checkout form.
    return FALSE;
  }
}

/**
 * Shipping service callback: increases the shipping line item's unit price if
 * express delivery was selected.
 */

function commerce_shipping_example_service_details_form_submit($details_form, $details_values, $line_item) {
  if ($details_values['express']) {
    $line_item_wrapper = entity_metadata_wrapper('commerce_line_item', $line_item);

    // Build a price array for the express delivery fee.
    $express_price = array(
      'amount' => 1500,
      'currency_code' => 'USD',
      'data' => array(),
    );

    // Multiply the unit price by 2.
    $line_item_wrapper->commerce_unit_price->amount += 1500;

    // Add the express delivery fee component to the unit price.
    $line_item_wrapper->commerce_unit_price->data = commerce_price_component_add(
      $line_item_wrapper->commerce_unit_price->value(),
      'example_shipping_service_express',
      $express_price,
      TRUE,
      FALSE
    );
  }
}

/**
 * Implements hook_commerce_price_component_type_info().
 */

function commerce_shipping_example_commerce_price_component_type_info() {
  return array(
    'example_shipping_service_express' => array(
      'title' => t('Express delivery'),
      'weight' => 20,
    ),
  );
}

Комментарии

Аватар пользователя volocuga@drupal.org volocuga@drupal.org 6 декабря 2012 в 18:15

Эти ушлёпки поубирали ключи для АПИ и игнорируют вопросы в техподдержку:) И походу АПи будет либо меняться либо вообще убираться :). Как раз засел за модуль тут на тебе Smile