| @@ 135-170 (lines=36) @@ | ||
| 132 | * @Route("/shopping", name="shopping") |
|
| 133 | * @Template("Shopping/index.twig") |
|
| 134 | */ |
|
| 135 | public function index(Application $app, Request $request) |
|
| 136 | { |
|
| 137 | // カートチェック |
|
| 138 | $response = $app->forward($app->path("shopping_check_to_cart")); |
|
| 139 | if ($response->isRedirection() || $response->getContent()) { |
|
| 140 | return $response; |
|
| 141 | } |
|
| 142 | ||
| 143 | // 受注情報を初期化 |
|
| 144 | $response = $app->forward($app->path("shopping_initialize_order")); |
|
| 145 | if ($response->isRedirection() || $response->getContent()) { |
|
| 146 | return $response; |
|
| 147 | } |
|
| 148 | ||
| 149 | /** @var Order $Order */ |
|
| 150 | $Order = $this->parameterBag->get('Order'); |
|
| 151 | ||
| 152 | // 単価集計 |
|
| 153 | $flowResult = $this->executePurchaseFlow($app, $Order); |
|
| 154 | ||
| 155 | // フォームを生成する |
|
| 156 | $app->forward($app->path("shopping_create_form")); |
|
| 157 | ||
| 158 | if ($flowResult->hasWarning() || $flowResult->hasError()) { |
|
| 159 | return $app->redirect($app->url('cart')); |
|
| 160 | } |
|
| 161 | ||
| 162 | // 複数配送の場合、エラーメッセージを一度だけ表示 |
|
| 163 | $app->forward($app->path("shopping_handle_multiple_errors")); |
|
| 164 | $form = $this->parameterBag->get(OrderType::class); |
|
| 165 | ||
| 166 | return [ |
|
| 167 | 'form' => $form->createView(), |
|
| 168 | 'Order' => $Order, |
|
| 169 | ]; |
|
| 170 | } |
|
| 171 | ||
| 172 | /** |
|
| 173 | * 購入確認画面から, 他の画面へのリダイレクト. |
|
| @@ 179-210 (lines=32) @@ | ||
| 176 | * @Route("/shopping/redirect", name="shopping_redirect_to") |
|
| 177 | * @Template("Shopping/index.twig") |
|
| 178 | */ |
|
| 179 | public function redirectTo(Application $app, Request $request) |
|
| 180 | { |
|
| 181 | // カートチェック |
|
| 182 | $response = $app->forward($app->path("shopping_check_to_cart")); |
|
| 183 | if ($response->isRedirection() || $response->getContent()) { |
|
| 184 | return $response; |
|
| 185 | } |
|
| 186 | ||
| 187 | // 受注の存在チェック |
|
| 188 | $response = $app->forward($app->path("shopping_exists_order")); |
|
| 189 | if ($response->isRedirection() || $response->getContent()) { |
|
| 190 | return $response; |
|
| 191 | } |
|
| 192 | ||
| 193 | // フォームの生成 |
|
| 194 | $app->forward($app->path("shopping_create_form")); |
|
| 195 | $form = $this->parameterBag->get(OrderType::class); |
|
| 196 | $form->handleRequest($request); |
|
| 197 | ||
| 198 | // 各種変更ページへリダイレクトする |
|
| 199 | $response = $app->forward($app->path("shopping_redirect_to_change")); |
|
| 200 | if ($response->isRedirection() || $response->getContent()) { |
|
| 201 | return $response; |
|
| 202 | } |
|
| 203 | $form = $this->parameterBag->get(OrderType::class); |
|
| 204 | $Order = $this->parameterBag->get('Order'); |
|
| 205 | ||
| 206 | return [ |
|
| 207 | 'form' => $form->createView(), |
|
| 208 | 'Order' => $Order, |
|
| 209 | ]; |
|
| 210 | } |
|
| 211 | ||
| 212 | /** |
|
| 213 | * 購入処理 |
|
| @@ 219-254 (lines=36) @@ | ||
| 216 | * @Method("POST") |
|
| 217 | * @Template("Shopping/index.twig") |
|
| 218 | */ |
|
| 219 | public function confirm(Application $app, Request $request) |
|
| 220 | { |
|
| 221 | // カートチェック |
|
| 222 | $response = $app->forward($app->path("shopping_check_to_cart")); |
|
| 223 | if ($response->isRedirection() || $response->getContent()) { |
|
| 224 | return $response; |
|
| 225 | } |
|
| 226 | ||
| 227 | // 受注の存在チェック |
|
| 228 | $response = $app->forward($app->path("shopping_exists_order")); |
|
| 229 | if ($response->isRedirection() || $response->getContent()) { |
|
| 230 | return $response; |
|
| 231 | } |
|
| 232 | ||
| 233 | // form作成 |
|
| 234 | // FIXME イベントハンドラを外から渡したい |
|
| 235 | $app->forward($app->path("shopping_create_form")); |
|
| 236 | ||
| 237 | $form = $this->parameterBag->get(OrderType::class); |
|
| 238 | $Order = $this->parameterBag->get('Order'); |
|
| 239 | ||
| 240 | $form->handleRequest($request); |
|
| 241 | ||
| 242 | // 受注処理 |
|
| 243 | $response = $app->forward($app->path("shopping_complete_order")); |
|
| 244 | if ($response->isRedirection() || $response->getContent()) { |
|
| 245 | return $response; |
|
| 246 | } |
|
| 247 | ||
| 248 | log_info('購入チェックエラー', array($Order->getId())); |
|
| 249 | ||
| 250 | return [ |
|
| 251 | 'form' => $form->createView(), |
|
| 252 | 'Order' => $Order, |
|
| 253 | ]; |
|
| 254 | } |
|
| 255 | ||
| 256 | ||
| 257 | /** |
|