Hi all, a novice here, seeking to learn, tied by deadline… the usual..!

The Situation:

A person buys a product, an order is placed, the buyer is returned from the cart to a "thankyou" page, the thankyou page is required to:

a) update a mysql db table (…_cartorders.orders) creating a log of all data
for the order (customer id, order id, etc)

b) update the stock level for each product purchased (by deducting the
purchased quantity from the existing stock level) in another table on
another db (…_eshop.products)

c) assesses whether, as a result of the purchase, the product is:
i) (stock>0) ‘in stock’ - the website shows "instock"
ii) (stock<=0) ‘out of stock’ -the website shows "available to order"
- if the resultant stock level is <=1 then an email is sent to the
administrator identifying the product and its calculated stock level,
informing them that its time to replenish.

The problem:

Due to shopping cart design, the product information recieved by the ‘thankyou’ page is contained within a string in the format:

$cart=(description(D):quantity(Q):unitprice(UP):sh ipping(S):productcode(P))

the more products added to the cart from the site, the longer the string gets, each seperate product added is seperated by ‘~’, hence, for MULTIPLE products, the string would appear like:

$cart=(D:Q:UP:S:P~D:Q:UP:S:P~D:Q:UP:S:P~D:Q:UP:S:P ~D:Q:UP:S:P)

in order to fullfill the given situation above, it is necessary to extract the individual values from $cart so that:

(P) can be used to identify each unique product
(Q) can be used to set a new stock level for each unique product
(D) can be used to furnish the ‘replenish stock email’ if required
-(UP) & (S) are not required.

Tried Solutions:

1) I have successfully created a log of each order in …_cartorders.orders.
2) I have successfully updated …_eshop.products with a new stock level for
a unique product using (P) for the product_id and ’stocklevel-(Q)’ for a
SINGLE $cart order (by creating an array and extracting (array => P) and
(array => Q) and updating the correct db table accordingly.
3) by querying the updated db entry, I can establish cases for stock>0,
stock<=0 and send email if stock <=1, thus solving the Situation Criteria.

—————-BUT ONLY FOR A SINGLE PURCHASE..!—————–

The moment a second product is added to the order, the solution fails..!

The Code (excluding cases & html):

PHP Code:


<?php
require_once ‘config.php’;
$dt=(str_replace(“~”,“<br />”,$cart));
mysql_query(“REPLACE INTO orders (username,id,ip,date,method,cart,discount,subtotal,shipping,tax,total,shipping_zone,inv_name,inv_company,inv_addr1,inv_addr2,inv_state,inv_zip,inv_country,del_name,del_addr1,del_addr2,del_state,del_zip,del_country,tel,fax,email,message,sd)
VALUES (’$username’,$id,’$ip’,'$date’,'$method’,'$dt’,'$discount’,'$subtotal’,'$shipping’,'$tax’,'$total’,$shipping_zone,’$inv_name’,'$inv_company’,'$inv_addr1′,’$inv_addr2′,’$inv_state’,'$inv_zip’,'$inv_country’,'$del_name’,'$del_addr1′,’$del_addr2′,’$del_state’,'$del_zip’,'$del_country’,'$tel’,'$fax’,'$email’,'$message’,'$sd’)”
); 
$_POST[‘cart’];
$ct=(str_replace(“~”,“:”,$cart));
$details=(explode(“:”,$ct));
$det[description]=$details[0]; 
$qty[qty]=$details[1];
$price[price]=$details[2];
$ship[ship]=$details[3];
$scode[scode]=$details[4]; 
$sql mysql_query (“update memorydaddy_co_uk_eshop.tbl_product set stock = stock - $details[1] where pd_id = ’$details[4]’”)or die (mysql_error());
}
?>


-Probably not the neatest of methods, however….

Any thoughts out there…?

30,000 Mb And Unlimited Bandwidth Only $3.75/mo.


Go Daddy  $6.95 .com sale 468x60

Powered By: BigInfo.org