Ajustes personalizados

Los ajustes personalizados deben implementar la interfaz com.ibm.commerce.marketing.promotion.reward.Adjustment. A continuación, se proporciona su definición:


package com.ibm.commerce.marketing.promotion.reward;

import java.math.BigDecimal;
import java.util.Vector;

import com.ibm.commerce.marketing.promotion.runtime.LineItemSet;
import com.ibm.commerce.marketing.promotion.runtime.PromotionContext;
import com.ibm.commerce.marketing.promotion.runtime.PromotionRuntimeException;
import com.ibm.commerce.marketing.promotion.xml.XMLizable;

/**
 * <code>Adjustment</code> interface contains the methods common to
 * all adjustments.
 * This interface extends <code>XMLizable</code> and <code>Cloneable</code> 
 * interfaces. 
 * All the adjustments should implement this interface.
 */

public interface Adjustment extends XMLizable, Cloneable {
   /**
    * IBM copyright notice field.
    */
    public static final String COPYRIGHT =
          com.ibm.commerce.copyright.IBMCopyright.SHORT_COPYRIGHT;
       /**
        * Indicates Whole Order.
        */
        
    public static final Integer WHOLE_ORDER = new Integer(1);
       /**
        * Indicates all Affected Items.
        */

    public static final Integer ALL_AFFECTED_ITEMS = new Integer(2);
       /**
        * Indicates Individual Affected Items.
        */

    public static final Integer INDIVIDUAL_AFFECTED_ITEMS = new Integer(3);
       /**
        * This method gets the type of Adjustment. Adjustment can be one of the 
        * following types for whole Order, for All Affected Items, and for 
        * Individual Affected Items.
        * @return Integer  <code>1 </code> Order as a whole
        *                   <code>2 </code> All Affected Items
        *                   <code>3 </code> Individual Affected Items 
        */

    Integer getAdjustmentType();

       /**
        * This method sets the promotion level.
        * @return Integer <code>1 </code> Order as a whole
        *                   <code>2 </code> All Affected Items
        *                   <code>3 </code> Individual Affecte Items 
        */

    void setAdjustmentType(Integer adjustmentType);

       /**
        * Applies adjustment to affected order items
        * @param targeted targeted order items
        * @param affected affected order items
        * @param context PromotionExecutionContext
        * @return the actual adjustment
        * @throws PromotionRuntimeException when the computation 
        * encounters a problem
        */

    boolean apply(
          LineItemSet targeted, 
          BigDecimal targetedAmount,
          int targetedAmountTypes,
          LineItemSet affected,
          Vector affectedVector,
          Vector adjustmentVector,
          PromotionContext context)
          throws PromotionRuntimeException;
}

Esta interfaz también es una subclase de XMLizable. Las tres constantes declaradas en la interfaz representan tres modos diferentes en que un ajuste se adjunta a los artículos afectados. Examine el método de aplicación, que toma los parámetros siguientes:

LineItemSet targeted
Este parámetro de entrada es el conjunto de artículos de pedido (o partes de artículos de pedido) que se utilizan para tener derecho a la promoción de la que forma parte este ajuste.
BigDecimal targetedAmount
Actualmente, no se utiliza este parámetro de entrada y se pasará siempre un valor nulo a los ajustes.
int targetedAmountType
Este parámetro de entrada no se utiliza actualmente.
LineItemSet affected
Este parámetro de salida es el conjunto de artículos de pedido, identificados por la promoción, al que se adjuntará el ajuste.
Vector affectedVector
Es un parámetro de salida. Normalmente, cuando el método de aplicación finaliza, este vector aumenta en 1. El parámetro afectado se añade al final de este vector. Sin embargo, en determinadas situaciones, el método de aplicación puede dividir LineItemSet y aplicar ajustes diferentes a subconjuntos diferentes. En ese caso, todos los subconjuntos resultantes se añadirán a este vector
Vector adjustmentVector
Es un parámetro de salida. Normalmente, cuando el método de aplicación finaliza, este vector aumenta en 1. El ajuste se añade al final de este vector. Sin embargo, en determinadas situaciones, el método de aplicación puede dividir LineItemSet y aplicar ajustes diferentes a subconjuntos diferentes. En este caso, cada ajuste resultante se añade a este vector. Los elementos de affectedVector y este parámetro tienen una relación de uno a uno basada en el índice del vector.
PromotionContext context
Proporciona un contexto en el que se ejecuta el ajuste.

