バージョン選択

フォーラム

メニュー

オンライン状況

41 人のユーザが現在オンラインです。 (31 人のユーザが フォーラム を参照しています。)
登録ユーザ: 0
ゲスト: 41
もっと...

サイト内検索

質問 > フロント機能 > カート画面での商品単位の指定個数への変更処理

フロント機能

新規スレッドを追加する

スレッド表示 | 新しいものから 前のトピック | 次のトピック | 下へ
投稿者 スレッド
be-s
投稿日時: 2021/3/29 17:48
対応状況: −−−
一人前
登録日: 2016/2/2
居住地: São Paulo
投稿: 115
カート画面での商品単位の指定個数への変更処理
EC-CUBE] 4.0.4
[レンタルサーバ] AWS
[OS] Linux
[PHP] 7.3.14
[データベース] MySQL 5.7.28
[WEBサーバ] Apache/2.4.25
[ブラウザ] Chrome
[現象]


カート画面でセレクトボックスなどを使って
商品単位での商品の個数を変更したいのですが
バック側の処理は、
下記のように

CartController.phpの
handleCartItem
を変更するだけで可能でしょうか?
宜しくお願いいたします


/**
     * カート明細の加算/減算/削除を行う.
     *
     * - 加算
     *      - 明細の個数を1増やす
     * - 減算
     *      - 明細の個数を1減らす
     *      - 個数が0になる場合は、明細を削除する
     * - 削除
     *      - 明細を削除する
     *
     * @Route(
     *     path="/cart/{operation}/{productClassId}/{changeAmount},
     *     name="cart_handle_item",
     *     methods={"PUT"},
     *     requirements={
     *          "operation": "up|down|remove|change",
     *          "productClassId": "\d+",
     *          "changeAmount": "\d+"
     *     }
     * )
     */
    public function handleCartItem($operation, $productClassId,$chanheAmount)
    {        
        log_info('カート明細操作開始', ['operation' => $operation, 'product_class_id' => $productClassId]);

        $this->isTokenValid();

        /** @var ProductClass $ProductClass */
        $ProductClass = $this->productClassRepository->find($productClassId);

        if (is_null($ProductClass)) {
            log_info('商品が存在しないため、カート画面へredirect', ['operation' => $operation, 'product_class_id' => $productClassId]);

            return $this->redirectToRoute('cart');
        }

        // 明細の増減・削除
        switch ($operation) {
            case 'up':
                $this->cartService->addProduct($ProductClass, 1);
                break;
            case 'down':
                $this->cartService->addProduct($ProductClass, -1);
                break;
            case 'remove':
                $this->cartService->removeProduct($ProductClass);
                break;
            //個数変更商品単位個数指定変更
            case 'change':
                $nowAmount = "現在のカートの数";
                $differenceAmount = $nowAmount - $chanheAmount;

                $this->cartService->addProduct($ProductClass,$differenceAmount);
                break;
            //個数変更商品単位個数指定変更
        }

        // カートを取得して明細の正規化を実行
        $Carts = $this->cartService->getCarts();
        $this->execPurchaseFlow($Carts);

        log_info('カート演算処理終了', ['operation' => $operation, 'product_class_id' => $productClassId]);

        return $this->redirectToRoute('cart');
    }
スレッド表示 | 新しいものから 前のトピック | 次のトピック | トップ


 



ログイン


EC-CUBE公式 Amazon Payプラグイン

統計情報

総メンバー数は88,284名です
総投稿数は109,688件です

投稿数ランキング

1
seasoft
7365
2
468
3217
3
AMUAMU
2712
4
nanasess
2303
5
umebius
2085
6
yuh
1818
7
h_tanaka
1610
8
red
1567
9
mcontact
1240
10
tsuji
958
11
fukap
907
12
shutta
835
13
tao_s
796
14 ramrun 789
15 karin 689
16 sumida 641
17
homan
633
18 DELIGHT 572
19
patapata
502
20
flealog
485


ネットショップの壺

EC-CUBEインテグレートパートナー

Copyright© EC-CUBE CO.,LTD. All Rights Reserved.