Skip to content

Commit

Permalink
Added better CMS UI for price tiers
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Guinn committed Jan 7, 2015
1 parent c345711 commit 20c629f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
16 changes: 13 additions & 3 deletions code/HasPriceTiers.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,21 @@ public function getTierForQuantity($qty) {
* @param FieldList $fields
*/
public function updateCMSFields(FieldList $fields) {
$baseLabel = TextField::create('BasePriceLabel', 'Label for Base Tier');
$bp = $fields->fieldByName('Root.Pricing.BasePrice');
if ($bp) {
// Base price label
if ($bp = $fields->fieldByName('Root.Pricing.BasePrice')) {
$baseLabel = TextField::create('BasePriceLabel', 'Label for Base Tier');
$fields->addFieldToTab('Root.Pricing', $baseLabel, 'BasePrice');
}

// Price tier grid
$fields->addFieldToTab('Root.Pricing',
GridField::create(
'PriceTiers',
$this->owner instanceof SiteConfig ? 'Global Price Tiers' : 'Price Tiers',
$this->owner->PriceTiers(),
GridFieldConfig_RelationEditor::create()
)
);
}

}
Expand Down
19 changes: 19 additions & 0 deletions code/PriceTier.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ class PriceTier extends DataObject

private static $default_sort = 'MinQty';

private static $summary_fields = array(
'MinQty' => 'Min. Qty.',
'Label' => 'Label',
'Price' => 'Price',
'Percentage' => 'Percentage',
);

private static $searchable_fields = array('MinQty', 'Label', 'Price', 'Percentage');


/**
* Calculate the price for this tier from a given base price
Expand All @@ -45,5 +54,15 @@ public function calcPrice($price=0.0) {
if (!$price) $price = $this->Price;
return round($price * $this->Percentage, 2);
}


/**
* @return FieldList
*/
public function getCMSFields() {
$fields = parent::getCMSFields();
$fields->removeByName(array('ProductID', 'SiteConfigID'));
return $fields;
}
}

0 comments on commit 20c629f

Please sign in to comment.