PHP XML Shopping Cart -
hi i've got xml file products in shop. used php parse file , list products on page. next task add 'add cart' button list , simple shopping cart work.
honestly, i'm total newbie in php , have no idea start , how work. need basic overview of should learn , how i'm going solve problem. !!!
maybe started:
<?php $xml='<?xml version="1.0" encoding="iso-8859-1"?> <catalogue> <music> <cd id="0010"> <name>album</name> <price>10</price> <quantity>100</quantity> </cd> <cd id="0011"> <name>live ep</name> <price>10</price> <quantity>100</quantity> </cd> <cd id="0012"> <name>single</name> <price>2</price> <quantity>100</quantity> </cd> <cd id="0013"> <name>b-sides</name> <price>5</price> <quantity>100</quantity> </cd> </music> <merchandise> <shirt id="0001"> <name>album cover shirt</name> <price>9.99</price> <sizes> <size>small</size> <quantity>10</quantity> </sizes> <sizes> <size>medium</size> <quantity>10</quantity> </sizes> <sizes> <size>large</size> <quantity>10</quantity> </sizes> </shirt> </merchandise> <merchandise> <shirt id="0002"> <name>band logo shirt</name> <price>9.99</price> <sizes> <size>small</size> <quantity>10</quantity> </sizes> <sizes> <size>medium</size> <quantity>10</quantity> </sizes> <sizes> <size>large</size> <quantity>10</quantity> </sizes> </shirt> </merchandise> <merchandise> <shirt id="0003"> <name>guitar shirt</name> <price>9.99</price> <sizes> <size>small</size> <quantity>10</quantity> </sizes> <sizes> <size>medium</size> <quantity>10</quantity> </sizes> <sizes> <size>large</size> <quantity>10</quantity> </sizes> </shirt> </merchandise> <merchandise> <cap id="0004"> <name>band logo cap</name> <price>4.99</price> <quantity>20</quantity> </cap> </merchandise> <merchandise> <cap id="0005"> <name>album cover cap</name> <price>4.99</price> <quantity>20</quantity> </cap> </merchandise> <merchandise> <cap id="0006"> <name>guitar cap</name> <price>4.99</price> <quantity>20</quantity> </cap> </merchandise> <merchandise> <others id="0007"> <name>band buttons</name> <price>4.99</price> <quantity>20</quantity> </others> </merchandise> <merchandise> <others id="0008"> <name>large poster</name> <price>10.99</price> <quantity>20</quantity> </others> </merchandise>v <merchandise> <others id="0009"> <name>guitar</name> <description>very limited!</description> <price>300</price> <quantity>5</quantity> </others> </merchandise> <tickets> <ticket id="0014"> <location>charles\'s pub</location> <city>sliema</city> <country>malta</country> <day>12</day> <month>6</month> <year>2013</year> <price>15</price> <quantity>200</quantity> </ticket> <ticket id="0015"> <location>olympus</location> <city>valletta</city> <country>malta</country> <day>23</day> <month>6</month> <year>2013</year> <price>15</price> <quantity>200</quantity> </ticket> <ticket id="0015"> <location>the venue</location> <city>rome</city> <country>italy</country> <day>5</day> <month>7</month> <year>2013</year> <price>15</price> <quantity>200</quantity> </ticket> </tickets> </catalogue>'; $header='<!doctype html> <html> <head> <title>example shop</title> </head> <body>'; $footer=' </body> </html>'; $xml=simplexml_load_string($xml); $store=array(); foreach($xml $section=>$items) { $store[$section][]=$items; } $sections=array_keys($store); foreach ($sections $section) { if (isset($_get[$section])) { echo $header; echo '<a href="'.$_server["script_name"].'">back index</a>'; foreach ($store[$section] $items) { foreach ($items $type=>$item) { if ($section=="music") { echo "<h2>".$item->name."</h2>"; echo "price: ".$item->price."<br>"; $attr=$item->attributes(); echo "id: ".$attr['id']; } if ($section=="merchandise") { echo "<h2>".$item->name."</h2>"; echo "price: ".$item->price."<br>"; if (isset($item->sizes)) { echo "<h3>sizes:</h3>"; foreach ($item->sizes $size) { echo "<b>".$size->size."</b> quantity: ".$size->quantity."<br>"; } } $attr=$item->attributes(); echo "id: ".$attr['id']; } if ($section=="tickets") { echo "<h2>".$item->location."</h2>"; echo "country: ".$item->country."<br>"; echo "city: ".$item->city."<br>"; echo "quantity: ".$item->quantity."<br>"; echo "date: ".$item->month." ".$item->day.", ".$item->year."<br>"; echo "price: ".$item->price."<br>"; $attr=$item->attributes(); echo "id: ".$attr['id']; } } } ?> <?php echo $footer; exit; } } echo $header; ?> <h3>please select section begin.</h3> <?php foreach ($sections $section) { echo '<a href="?'.$section.'">'.ucfirst($section).'</a><br>'; } echo $footer; ?>
Comments
Post a Comment