Path: csiph.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: Replace punctuation in an associative array Date: Fri, 14 Apr 2023 19:34:23 +0200 Lines: 197 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net WWWzLIjlozNXj9/z1C7FvAFDC9hT1TNXIYllBYykTpSW+8f5Df Cancel-Lock: sha1:z54hsCZSzXwmJRL7KZqWGn93w0w= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Content-Language: en-US-large In-Reply-To: Xref: csiph.com comp.lang.php:19435 On 4/14/23 03:12, The Doctor wrote: > 95% there. > > > Now I have split the form successfully I need to get > the cartitem in a printable format. > > So given when I have worked on > > > error_reporting(E_ALL); > ?> > > > > > > > > if(!empty($_SESSION['sessiondata'])){ > } > ?> > $myObj = []; > $storevalues= array(); > $cartarray= array(); > $cart= array(); > $contact1=array(); > $contact_details=array(); > $shipping1=array(); > $shipping_details=array(); > $billing1=array(); > $billing_details=array(); > $arr2 =array(); Try to avoid all these arrays, they don't make life easier. > class Storevs{ > } > class Item > { > } > class TaxItem > { > } > > class CartItem > { > public $items; > public $subtotal; > public $tax; > }; > > class Contact > { > } > > class Shipping > { > } > > class Billing > { > } Don't define the classes here, then you need to do it each file you use, you create an php script that just includes the classes and then use include https://www.php.net/manual/en/function.include.php > $items_count = 0; > $newsubtotal = 0; > $subtotal = 0; > $arr = array(); > > if (isset($_POST["submit"])){ > $storevalues=(array) $storev; > } > > if (isset($_POST["submit"])){ > $cartitem= new CartItem(); > > foreach ($_POST['quantity'] as $key => $value) { > if( $value > 0){ > if(isset($_POST['with_gst'][$key])){ > $unit_cost = 63.00; > }else{ > $unit_cost = 60.00; //no gst included > } prices shouldn't be hard coded, you don't want to change the code just for the price went up due of inflation, you change the price in a database of some sort. > $item = new Item(); > $item->url = "https://image"; > $item->description = $_POST['description'][$key]; > $item->product_code = $_POST['id'][$key]; > $item->unit_cost = $unit_cost; > $item->quantity = $value; > $cartitem->items[] = $item; > > } > } > > $cartitem->subtotal = ($_POST['charge_total']/1.05); Hey, this ain't a value you can trust, you need to go trough all the items in the cart, check up the price for each item and calculate the total. Say a user with one of the many browser plugins that allows you to modify post data, the user just adds all the items it wants and then change the value for charge_total to 0, please calculate how pissed your boss will be. > > $taxItem = new TaxItem(); > $taxItem->amount = (($_POST['charge_total']/1.05) * 0.05); > $taxItem->description = "GST"; > $taxItem->rate = "5.00"; > $cartitem->tax = $taxItem; > $cart= (array) $cartitem ; > $cartarray = array( "cart" => $cartitem); > } > > if (isset($_POST["submit"])){ > $contact=new Contact; > $contact1= (array) $contact ; > $contact_details=array ( "contact_details" => $contact1 ); > } > if (isset($_POST["submit"])){ > $shipping = new Shipping; > $shipping1 = (array) $shipping; > $shipping_details=array( "shipping_details" => $shipping1 ); > } > if (isset($_POST["submit"])){ > $billing = new Billing; > $billing_details=array( "billing_details" => $billing1 ); > > } > > $_SESSION['arr'] = serialize($arr); > $_SESSION['serialized_Obj'] = serialize($myObj); > > ?> > > >
> >

Please review your order!

> echo "

"; why do you echo the html code? leave those outside the php code, you can have multiple in a page. > echo "

Contact Information

"; > > echo "
My name is " . $contact->first_name . " " . $contact->last_name . "
"; > echo "My E-mail address is " . $contact->email . "
"; > echo "You can call me at " . $contact->phone . "

"; > > echo "

Billing Information

"; > > echo "
Address :" . $billing->address_1 . "
"; > echo $billing->address_2 . "
"; > echo "Municipality:" . $billing->city . "
"; > echo "Province:" . $billing->province . "
"; > echo "Postal Code:" . $billing->postal_code . "

"; > > echo "

Shipping Information

"; > > echo "
Address :" . $shipping->address_1 . "
"; > echo $shipping->address_2 . "
"; > echo "Municipality:" . $shipping->city . "
"; > echo "Province:" . $shipping->province . "
"; > echo "Postal Code:" . $shipping->postal_code . "

"; > > > > echo "

Course Information

"; Here you use a foreach loop that goes over the cart items, of course you need to deserialize the $_SESSION['serialized_Obj']. https://www.php.net/manual/en/control-structures.foreach.php > ?> > > >
> > -- //Aho