问题描述
我正在建立一个电子商务网站。购物车,它的显示和通过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();
}
}
为什么我不能将订单的所有行都保存在数据库中?我该怎么办?
预先感谢您的帮助。
皮质
维维安
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)