在Symfony / php下的bdd中插入命令

问题描述

我正在建立一个电子商务网站。购物车,它的显示和通过Stripe的付款方式都有效。付款有效后,我想在数据库中注册整个订单。我只是碰巧保存了购物车的最后一行。为了制造购物车,我在YouTube上使用了Lior Chamla的教程。

这是购物车的代码:

    $panierWithData = [];

    foreach ($panier as $id => $quantity) {
        $panierWithData[] = [
            'product' => $repasRepository->find($id),'quantity' => $quantity
        ];
    }

    dd($panierWithData);

    $total = 0;
    foreach ($panierWithData as $item) {
        $totalItem = $item['product']->getPrix() * $item['quantity'];
        $total += $totalItem;
    }


    return $this->render('panier/index.html.twig',[
        'items' => $panierWithData,'total' => $total
    ]);
}

通过Stripe进行付款并结帐。

付款完成后,尽管我使用for函数扫描数组的索引,但我写的是这个,我只有要注册​​的数组的最后一行。您将在下面看到保存在bdd中的函数以及$ panierWithData数组的转储和消亡。

  if ('success_url') {
            $commande = new Commande();
            for ($i = 0; $i < count($panierWithData ); $i++) {
                $commande->setProduit($panierWithData [$i]['product']->getProduit());
                $commande->setQuantite($panierWithData [$i]['quantity']);

            $commande->setTotal($total);
            $commande->setUser($this->getUser());
            $em->persist($commande);
            $em->flush();
    }
        }

dd($panierWithData)

为什么我不能将订单的所有行都保存在数据库中?我该怎么办?

预先感谢您的帮助。

皮质

维维安

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...