public function getModifier($className, $forcecreate = false)
    {
        if (!ClassInfo::exists($className)) {
            user_error("Modifier class \"$className\" does not exist.");
        }
        //search for existing
        $modifier = $className::get()
            ->filter("OrderID", $this->order->ID)
            ->first();
        if ($modifier) {
            //remove if no longer valid
            if (!$modifier->valid()) {
                //TODO: need to provide feedback message - why modifier was removed
                $modifier->delete();
                $modifier->destroy();
                return null;
            }
            return $modifier;
        }
        $modifier = new $className();
        if ($modifier->required() || $forcecreate) { //create any modifiers that are required for every order
            $modifier->OrderID = $this->order->ID;
            $modifier->write();
            $this->order->Modifiers()->add($modifier);

            return $modifier;
        }

        return null;
    }
public function getModifier($className, $forcecreate = false)
    {
        if (!ClassInfo::exists($className)) {
            user_error("Modifier class \"$className\" does not exist.");
        }
        //search for existing
        $modifier = $className::get()
            ->filter("OrderID", $this->order->ID)
            ->first();
        if ($modifier) {
            //remove if no longer valid
            if (!$modifier->valid()) {
                //TODO: need to provide feedback message - why modifier was removed
                $modifier->delete();
                $modifier->destroy();
                return null;
            }
            return $modifier;
        }
        $modifier = new $className();
        if ($modifier->required() || $forcecreate) { //create any modifiers that are required for every order
            $modifier->OrderID = $this->order->ID;
            $modifier->write();
            $this->order->Modifiers()->add($modifier);

            return $modifier;
        }

        return null;
    }
public function getModifier ( $ className , $ forcecreate = false ) { if ( ! ClassInfo :: exists ( $ className ) ) { user_error ( "Modifier class \"$className\" does not exist." ) ; } //search for existing $ modifier = $ className :: get ( ) -> filter ( "OrderID" , $ this -> order -> ID ) -> first ( ) ; if ( $ modifier ) { //remove if no longer valid if ( ! $ modifier -> valid ( ) ) { //TODO: need to provide feedback message - why modifier was removed $ modifier -> delete ( ) ; $ modifier -> destroy ( ) ; return null ; } return $ modifier ; } $ modifier = new $ className ( ) ; if ( $ modifier -> required ( ) || $ forcecreate ) { //create any modifiers that are required for every order $ modifier -> OrderID = $ this -> order -> ID ; $ modifier -> write ( ) ; $ this -> order -> Modifiers ( ) -> add ( $ modifier ) ; return $ modifier ; } return null ; }
Retrieve a modifier of a given class for the order.
Modifier will be retrieved from database if it already exists,
or created if it is always required.

@param string  $className
@param boolean $forcecreate - force the modifier to be created.
Retrieve a modifier of a given class for the order . Modifier will be retrieved from database if it already exists or created if it is always required .