Hi everyone,
I have created a bespoke quote form which is connected to my PrestaShop Database.
I am trying to now add a Quantity field which allows the user to type in a number of their choice which will then automatically update the price of the product; for example – if Product A is £20.00 and they change the quantity to 5, then Product A becomes £100.
How can I do this? What is this best way to go about this?
Any help is greatly appreciated!
I have provided my code below:
[CODE]
<?php
$servername = ‘REMOVED’;
$username = ‘REMOVED’;
$password = ‘REMOVED’;
$dbname = ‘REMOVED’;
try {
$conn = new PDO(“mysql:host=$servername;dbname=$dbname”, $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare(“SELECT id_product, price, unity FROM ps_product”);
$stmt->execute();
$product = $stmt->fetchAll();
echo ‘<div class=”table-responsive”>’;
echo ‘<table class=”table table-striped”>’;
echo ‘<th>Checkbox</th><th>Product Reference</th><th>Product Name</th><th>Price</th><th>Unit</th>’;
foreach ($product as $rowProd) {
$stmt = $conn->prepare(“SELECT reference, price FROM ps_product_attribute WHERE id_product = “. $rowProd[“id_product”] .””);
$stmt->execute();
$attribute = $stmt->fetchAll();
$stmt = $conn->prepare(“SELECT name FROM ps_product_lang WHERE id_product = “. $rowProd[“id_product”] .””);
$stmt->execute();
$name = $stmt->fetchAll();
foreach ($name as $rowName) {
$productName = $rowName[‘name’];
}
foreach ($attribute as $rowAttr) {
if($rowAttr[“price”] == 0 OR $rowAttr[“price”] < $rowProd[“price”]) {
$rowAttr[“price”] = $rowAttr[“price”] + $rowProd[“price”];
}
if($rowProd[“unity”] == false) {
$rowProd[“unity”] = 1;
}
$reference = ‘Reference’;
$price = ‘Price’;
$unit = ‘Unit’;
print ‘<tr>’;
print ‘<td><input type=”checkbox” name=”product[]” value=”‘. $rowAttr[“reference”] .’;’. $productName .’;’. number_format($rowAttr[“price”], 2) .’;’. $rowProd[“unity”] .'”></td>’;
print ‘<td>’. $rowAttr[“reference”] .'</td>’;
print ‘<td>’. $productName .'</td>’;
print ‘<td>£’. number_format($rowAttr[“price”], 2) .'</td>’;
print ‘<td>’. $rowProd[“unity”] .'</td>’;
print ‘</tr>’;
}
}
echo ‘</table>’;
echo ‘</div>’;
}
catch(PDOException $e) {
echo “Error: ” . $e->getMessage();
}
$conn = null;
?>