Existe un tipo especial de ajustes, denominado MonetaryAdjustments. Actualmente, en un entorno de minorista en línea, hay cuatro tipos diferentes de valores monetarios asociados con una compra. Son los siguientes: precio, envío y manipulación, impuestos e impuestos sobre el envío y la manipulación. Las promociones que cambian estos valores adjuntan un MonetaryAdjustment a los artículos afectados. MonetaryAdjustment es una subclase de la interfaz de ajuste. Por consiguiente, se aplican todos los detalles sobre los ajustes a MonetaryAdjustment. Además del ajuste, hay varias extensiones en MonetaryAdjustment. A continuación se proporciona la definición de interfaz:


package com.ibm.commerce.marketing.promotion.reward;

import java.math.BigDecimal;
import com.ibm.commerce.marketing.promotion.runtime.AssociatedOrderItem;
import com.ibm.commerce.marketing.promotion.runtime.PromotionContext;

public interface MonetaryAdjustment extends Adjustment {
       /**
        * IBM copyright notice field.
        */
       public static final String COPYRIGHT =
             com.ibm.commerce.copyright.IBMCopyright.SHORT_COPYRIGHT;

       /**
        * Adjustment is on the sub total of an order or a subset of an order.
        */
       public static final int PRICE = 1;
       
       /**
        * Adjustment is on the shipping charges of an order or a subset of an order.
        */
       public static final int SHIPPING = 2;

       /**
        * Adjustment is on the tax levied on the shipping charges of an order or a
        * subset of an order.
        */
       public static final int SHIPPING_TAX = 4;
       /**
        * Adjustment is on the tax levied on an order or a subset of an order
        */
       public static final int TAX = 8;

       /**
        * A simple BigDecimal constant value of 0.
        */
       public static final BigDecimal ZERO = new BigDecimal("0");

       /**
        * Returns the target of a monetary adjustmennt. Possible values are:
        * SUBTOTAL=1, SHIPPING=2, SHIPPING_TAX=4, TAX=8. 
        * @return target of a monetary adjustment
        */
       int getTheTypeOfMonetaryValueToBeAdjusted();

       /**
        * Returns the monetary adjustment that need to be apply to each unit of an order
        * item or a portion of an order item (as identified by the AssociationOrderItem).
        * It is guaranteed that all units in <code>one</code> have been adjusted by
        * exactly the same set of monetary adjustments.
        * @param one the order item or portion of an order item for which a per unit 
        * adjustment amount needs to be calculated.
        * @param all all of the AssociatedOrderItems to which this 
        * adjustment applies.
        * @param context PromotionContext
        * @return a perUnit value, value could be positive which means a discount, 
        * negative which means a markup, or zero which means no change is needed.
        */
       BigDecimal getPerUnitAdjustment(
              AssociatedOrderItem one,
              AssociatedOrderItem all[],
              PromotionContext context);
}

En comparación con la interfaz de ajuste, se han definido dos métodos adicionales. En primer lugar, el método getTheTypeOfMonetaryValueToBeAdjusted que devuelve un mapa de bits de valores que representan el valor monetario al que se aplica este ajuste. Se puede aplicar MonetaryAdjustment a varios valores monetarios si el mapa de bits devuelto por este método tiene más de 1 bit establecido en 1. En segundo lugar, el método BigDecimal, que utiliza la lógica de distribución de los ajustes monetarios definida por un MonetaryAdjustment a los artículos afectados individuales. Los comentarios de la definición de interfaz deben ser suficientes para explicar el comportamiento de este método.

Todos los ajustes monetarios deben implementar la interfaz MonetaryAdjustment.

Nota: Todas las implementaciones de ajuste personalizadas deben ser reentrantes y de proceso múltiple.

Una vez que ha implementado el ajuste de promoción, debe asegurarse de que el subsistema de pedidos soporta el ajuste. De forma predeterminada, se soportan los métodos de aplicación de ajuste siguientes:

  • WHOLE_ORDER
  • INDIVIDUAL_AFFECTED_ITEMS
  • ALL_AFFECTED_ITEMS