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"
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 ?>">
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 />
I have a form which consists of rows set up like:
<div class="row unit" onmouseover="this.style.background = '#eeeeee';" onmouseout="this.style.background = 'white';" onclick="if(event.srcElement.nodeName != 'INPUT' && event.srcElement.nodeName != 'SELECT' && event.srcElement.nodeName != 'TEXTAREA'){goToByScroll(event.srcElement,-160);}">
<div class="col">
<div class="select">
<input type="checkbox" id="select<?php echo $i; ?>" name="select<?php echo $i; ?>">
</div>
</div>
<div class="col name">
<p><input class="searchable" type="text" id="name<?php echo $i; ?>" name="name<?php echo $i; ?>" value="<?php echo $name; ?>"></p>
<p>Badge ID: <input class="searchable" type="text" id="badge<?php echo $i; ?>" name="badge<?php echo $i; ?>" value="<?php echo $badge; ?>" style="width: 50px;"></p>
</div>
<div class="col phone">
<p>Work: <input class="searchable" type="text" id="phone<?php echo $i; ?>" name="phone<?php echo $i; ?>" value="<?php echo $phone; ?>"></p>
<p>Cell: <input class="searchable" type="text" id="cell<?php echo $i; ?>" name="cell<?php echo $i; ?>" value="<?php echo $cell; ?>"></p>
<p>Home: <input class="searchable" type="text" id="home<?php echo $i; ?>" name="home<?php echo $i; ?>" value="<?php echo $home; ?>"></p>
</div>
<div class="col email">
<p>Work: <input class="searchable" type="text" id="email<?php echo $i; ?>" name="email<?php echo $i; ?>" value="<?php echo $email; ?>"></p>
<p>Personal: <input class="searchable" type="text" id="perEmail<?php echo $i; ?>" name="perEmail<?php echo $i; ?>" value="<?php echo $perEmail; ?>"></p>
</div>
<div class="col file">
<p class="removeFile"><input type="text" id="filename<?php echo $i; ?>" name="filename<?php echo $i; ?>" class="file" value="<?php echo $filename; ?>" readonly>
Remove: <input type="checkbox" id="removeFile<?php echo $i; ?>" name="removeFile<?php echo $i; ?>"></p>
<input type="file" id="file<?php echo $i; ?>" name="file<?php echo $i; ?>" onchange="myForm.elements['filename<?php echo $i; ?>'].value=myForm.elements['file<?php echo $i; ?>'].value;">
</div>
</div>
These rows get repeated using a javascript function which increments the name:
function addTableRow(table){
for(i=0; i<myForm.elements['entriesNum'].value; i++){
var $tr = $(table).find(".row:last").clone();
$tr.find("input,select,textarea").attr("name", function(){
var parts = this.id.match(/(\D+)(\d+)$/);
return parts[1] + ++parts[2];
}).attr("id", function(){
var parts = this.id.match(/(\D+)(\d+)$/);
return parts[1] + ++parts[2];
});
$(table).find(".row:last").after($tr);
$tr.find('.fileElements').remove();
$tr.find('input[type!="radio"], textarea').removeAttr("value");
$tr.find('input').removeAttr("checked");
$tr.find('select option:first-child').attr("selected", true);
$tr.find('input[type!="radio"]').removeAttr("disabled");
$tr.find('input[type="radio"]').attr("disabled", "disabled");
$tr.find('.error').hide();
}
}
This works perfectly until the number of rows gets higher than 111. At this point when I submit no more data gets included in the array no matter how many rows I add. I was able to deduce this by using print_r($_REQUEST);. I have edited my php.ini and set all the maxes to be absurdly high with still no change.
Whenever I've had issues with javascript created form elements not showing up in the POST, it's always had to do with the way I've structured the FORM tags.
Things to look for...
Is your FORM tag properly closed off?
Is your FORM start and close at the same level in the DOM? For example, you wouldn't want to do this...
<form method='post'>
<div>
<!--lots of stuff-->
</form>
</div>
You would instead want this...
<form method='post'>
<div>
<!--lots of stuff-->
</div>
</form>
Do you have another FORM tag that's opened and not closed before the one you're actually working with? Like this...
<form method='get'>
<!--some kind of form about something else-->
<form method='post'>
<!--the data you're currently focused on-->
</form>