Добавление, изменение элементов заказа типа line item в заказе Ubercart

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

Аватар пользователя artanna@drupal.org artanna@drupal.org 21 апреля 2010 в 23:40

Привет всем,

Кто программировал для Ubercart, подскажите как правильно работать с добавлением собственных строк типа Line Item в заказ. Ищу материалы по hook_line_item, но конкретных примеров так и не нашел.

Задача довольно простая при добавлении в корзину определенного товара автоматом добавлять строку с дополнительной ценой, соответственно когда товар удаляют и эту доп. строку тоже удалять. И потом чтобы эта строка светилась в заказе всегда.

Смотрел модуль Fee но тоже ничего не понял. Понял концепцию - но заставить заработать ее не смог.

Кто сталкивался помогите советом.

Заранее благодарен.

Комментарии

Аватар пользователя Stutzer Stutzer 22 апреля 2010 в 0:45

А чем пример из документации не устраивает?

<?php

/**
 * Used to define line items that are attached to orders.
 *
 * A line item is a representation of charges, fees, and totals for an order.
 * Default line items include the subtotal and total line items, the tax line
 * item, and the shipping line item. There is also a generic line item that store
 * admins can use to add extra fees and discounts to manually created orders.
 * Module developers will use this hook to define new types of line items for
 * their stores. An example use would be for a module that allows customers to
 * use coupons and wants to represent an entered coupon as a line item.
 *
 * Once a line item has been defined in hook_line_item, Übercart will begin
 * interacting with it in various parts of the code. One of the primary ways this
 * is done is through the callback function you specify for the line item.
 *
 * return
 *   Your hook should return an array of associative arrays. Each item in the
 *   array represents a single line item and should use the following keys:
 *   - "id"
 *     - type: string
 *     - value: The internal ID of the line item.
 *   - "title"
 *     - type: string
 *     - value: The title of the line item shown to the user in various interfaces.
 *         Use t().
 *   - "callback"
 *     - type: string
 *     - value: Name of the line item's callback function, called for various
 *         operations.
 *   - "weight"
 *     - type: integer
 *     - value: Display order of the line item in lists; "lighter" items are
 *         displayed first.
 *   - "stored"
 *     - type: boolean
 *     - value: Whether or not the line item will be stored in the database.
 *         Should be TRUE for any line item that is modifiable from the order
 *         edit screen.
 *   - "add_list"
 *     - type: boolean
 *     - value: Whether or not a line item should be included in the "Add a Line
 *         Item" select box on the order edit screen.
 *   - "calculated"
 *     - type: boolean
 *     - value: Whether or not the value of this line item should be added to the
 *         order total. (Ex: would be TRUE for a shipping charge line item but
 *         FALSE for the subtotal line item since the product prices are already
 *         taken into account.)
 *   - "display_only"
 *     - type: boolean
 *     - value: Whether or not this line item is simply a display of information
 *         but not calculated anywhere. (Ex: the total line item uses display to
 *         simply show the total of the order at the bottom of the list of line
 *         items.)
 */
function hook_line_item() {
  
$items[] = array(
    
'id' => 'generic',
    
'title' => t('Empty Line'),
    
'weight' => 2,
    
'default' => FALSE,
    
'stored' => TRUE,
    
'add_list' => TRUE,
    
'calculated' => TRUE,
    
'callback' => 'uc_line_item_generic',
  );

  return 

$items;
}
?>
Аватар пользователя artanna@drupal.org artanna@drupal.org 22 апреля 2010 в 3:05

Этот пример у меня никакого эффекта не имеет. Равно как и модуль Fee - делаю это Фи, она показывается в продукте но при добавлении в корзину нет этой фии ни в каком виде и в checkoute ее нет. И в дебагере эта функция не перехватывается.

Кто работал с Fee - как она должна проявить себя?