PHP 클래스 OrderModifier, silvershop-core

This is especially useful for discounts or a shipping calculator. Based on what items are in the users cart, you could charge an additional amount to the order for shipping costs. There are three types of OrderModifiers (denoted by the "Type" enum field below): - 'None': This is for a state when you need to indicate to the user an amount, but it doesn't modify the total. (very useful for indicating tax on an order where tax is inclusive on the products being purchased) - 'Chargable': Charges an amount to the order. A good example of this would be shipping costs. - 'Deductable': Discounts an amount from the order. A good example is a discount being offered to the customer; a rewards scheme, or offering a 10% discount if the customer is a VIP or frequent customer. OrderModifiers can be as simple or as complex as needed. {@link OrderModifier::Amount()} returns the amount to be charged or discounted. The amount is calculated in {@link OrderModifier::calculateAmount()} (this should be implemented on your modifier classes). If the OrderModifier is saved to the DB (user has checked out), then {@link OrderModifier::Amount()} will return the amount from the DB instead of performing a calculation.
상속: extends DataObject
파일 보기 프로젝트 열기: burnbright/silverstripe-shop 1 사용 예제들

공개 메소드들

메소드 설명
Amount ( ) This function is always called to determine the amount this modifier needs to charge or deduct.
IsChargable ( ) : boolean Checks if this modifier has type = Chargable
TableValue ( ) Monetary to use in templates.
Total ( ) : boolean Provides a modifier total that is positive or negative, depending on whether the modifier is chargable or not.
canRemove ( ) : boolean Checks if the modifier can be removed.
modify ( $subtotal, $forcecalculation = false ) Modifies the incoming value by adding, subtracting or ignoring the value this modifier calculates.
required ( ) Specifies whether this modifier is always required in an order.
valid ( ) Check if the modifier should be in the cart.
value ( float $incoming ) Calculates value to store, based on incoming running total.

메소드 상세

Amount() 공개 메소드

If the modifier exists in the DB, in which case it already exists for a given order, we just return the Amount data field from the DB. This is for existing orders. If this is a new order, and the modifier doesn't exist in the DB ($this->ID is 0), so we return the amount from $this->LiveAmount() which is a calculation based on the order and it's items.
public Amount ( )

IsChargable() 공개 메소드

Checks if this modifier has type = Chargable
public IsChargable ( ) : boolean
리턴 boolean

TableValue() 공개 메소드

Monetary to use in templates.
public TableValue ( )

Total() 공개 메소드

Provides a modifier total that is positive or negative, depending on whether the modifier is chargable or not.
public Total ( ) : boolean
리턴 boolean

canRemove() 공개 메소드

Checks if the modifier can be removed.
public canRemove ( ) : boolean
리턴 boolean

modify() 공개 메소드

Sets $this->Amount to the calculated value;
public modify ( $subtotal, $forcecalculation = false )
$subtotal - running total to be modified
$forcecalculation - force calculating the value, if order isn't in cart

required() 공개 메소드

Specifies whether this modifier is always required in an order.
public required ( )

valid() 공개 메소드

Check if the modifier should be in the cart.
public valid ( )

value() 공개 메소드

Calculates value to store, based on incoming running total.
public value ( float $incoming )
$incoming float the incoming running total.