We're using the built in Paypal Standard payment system on Opencart but it is not pulling the option price to Paypal.
Here is the code we have in our pp_standard.tpl file
<?php $i = 1; ?>
<?php foreach ($products as $product) { ?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['name']; ?>" />
<input type="hidden" name="item_number_<?php echo $i; ?>" value="<?php echo $product['model']; ?>" />
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['price']; ?>" />
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $product['quantity']; ?>" />
<input type="hidden" name="weight_<?php echo $i; ?>" value="<?php echo $product['weight']; ?>" />
<?php $j = 0; ?>
<?php foreach ($product['option'] as $option) { ?>
<input type="hidden" name="on<?php echo $j; ?>_<?php echo $i; ?>" value="<?php echo $option['value']; ?>" />
<input type="hidden" name="os<?php echo $j; ?>_<?php echo $i; ?>" value="<?php echo $option['price']; ?>" />
<?php $j++; ?>
<?php } ?>
<?php $i++; ?>
<?php } ?>
I think the line that is the issue is this
<input type="hidden" name="os<?php echo $j; ?>_<?php echo $i; ?>"
value="<?php echo $option['price']; ?>" />
But I am not sure what to change it to for Paypal to pull the correct price
Here is the code that shows the price in the cart.tpl file
<?php foreach ($product['option'] as $option) { ?>
- <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?>
- Price: <?php echo $option['price']; ?></small><br />
Related
In my code for shopping cart, sessions are not formed dynamically. I want to create session in this page and use sessions on the other page for item cart details.
How do I solve this problem?
<form method="post" action="men.php?action=add&id=<?php echo
$product['id']; ?>">
<img src="<?php echo $product['image'];?>">
<img class="hover-img" src="<?php echo $product['h_image'];?>" >
<p><?php echo $product['price'];?></p>
<h6><?php echo $product['name'];?></h6>
<input type="hidden" name="id" value="<?php echo $product['id']; ?>" />
<input type="hidden" name="hidden_name" value="<?php echo
$product['name']; ?>" />
<input type="hidden" name="hidden_price" value="<?php echo
$product['price']; ?>" />
<input type="hidden" name="hidden_image" value="<?php echo
$product['image']; ?>" />
Quantity <input type="text" class="form-control" name="qty" value="1" /><br>
<input type="submit" name="cart" value="Add to Cart" />
</form>
<?php
session_start();
if(isset($_POST['cart']))
{
// not working
if(isset($_SESSION['shopping_cart']))
{
$count= count($_SESSION['shopping_cart']);
$product_ids= array_column($_SESSION['shopping_cart'],'id');
if(!in_array(filter_input(INPUT_GET,'id'), $product_ids))
{
$_SESSION['shopping_cart'][$count]=array
(
'id'=> filter_input(INPUT_GET,'id'),
'name'=> filter_input(INPUT_POST,'hidden_name'),
'price'=> filter_input(INPUT_POST,'hidden_price'),
'quantity'=> filter_input(INPUT_POST,'qty'),
'image'=> filter_input(INPUT_POST,'hidden_image')
);
}
else
{
for($i=0; $i<count($product_ids); $i++)
{
if($product_ids[$i]==filter_input(INPUT_GET,'id'))
{
$_SESSION['shopping_cart'][$i]['quantity']+=
filter_input(INPUT_POST,'quantity');
}
}
}
}
else
{
}
}
?>
Sara. The session_start(); should be the first line in your document.
So, it should look like:
<?php session_start(); ?>
and then the rest of your work
NOTE : IF IT STILL NOT WORKING PLEASE PROVIDE THE ERROR.
Just that, here's some of he code i use
<?php
include('lib_carrito.php');
session_start();
?>
<form action="mete_producto.php" method="POST">
<input type="hidden" name="producto" value="<?php echo $nombre ?>">
<input type="hidden" name="precio" value="<?php echo $precio ?>">
<input type="hidden" name="producto" value="<?php echo $Id ?>">
<?php
if ($stock == 0 || !(isset($_SESSION['usuario'])) || $_SESSION['autoridad'] == 1) {
echo "<input type='submit' class='disabled' value='Añadir al carrito'>";
}
else{
echo "<input type='submit' class='añadir' value='Añadir al carrito'>";
}
?>
<select name="cantidad" style="height:35px; font-size: 25px">
<?php
for ($i=1; $i <= $stock; $i++) {
echo "<option value='".$i."'>".$i."</option>";
}
?>
</select>
</form>
That's on the page with the item the customer would buy,
then this is mete_producto.php
<?php
include("lib_carrito.php");
require('config.php');
session_start();
$_SESSION['ocarrito']->introduce_producto($_REQUEST["Id"], $_REQUEST["Nombre"], $_REQUEST["Precio"], $_REQUEST['Cantidad']);
//header("Location:index.php");
?>
I have the header as a comment so it would show me the errors,
for all of them is the same error 'Undefined index: Id'
You haven't defined either Id or Nombre as name attributes to be sent with your form. You have, however, assigned two producto names which have corresponding PHP variables. I assume this is how you are intending to use these variables.
Instead of:
<input type="hidden" name="producto" value="<?php echo $nombre ?>">
<input type="hidden" name="precio" value="<?php echo $precio ?>">
<input type="hidden" name="producto" value="<?php echo $Id ?>">
You're looking for:
<input type="hidden" name="nombre" value="<?php echo $nombre ?>">
<input type="hidden" name="precio" value="<?php echo $precio ?>">
<input type="hidden" name="Id" value="<?php echo $Id ?>">
I have two questions with radio button (each question having 4 radio) in PHP
But there is single check in all 8 radio buttons, but it should be, with 4-4 radio buttons.
Look: https://imgur.com/Sytl72a
My Code:
<form method="post" enctype="multipart/form-data" class="form-horizontal">
<?php
$lstmt = $user->runQuery("SELECT * FROM mcq WHERE LRN=:lrn ORDER BY Sr ASC ");
$lstmt->bindparam(":lrn",$id);
$lstmt->execute();
if($lstmt->rowCount() > 0)
{
$i=0;
while($lrow=$lstmt->fetch(PDO::FETCH_ASSOC))
{
extract($lrow);
$i++;
?>
<div>
<h1><?php echo $i; ?>) <?php echo $Question; ?></h1></br>
<h2> <input type="radio" name="radio" value="<?php echo $Oa; ?>"> A) <?php echo $Oa; ?></h2>
<h2> <input type="radio" name="radio" value="<?php echo $Ob; ?>"> B) <?php echo $Ob; ?></h2>
<h2> <input type="radio" name="radio" value="<?php echo $Oc; ?>"> C) <?php echo $Oc; ?></h2>
<h2> <input type="radio" name="radio" value="<?php echo $Od; ?>"> D) <?php echo $Od; ?></h2>
</div>
<hr></br></br>
<?php
}
}
?>
<button class="btn btn-large btn-primary" type="submit" name="btn-submit">Submit</button>
</form>
<?php
}
if(isset($_POST['btn-submit']))
{
echo $ufname = trim($_POST['radio']);
}
?>
Update your radio input name attribute just like this,
<div>
<h1><?php echo $i; ?>) <?php echo $Question; ?></h1></br>
<h2> <input type="radio" name="radio<?php echo $i; ?>?>" value="<?php echo $Oa; ?>"> A) <?php echo $Oa; ?></h2>
<h2> <input type="radio" name="radio<?php echo $i; ?>" value="<?php echo $Ob; ?>"> B) <?php echo $Ob; ?></h2>
<h2> <input type="radio" name="radio<?php echo $i; ?>" value="<?php echo $Oc; ?>"> C) <?php echo $Oc; ?></h2>
<h2> <input type="radio" name="radio<?php echo $i; ?>" value="<?php echo $Od; ?>"> D) <?php echo $Od; ?></h2>
</div>
And for submitting:
<?php
}
$count = $i;
for($j = 1; $j <= $count; $j++){ if(isset($_POST['btn-submit'])) {
echo $ufname = trim($_POST['radio'.$j]);
}
}
?>
It will definitely solve your problem,
The id is passing correctly but the post value is returning as empty , Please suggest with a solution what mistake i am doing here
Here is my view
<?php for($i=0;$i<count($array['value']);$i++) { ?>
<?php $id= $room['value'][$i]['Index']; ?>
<ul >
<li>
<?php echo form_open('cont/arraylist/'.$id); ?>
<input type="hidden" name="<?php echo 'foo'.$i ?>" value="<?php echo $room['value'][$i]['foo']?>" />
<input type="hidden" name="<?php echo 'boo'.$i?>" value="<?php echo $room['value'][$i]['boo']?>" />
<input type="hidden" name="<?php echo 'bar'.$i?>" value="<?php echo $room['value'][$i]['bar']?>" />
<input type="hidden" name="<?php echo 'baba'.$i?>" value="<?php echo $room['value'][$i]['baba']?>" />
<input type="submit" />
<?php echo form_close(); ?>
</li>
</ul>
<?php } ?>
Here is My controller
function arraylist($id)
{
echo $id;
echo $this->input->post('foo'.$id);
echo $this->input->post('boo'.$id);
echo $this->input->post('bar'.$id);
echo $this->input->post('baba'.$id);
}
You are trying get the input name 'foo'.$id but in view you are concatenating 'foo'.$i. This occurs to all. Do this:
<input type="hidden" name="<?php echo 'foo'.$id ?>" value="<?php echo $room['value'][$i]['foo']?>" />
<input type="hidden" name="<?php echo 'boo'.$id?>" value="<?php echo $room['value'][$i]['boo']?>" />
<input type="hidden" name="<?php echo 'bar'.$id?>" value="<?php echo $room['value'][$i]['bar']?>" />
<input type="hidden" name="<?php echo 'baba'.$id?>" value="<?php echo $room['value'][$i]['baba']?>" />
We're using the built in Paypal Standard payment system on Opencart but it is not pulling the option price to Paypal.
Here is the code we have in our pp_standard.tpl file
<?php $i = 1; ?>
<?php foreach ($products as $product) { ?>
<input type="hidden" name="item_name_<?php echo $i; ?>" value="<?php echo $product['name']; ?>" />
<input type="hidden" name="item_number_<?php echo $i; ?>" value="<?php echo $product['model']; ?>" />
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['price']; ?>" />
<input type="hidden" name="quantity_<?php echo $i; ?>" value="<?php echo $product['quantity']; ?>" />
<input type="hidden" name="weight_<?php echo $i; ?>" value="<?php echo $product['weight']; ?>" />
<?php $j = 0; ?>
<?php foreach ($product['option'] as $option) { ?>
<input type="hidden" name="on<?php echo $j; ?>_<?php echo $i; ?>" value="<?php echo $option['value']; ?>" />
<input type="hidden" name="os<?php echo $j; ?>_<?php echo $i; ?>" value="<?php echo $option['price']; ?>" />
<?php $j++; ?>
<?php } ?>
<?php $i++; ?>
<?php } ?>
I think the line that is the issue is this
<input type="hidden" name="os<?php echo $j; ?>_<?php echo $i; ?>"
value="<?php echo $option['price']; ?>" />
But I am not sure what to change it to for Paypal to pull the correct price
Here is the code that shows the price in the cart.tpl file
<?php foreach ($product['option'] as $option) { ?>
- <small><?php echo $option['name']; ?>: <?php echo $option['value']; ?>
- Price: <?php echo $option['price']; ?></small><br />
you can't use counter with paypal standard hidden inputs like amount, item_name and other hidden inputs inside foreach
<input type="hidden" name="amount_<?php echo $i; ?>" value="<?php echo $product['price']; ?>" />
in your case, paypal is looking request from input="amount" and you are posting request through input="amount_1"