私は現在AngularJS、PHP、webservice、およびいくつかのhtml/cssとXMLを使ってショッピングアプリケーションを開発しています。既存のセッションでの計算の作成
私は現在カートセッションで作業しており、合計価格、合計アイテム数、およびVAT計算を作成する際に問題が発生しました。
セッションはPHPで書かれています。
<?php
session_start();
$product_id = $_REQUEST['product_id'];
$product_name = $_REQUEST['product_name'];
$product_price = round($_REQUEST['product_price'], 2);
$product_size = $_REQUEST['product_size'];
$product_quantity = $_REQUEST['product_quantity'];
$total_product_price = $product_price*$product_quantity;
round($total_product_price, 2);
$total_items = $_SESSION['cart'][$product_quantity];
// Add new item to session
$cartProduct = array(
"id" => $product_id,
"name" => $product_name,
"price" => $product_price,
"size" => $product_size,
"quantity" => $product_quantity,
"total_price" => $total_product_price,
"total_items" => $total_items
);
/*
* check if the 'cart' session array was created
* if it is NOT, create the 'cart' session array
*/
if(!isset($_SESSION['cart'])){
$_SESSION['cart'] = array();
}
// check if the item is in the array, if it is, do not add
if(array_key_exists($product_id and $product_size, $_SESSION['cart'])){
// redirect to product list and tell the user it was added to cart
echo "<script> alert('Dit product staat al in de winkelwagen')</script>])";
}
// else, add the item to the array
else{
$_SESSION['cart'][$product_id]=$cartProduct;
}
を上記のコードは、製品に関するすべての情報が要求された状態として:コードは、次の通りです。 product_id
のような要求されたアイテムはarray()
に設定されます。 array()
は、いくつかのチェックの後、セショーション:$_SESSION['cart'];
に追加されます。カートを追加して見せても問題ありません。私が抱えている問題は、カート内のtotal_items、カートのtotal_price、およびVAT計算を表示するのに必要な計算を作成することです。
さらに詳しい情報が必要な場合は、お知らせください。
ありがとうございます!あなたが3
の$product_quantity
を持っている場合
$_SESSION['cart'][$product_id]=$cartProduct;
そして
$cartProduct = array(
"id" => $product_id,
"name" => $product_name,
"price" => $product_price,
"size" => $product_size,
"quantity" => $product_quantity,
"total_price" => $total_product_price,
"total_items" => $total_items
);
だから、あなたが$product_id
を引いているので、これは私が見る問題
$total_items = $_SESSION['cart'][$product_quantity];
であなたのコードを見てみると
作成する前にセッションを使用している可能性がありますか? '$ total_items = $ _SESSION ['cart'] [$ product_quantity];' –