public function doAddDiscount($data, $form)
    {
        $code_to_search = $data['DiscountCode'];

        // First check if the discount is already added (so we don't
        // query the DB if we don't have to).
        if (!$this->discount || ($this->discount && $this->discount->Code != $code_to_search)) {
            $code = Discount::get()
                ->filter("Code", $code_to_search)
                ->exclude("Expires:LessThan", date("Y-m-d"))
                ->first();

            if ($code) {
                $this->discount = $code;
            }
        }

        $this->save();

        return $this->redirectBack();
    }
public function doAddDiscount($data, $form)
    {
        $code_to_search = $data['DiscountCode'];

        // First check if the discount is already added (so we don't
        // query the DB if we don't have to).
        if (!$this->discount || ($this->discount && $this->discount->Code != $code_to_search)) {
            $code = Discount::get()
                ->filter("Code", $code_to_search)
                ->exclude("Expires:LessThan", date("Y-m-d"))
                ->first();

            if ($code) {
                $this->discount = $code;
            }
        }

        $this->save();

        return $this->redirectBack();
    }
public function doAddDiscount ( $ data , $ form ) { $ code_to_search = $ data [ 'DiscountCode' ] ; // First check if the discount is already added (so we don't // query the DB if we don't have to). if ( ! $ this -> discount || ( $ this -> discount && $ this -> discount -> Code != $ code_to_search ) ) { $ code = Discount :: get ( ) -> filter ( "Code" , $ code_to_search ) -> exclude ( "Expires:LessThan" , date ( "Y-m-d" ) ) -> first ( ) ; if ( $ code ) { $ this -> discount = $ code ; } } $ this -> save ( ) ; return $ this -> redirectBack ( ) ; }
Action that will find a discount based on the code

@param type $data
@param type $form
Action that will find a discount based on the code