swipestripe
[ class tree: swipestripe ] [ index: swipestripe ] [ all elements ]

Class: Product

Source Location: /code/product/Product.php

Class Overview

Page
   |
   --Product

Represents a Product, which is a type of a Page. Products are managed in a seperate


Author(s):

Version:

  • 1.0

Copyright:

  • Copyright (c) 2011, Frank Mullenger

Variables

Methods



Class Details

[line 15]
Represents a Product, which is a type of a Page. Products are managed in a seperate

admin area ShopAdmin. A product can have Variations, in fact if a Product has attributes (e.g Size, Color) then it must have Variations. Products are Versioned so that when a Product is added to an Order, then subsequently changed, the Order can get the correct details about the Product.




Tags:

author:  Frank Mullenger <frankmullenger@gmail.com>
version:  1.0
copyright:  Copyright (c) 2011, Frank Mullenger


[ Top ]


Class Variables

static $allowed_currency = array(
    'NZD' => 'New Zealand Dollar'
  )

[line 33]

Currency allowed to be used for products Code match Payment::$site_currency Only one currency site wide allowed

TODO Set currency in a central location




Tags:

var:  Currency code indexes currency name
access:  public

Type:   Array


[ Top ]

static $belongs_many_many = array(    
    'ProductCategories' => 'ProductCategory'
  )

[line 80]

Belongs many many relations for Product


Type:   Array


[ Top ]

static $casting = array(
      'Category' => 'Varchar',
   )

[line 132]

Casting for searchable fields



Tags:

access:  public

Type:   Array


[ Top ]

static $db = array(
    'Amount' => 'Money'
  )

[line 42]

DB fields for Product.



Tags:

access:  public

Type:   Array


[ Top ]

static $defaults = array(
    'ParentID' => -1
  )

[line 89]

Defaults for Product



Tags:

access:  public

Type:   Array


[ Top ]

static $has_many = array(
    'Images' => 'ProductImage',
    'Options' => 'Option',
    'Variations' => 'Variation'
  )

[line 60]

Has many relations for Product.



Tags:

access:  public

Type:   Array


[ Top ]

static $has_one = array(
    'StockLevel' => 'StockLevel'
  )

[line 51]

Has one relations for Product



Tags:

access:  public

Type:   Array


[ Top ]

static $many_many = array(
    'Attributes' => 'Attribute'
  )

[line 71]

Many many relations for Product



Tags:

access:  public

Type:   Array


[ Top ]

static $searchable_fields = array(
     'Title' => array(
         'field' => 'TextField',
         'filter' => 'PartialMatchFilter',
         'title' => 'Name'
      ),'Status'=>array('filter'=>'PublishedStatusSearchFilter','title'=>'Status'),'Category'=>array('filter'=>'ProductCategorySearchFilter',))

[line 111]

Searchable fields for searching for Products in the CMS



Tags:

access:  public

Type:   Array


[ Top ]

static $summary_fields = array(
    'FirstImage' => 'Image',
    'SummaryOfPrice' => 'Price',
     'Title' => 'Name',
    'Status' => 'Status',
    'SummaryOfCategories' => 'Categories'
   )

[line 98]

Summary fields for displaying Products in the CMS



Tags:

access:  public

Type:   Array


[ Top ]

$firstWrite =  false

[line 22]

Flag for denoting if this is the first time this Product is being written.



Tags:

access:  protected

Type:   Boolean


[ Top ]



Class Methods


static method set_allowed_currency [line 249]

static void set_allowed_currency( Array $currency)

Set the currency for all products. Must match site curency.

TODO set currency for entire site in central location




Tags:

access:  public


Parameters:

Array   $currency  

[ Top ]

method buildSQL [line 469]

SQLQuery buildSQL( [string $filter = ""], [string|array $sort = ""], [string|array $limit = ""], [string $join = ""], [ $restrictClasses = true], [string $having = ""], boolean $restictClasses)

Removing generic entries for "AmountAmount", "AmountCurrency" because they are ambiguous when two dataobjects have those columns



Tags:

return:  Query built.
access:  public


Parameters:

