1919use App \Base \Abstracts \Controllers \FrontendPageWithLang ;
2020use App \Base \Models \CartDiscount ;
2121use App \Base \Models \Discount as DiscountModel ;
22+ use App \Base \Models \Language ;
2223use Symfony \Component \HttpFoundation \Response ;
2324use RuntimeException ;
2425
@@ -84,7 +85,7 @@ public function beforeRender() : BasePage|Response
8485
8586 try {
8687 if (!isJson ($ actionDetails )) {
87- throw new RuntimeException ($ this ->getUtils ()->translate ('No action details provided. ' ));
88+ throw new RuntimeException ($ this ->getUtils ()->translate ('No action details provided. ' , locale: $ this -> getCurrentLocale () ));
8889 }
8990
9091 $ actionDetails = json_decode ($ actionDetails , true );
@@ -95,7 +96,7 @@ public function beforeRender() : BasePage|Response
9596 if (isset ($ actionDetails ['action ' ]) && $ actionDetails ['action ' ] === 'apply_discount ' ) {
9697 $ discountCode = $ actionDetails ['discount_code ' ] ?? '' ;
9798 if (empty ($ discountCode )) {
98- throw new RuntimeException ($ this ->getUtils ()->translate ('Discount code is required. ' ));
99+ throw new RuntimeException ($ this ->getUtils ()->translate ('Discount code is required. ' , locale: $ this -> getCurrentLocale () ));
99100 }
100101
101102 $ discount = DiscountModel::getCollection ()
@@ -107,13 +108,13 @@ public function beforeRender() : BasePage|Response
107108 ->getFirst ();
108109
109110 if (!$ discount ) {
110- throw new RuntimeException ($ this ->getUtils ()->translate ('Invalid or inactive discount code. ' ));
111+ throw new RuntimeException ($ this ->getUtils ()->translate ('Invalid or inactive discount code. ' , locale: $ this -> getCurrentLocale () ));
111112 }
112113
113114 $ this ->getCart ()->fullLoad ();
114115
115116 if (in_array ($ discount ->getId (), array_map (fn ($ d ) => $ d ->getInitialDiscountId (), $ this ->getCart ()->getDiscounts () ?? []))) {
116- throw new RuntimeException ($ this ->getUtils ()->translate ('Discount code already applied. ' ));
117+ throw new RuntimeException ($ this ->getUtils ()->translate ('Discount code already applied. ' , locale: $ this -> getCurrentLocale () ));
117118 }
118119
119120 try {
@@ -127,33 +128,33 @@ public function beforeRender() : BasePage|Response
127128 $ this ->getCart ()->calculate ()->persist ();
128129
129130 $ this ->addSuccessFlashMessage (
130- $ this ->getUtils ()->translate ('Discount applied successfully. ' )
131+ $ this ->getUtils ()->translate ('Discount applied successfully. ' , locale: $ this -> getCurrentLocale () )
131132 );
132133 } catch (\Exception $ e ) {
133134 throw new RuntimeException (
134- $ this ->getUtils ()->translate ('Failed to apply discount: ' . $ e ->getMessage ())
135+ $ this ->getUtils ()->translate ('Failed to apply discount: ' . $ e ->getMessage (), locale: $ this -> getCurrentLocale () )
135136 );
136137 }
137138 }
138139
139140 if (isset ($ actionDetails ['action ' ]) && $ actionDetails ['action ' ] === 'remove_discount ' ) {
140141 $ discountId = $ actionDetails ['discount_id ' ] ?? null ;
141142 if (!$ discountId ) {
142- throw new RuntimeException ($ this ->getUtils ()->translate ('Discount ID is required to remove a discount. ' ));
143+ throw new RuntimeException ($ this ->getUtils ()->translate ('Discount ID is required to remove a discount. ' , locale: $ this -> getCurrentLocale () ));
143144 }
144145
145146 $ cartDiscount = CartDiscount::load ($ discountId );
146147 if (!$ cartDiscount ) {
147148 throw new RuntimeException ($ this ->getUtils ()->translate ('Discount not found. ' ));
148149 }
149150 if ($ cartDiscount ->getCartId () !== $ this ->getCart ()->getId ()) {
150- throw new RuntimeException ($ this ->getUtils ()->translate ('Discount does not belong to this cart. ' ));
151+ throw new RuntimeException ($ this ->getUtils ()->translate ('Discount does not belong to this cart. ' , locale: $ this -> getCurrentLocale () ));
151152 }
152153
153154 $ cartDiscount ->delete ();
154155 $ this ->getCart ()->calculate ()->persist ();
155156 $ this ->addSuccessFlashMessage (
156- $ this ->getUtils ()->translate ('Discount removed successfully. ' )
157+ $ this ->getUtils ()->translate ('Discount removed successfully. ' , locale: $ this -> getCurrentLocale () )
157158 );
158159 }
159160
0 commit comments