CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Custom insert in store

Print topic Send  topic

Author Message
mavtech

Posts: 133
Posted: 11/16/2004, 6:47 AM

I have a store page - Shoppingcart it has a list of the products chosen.

Problem is the Price is a calculated field including an if statement. Price is actually based on a List price or a special price and is muliplied by a currency convertor.

I used before show on the label and a few hidden fields, it works great.

Now when I chose purchase it goes to an (ON CLICK) Sql custom code (very similiar to your store shopping cart page).

On your shopping cart you use (quantity * price) as Price. But in my case I want to use the Price in the grid above, however it is a code expression.

How do I access it - Mainly syntax is what I am after.

mySQL and PHP

Thanks

Paul
View profile  Send private message
tonyk

Posts: 163
Posted: 11/16/2004, 7:40 AM

As far as I know you can't get the data from a label. I think you will have to use a hidden text field to hold the value. Also are you doing your calculations on the client i.e. as javascript or on the server as php. This will make a great difference in the advice you will be given. So more information please:)
Tony
View profile  Send private message
mavtech

Posts: 133
Posted: 11/16/2004, 8:17 AM

I can put it in a hidden field but since the insert is not part of the same form, I do not know how to insert that data into the other table.

How do I reference the hidden field. It is a button in the store with a custom insert script server side. Just like store sample.

//Custom Code @176-64A228FD
// -------------------------
global $purchase;
// Write your own code here.
$db = new clsDBInternetDB();

// Count Order Total
$SQL = "SELECT SUM(Price * quantity) as total "
."FROM store_shopping_cart_items a, Products b "
."WHERE a.product_id=b.ID AND "
."shopping_cart_id =" . $db->ToSQL(CCGetCookie("shopping_cart_id"),ccsInteger);
$db->query($SQL);
if($db->next_record()) {
$OrderTotal = $db->f("total");
}

// Create a new order
$SQL = "INSERT INTO store_orders (user_id, order_date, order_status_id, total) VALUES ("
.$db->ToSQL(CCGetUserID(),ccsInteger) . ","
.$db->ToSQL(date("Y-m-d"),ccsDate) . ",1,"
.$db->ToSQL($OrderTotal,ccsFloat) . ")";
$db->query($SQL);

// Get Order ID
//This method is compatible with all databases (Note that it is unsafe while the multiple insertion is performed at the same time)
//Specify the custom method for the database.
$SQL = "SELECT MAX(order_id) FROM store_orders";
$db->query($SQL);
if ($db->next_record()) {
$last_order_id = $db->f(0);
}

// Move items from user's shopping cart into the order
$SQL = "SELECT a.product_id as product_id, a.quantity as quantity, Price "
."FROM store_shopping_cart_items a, Products b "
."WHERE a.product_id=b.ID AND shopping_cart_id = " .$db->ToSQL(CCGetCookie("shopping_cart_id"),ccsInteger);
$db->query($SQL);

$db2 = new clsDBInternetDB();
while ($db->next_record()) {
$SQL = "INSERT INTO store_order_items (order_id, product_id, quantity, Price ) "
."VALUES (" . $db2->ToSQL($last_order_id,ccsInteger)
."," . $db2->ToSQL($db->f("product_id"),ccsInteger)
."," . $db2->ToSQL($db->f("quantity"),ccsInteger)
."," . $db2->ToSQL($db->f("Price"),ccsFloat)
.")";
$db2->query($SQL);
}
unset($db2);

// Delete items from user's shopping

$db->query("DELETE FROM store_shopping_cart_items WHERE shopping_cart_id = ".$db->ToSQL(CCGetCookie("shopping_cart_id"),ccsInteger));

unset($db);

// -------------------------
//End Custom Code
View profile  Send private message
tonyk

Posts: 163
Posted: 11/16/2004, 4:38 PM

Are you saying that you have a grid of values and that these are shown as labels rather than text fields?
If you are using labels I am sure you will need to use hidden text fields from which you recover the data using the php server side code
$form_name->control_name->GetValue(), you may have to enclose that in a ToSQL function to convert it to the correct format for your sql statement. That is explained in the help file.
I dont have a current copy of the shopping basket application to refer to.
I don't know if that helps at all.
Tony
View profile  Send private message
peterr


Posts: 5971
Posted: 11/16/2004, 10:40 PM

mavtech,
I'm not sure if I understand your issue, however:
1. It is not always a good idea to store information in hidden fields, without proper verification. For example someone could save the form to their computer, modify the hidden field value and submit the form with wrong information.
I sometimes use hidden fields only so that a field is available in the events, but I assign the value to it in the Before Insert or Update event, regardless of what it is on the page.
2. Label values cannot be accessed on the server since they are just text on a page, and HTML forms do not submit any values to the server that are not in form fields.
If you need to retrieve a Label value, then re-calculate it in the Before Insert/Update event, the same way as it was calculated when you originally printed it on the page.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
tonyk

Posts: 163
Posted: 11/17/2004, 8:55 PM

That was a succinct reply, right on the nail and very useful. I did not realize hidden fields could be abused in that way, I feel some recoding coming on :-/
Tony
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.