\Variation
Represents a Variation for a Product. A variation needs to have a valid Option set for each Attribute that the product has e.g Size:Medium, Color:Red, Material:Cotton. Variations are Versioned so that when they are added to an Order and then changed, the Order can still access the correct information.
- Author: Frank Mullenger <frankmullenger@gmail.com>
- Copyright: Copyright (c) 2011, Frank Mullenger
Synopsis
class Variation
extends DataObject
implements
PermissionProvider
{
- // members
- private static Array $db = ;
- private static Array $has_one = ;
- private static Array $many_many = ;
- private static Array $summary_fields = ;
- private static Array $extensions = ;
- private static array $defaults = ;
- private static string $default_sort = 'SortOrder';
- // methods
- public void Amount()
- public void Price()
- public void providePermissions()
- public void canEdit()
- public void canView()
- public void canDelete()
- public void canCreate()
- public void __get()
- public Option getOptionForAttribute()
- public FieldList getCMSFields()
- public String SummaryOfOptions()
- public String SummaryOfOptionValueForAttribute()
- public String SummaryOfPrice()
- public ValidationResult validateForCart()
- public Boolean hasValidOptions()
- public Boolean isDuplicate()
- public Boolean isEnabled()
- public Boolean isDeleted()
- public Boolean isNegativeAmount()
- public ValidationResult validate()
- protected void onAfterWrite()
- public void onBeforeWrite()
Hierarchy
Extends
- DataObject
Implements
- PermissionProvider
Tasks
Line | Task |
---|---|
465 | this might not be a good idea to unpublish the product |
Members
private
- $db
—
Array
DB fields for a Variation - $default_sort
- $defaults
- $extensions
—
Array
Versioning for a Variation, so that Orders can access the version that was purchased and correct information can be retrieved. - $has_one
—
Array
Has one relation for a Variation - $many_many
—
Array
Many many relation for a Variation - $summary_fields
—
Array
Summary fields for displaying Variations in the CMS
Methods
protected
- onAfterWrite() — Unpublish {@link Product}s if after the Variations have been saved there are no enabled Variations.
public
- Amount()
- Price()
- SummaryOfOptionValueForAttribute() — Get attribute option value, helper method
- SummaryOfOptions() — Get a summary of the Options, helper method for displaying Options nicely
- SummaryOfPrice() — Summarize the Product price, returns Amount formatted with Nice()
- __get() — Overloaded magic method so that attribute values can be retrieved for display in CTFs etc.
- canCreate()
- canDelete()
- canEdit()
- canView()
- getCMSFields() — Add fields for editing a Variation in the CMS popup.
- getOptionForAttribute() — Get a Variation option for an attribute
- hasValidOptions() — Convenience method to check that this Variation has valid options.
- isDeleted() — Check if the variation has been deleted, need to check the actual variation and not just this version.
- isDuplicate() — Convenience method to check that this Variation is not a duplicate.
- isEnabled() — If current variation is enabled, checks lastest version of variation because status is saved in versions. So a variation can be saved as enabled, the version can be added to cart, then the variation is disabled but the previous version stays enabled.
- isNegativeAmount() — Check if {@link Variation} amount is a negative value
- onBeforeWrite() — Update stock level associated with this Variation.
- providePermissions()
- validate() — Validate the Variation before it is saved.
- validateForCart() — Validate that this variation is suitable for adding to the cart.