@@ -17,6 +17,13 @@ class CartCondition {
1717 */
1818 private $ args ;
1919
20+ /**
21+ * the parsed raw value of the condition
22+ *
23+ * @var
24+ */
25+ private $ parsedRawValue ;
26+
2027 /**
2128 * @param array $args (name, type, target, value)
2229 * @throws InvalidConditionException
@@ -86,6 +93,19 @@ public function applyCondition($totalOrSubTotalOrPrice)
8693 return $ this ->apply ($ totalOrSubTotalOrPrice , $ this ->getValue ());
8794 }
8895
96+ /**
97+ * get the calculated value of this condition supplied by the subtotal|price
98+ *
99+ * @param $totalOrSubTotalOrPrice
100+ * @return mixed
101+ */
102+ public function getCalculatedValue ($ totalOrSubTotalOrPrice )
103+ {
104+ $ this ->apply ($ totalOrSubTotalOrPrice , $ this ->getValue ());
105+
106+ return $ this ->parsedRawValue ;
107+ }
108+
89109 /**
90110 * apply condition
91111 *
@@ -106,25 +126,25 @@ protected function apply($totalOrSubTotalOrPrice, $conditionValue)
106126 {
107127 $ value = Helpers::normalizePrice ( $ this ->cleanValue ($ conditionValue ) );
108128
109- $ valueToBeSubtracted = $ totalOrSubTotalOrPrice * ($ value / 100 );
129+ $ this -> parsedRawValue = $ totalOrSubTotalOrPrice * ($ value / 100 );
110130
111- return floatval ($ totalOrSubTotalOrPrice - $ valueToBeSubtracted );
131+ $ result = floatval ($ totalOrSubTotalOrPrice - $ this -> parsedRawValue );
112132 }
113133 else if ( $ this ->valueIsToBeAdded ($ conditionValue ) )
114134 {
115135 $ value = Helpers::normalizePrice ( $ this ->cleanValue ($ conditionValue ) );
116136
117- $ valueToBeSubtracted = $ totalOrSubTotalOrPrice * ($ value / 100 );
137+ $ this -> parsedRawValue = $ totalOrSubTotalOrPrice * ($ value / 100 );
118138
119- return floatval ($ totalOrSubTotalOrPrice - $ valueToBeSubtracted );
139+ $ result = floatval ($ totalOrSubTotalOrPrice + $ this -> parsedRawValue );
120140 }
121141 else
122142 {
123143 $ value = Helpers::normalizePrice ($ conditionValue );
124144
125- $ valueToBeSubtracted = $ totalOrSubTotalOrPrice * ($ value / 100 );
145+ $ this -> parsedRawValue = $ totalOrSubTotalOrPrice * ($ value / 100 );
126146
127- return floatval ($ totalOrSubTotalOrPrice + $ valueToBeSubtracted );
147+ $ result = floatval ($ totalOrSubTotalOrPrice + $ this -> parsedRawValue );
128148 }
129149 }
130150
@@ -134,23 +154,25 @@ protected function apply($totalOrSubTotalOrPrice, $conditionValue)
134154 {
135155 if ( $ this ->valueIsToBeSubtracted ($ conditionValue ) )
136156 {
137- $ value = Helpers::normalizePrice ( $ this ->cleanValue ($ conditionValue ) );
157+ $ this -> parsedRawValue = Helpers::normalizePrice ( $ this ->cleanValue ($ conditionValue ) );
138158
139- return floatval ($ totalOrSubTotalOrPrice - $ value );
159+ $ result = floatval ($ totalOrSubTotalOrPrice - $ this -> parsedRawValue );
140160 }
141161 else if ( $ this ->valueIsToBeAdded ($ conditionValue ) )
142162 {
143- $ value = Helpers::normalizePrice ( $ this ->cleanValue ($ conditionValue ) );
163+ $ this -> parsedRawValue = Helpers::normalizePrice ( $ this ->cleanValue ($ conditionValue ) );
144164
145- return floatval ($ totalOrSubTotalOrPrice + $ value );
165+ $ result = floatval ($ totalOrSubTotalOrPrice + $ this -> parsedRawValue );
146166 }
147167 else
148168 {
149- $ value = Helpers::normalizePrice ($ conditionValue );
169+ $ this -> parsedRawValue = Helpers::normalizePrice ($ conditionValue );
150170
151- return floatval ($ totalOrSubTotalOrPrice + $ value );
171+ $ result = floatval ($ totalOrSubTotalOrPrice + $ this -> parsedRawValue );
152172 }
153173 }
174+
175+ return $ result ;
154176 }
155177
156178 /**
0 commit comments