Skip to content

Commit

Permalink
Remove uneccisary DB call
Browse files Browse the repository at this point in the history
  • Loading branch information
mlewis-everley committed Oct 21, 2014
1 parent 41c3b13 commit 6f753d3
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions code/extensions/CustomisableProductShoppingCart.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@ class CustomisableProductShoppingCart extends Extension {
*/
public function augmentSetup() {
foreach($this->owner->Items as $item) {
$object = ($item->StockID) ? CatalogueProduct::get()->filter("StockID", $item->StockID)->first() : null;
if($item->Customisations && is_array($item->Customisations)) {
$base_price = $item->Price->RAW();
$customisations = ArrayList::create();

if($object) {
if($item->Customisations && is_array($item->Customisations)) {
$base_price = $item->Price->RAW();
$customisations = ArrayList::create();

foreach($item->Customisations as $customisation) {
if($customisation['Price'])
$base_price += $customisation['Price'];

$customisations->add($customisation);
}
foreach($item->Customisations as $customisation) {
if($customisation['Price'])
$base_price += $customisation['Price'];

$item->Customisations = $customisations;
$item->Price->setValue($base_price);
$customisations->add($customisation);
}

// If tax rate set work out tax
if($item->TaxRate) {
$tax = new Currency("Tax");
$tax->setValue(($item->Price->RAW() / 100) * $item->TaxRate);
$item->Tax = $tax;
}
$item->Customisations = $customisations;
$item->Price->setValue($base_price);
}

// If tax rate set work out tax
if($item->TaxRate) {
$tax = new Currency("Tax");
$tax->setValue(($item->Price->RAW() / 100) * $item->TaxRate);
$item->Tax = $tax;
}
}
}
Expand Down

0 comments on commit 6f753d3

Please sign in to comment.