string   $filter   A filter to be inserted into the WHERE clause.
string|array   $sort   A sort expression to be inserted into the ORDER BY clause. If omitted, self::$default_sort will be used.
string|array   $limit   A limit expression to be inserted into the LIMIT clause.
string   $join   A single join clause. This can be used for filtering, only 1 instance of each DataObject will be returned.
boolean   $restictClasses   Restrict results to only objects of either this class of a subclass of this class
string   $having   A filter to be inserted into the HAVING clause.
   $restrictClasses  

[ Top ]

method duplicateProductImages [line 494]

void duplicateProductImages( DataObjectSet $images)

Duplicate product images, useful when duplicating a product.



Tags:

access:  protected


Parameters:

DataObjectSet   $images  

[ Top ]

method FirstImage [line 508]

Image FirstImage( )

Get the first Image of all Images attached to this Product.



Tags:

access:  public


[ Top ]

method getCMSFields [line 266]

FieldSet getCMSFields( )

Set some CMS fields for managing Product images, Variations, Options, Attributes etc.



Tags:

access:  public


[ Top ]

method getCMSValidator [line 614]

ProductAdminValidator getCMSValidator( )

Set custom validator for validating EditForm in ShopAdmin. Not currently used.

TODO could use this custom validator to check variations perhaps




[ Top ]

method getOptionsForAttribute [line 564]

DataObjectSet getOptionsForAttribute( Int $attributeID)

Get options for an Attribute of this Product.



Tags:

access:  public


Parameters:

Int   $attributeID  

[ Top ]

method getParentType [line 652]

String getParentType( )

Get parent type for Product, extra parent type of exempt where the product is not part of the site tree (instead associated to product categories).



Tags:

return:  Returns root, exempt or subpage


[ Top ]

method getUnprocessedQuantity [line 706]

Array getUnprocessedQuantity( )

Get the quantity of this product that is currently in shopping carts or unprocessed orders



Tags:

return:  Number in carts and number in orders


[ Top ]

method inheritedDatabaseFields [line 438]

Array inheritedDatabaseFields( )

Hack to set Amount field in the array of database fields for this Product.

Helps to ensure a new version is created when Amount (type of Money) is changed on a Product.




Tags:

access:  public


[ Top ]

method InStock [line 672]

Boolean InStock( )

Product is in stock if stock level for product is != 0 or if ANY of its product variations is in stock.



Tags:

access:  public


[ Top ]

method Link [line 538]

String Link( [ $action = null])

Get the URL for this Product, products that are not part of the SiteTree are displayed by the Product_Controller.



Parameters:

   $action  

[ Top ]

method onAfterDelete [line 235]

void onAfterDelete( )

Unpublish products if they get deleted, such as in product admin area



[ Top ]

method onAfterWrite [line 205]

void onAfterWrite( )

Copy the original product options or generate the default product options



[ Top ]

method onBeforeWrite [line 173]

void onBeforeWrite( )

Set firstWrite flag if this is the first time this Product is written.

If this product is a child of a ProductCategory, make sure that ProductCategory is in the ProductCategories for this Product.




[ Top ]

method requiresVariation [line 553]

Boolean requiresVariation( )

A product is required to be added to a cart with a variation if it has attributes.

A product with attributes needs to have some enabled Variations




Tags:

access:  public


[ Top ]

method scaffoldSearchFields [line 142]

FieldSet scaffoldSearchFields( )

Filter for order admin area search.



[ Top ]

method SummaryOfCategories [line 519]

String SummaryOfCategories( )

Summary of product categories for convenience, categories are comma seperated.



[ Top ]

method SummaryOfPrice [line 623]

String SummaryOfPrice( )

Summary of price for convenience



Tags:

return:  Amount formatted with Nice()


[ Top ]

method updateStockBy [line 635]

Void updateStockBy( Int $quantity)

Update the stock level for this Product. A negative quantity is passed when product is added to a cart, a positive quantity when product is removed from a cart.



Tags:

access:  public


Parameters:

Int   $quantity  

[ Top ]

method validate [line 585]

ValidationResult validate( )

Validate the Product before it is saved in ShopAdmin.



Tags:

access:  public


[ Top ]


Documentation generated on Thu, 08 Mar 2012 16:47:28 +1300 by phpDocumentor 1.4.4