Skip to content

Instantly share code, notes, and snippets.

@hailwood
Created February 17, 2016 05:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hailwood/f0863d195dba5ad501f6 to your computer and use it in GitHub Desktop.
Save hailwood/f0863d195dba5ad501f6 to your computer and use it in GitHub Desktop.
<?php
class SomeDataObject extends DataObject
{
public function updateQuantity($newQuantity)
{
$beforeUpdateQuantity = $this->extend('onBeforeUpdateQuantity', $this, $newQuantity);
if ($beforeUpdateQuantity !== null) {
return $beforeUpdateQuantity;
}
$oldQuantity = $this->Quantity;
$this->extend('onUpdateQuantity', $this, $oldQuantity, $newQuantity);
if (!$newQuantity) {
return $this;
}
$this->Quantity = $newQuantity;
$this->write();
$this->extend('onAfterUpdateQuantity', $this, $oldQuantity, $newQuantity);
return $this;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment