Forum Moderators: coopster

Message Too Old, No Replies

Advanced: Parsing server-side data into simple cart (CMS required)

dynamic entry capable dual arrays using checkboxes, from CMS entries

         

4bizmedia

4:15 am on Apr 17, 2008 (gmt 0)

10+ Year Member



Hi all,

First time poster, Long time reader...

Could I get help with a small problem I'm trying to get my head around, this is my pretty much my last resort, as I've exhausted all other avenues, the problem is thus, basically I'm writing a 'simple cart system' all data entry and server-side functions are handled by CMS, called website-baker.

All the functions and pages are written, the actual problem is printing the 'list' (dynamic) whereby, where you can select multiple 'items' from that 'list' using check-boxes (adding into array) then creating a total, as well as display of those items in a generated email. (using php, I can't use javascript or ajax, because of integration issues into CMS.)

So far, i am able to dynamically print the each 'item' from the 'list':


$header = addslashes('');

$item_loop = addslashes('
<table cellpadding="8"><form action="[SHOP_URL]" method="post">
<tr>
<td rowspan="3" width="150"><a href="[LINK]">[THUMB]</a></td>
<td><p>Item name:&nbsp;<a href="[LINK]">[TITLE]</p></a></td>
<td><p>Expiry date:&nbsp; [EXPIRY]</p></td>
</tr>
<tr>
<td><p>Item ID:&nbsp;[SKU]</p></td>
<td rowspan="2" valign="top"><p>Condition:&nbsp;[DESCRIPTION]</p></td>
<td><input type="checkbox" name="item[ITEM_ID]" value="1"/></td>
</tr>
<tr>
<td><p>Price:(AU$)[PRICE]</p></td>
</tr>
<tr><td><input type="submit" name="cart" value="[ADD_TO_CART]"></form></td></tr>
');

$footer = addslashes('
</table>
<table width="98%" style="display: [DISPLAY_PREVIOUS_NEXT_LINKS]">
<tr>
<td width="33%" align="left">[PREVIOUS_PAGE_LINK]</td>
<td width="33%" align="center">[TXT_ITEM] [OF]</td>
<td width="33%" align="right">[NEXT_PAGE_LINK]</td>
</tr>
</table>

This prints the catalogue of items, check box and submit button in the loop, I realise that the submit (evokes cart function in view.php class) button is inside the printing loop, this will change.

My would start the new item printing, using a dual or multi-dimensional array, but I'm not sure how to go about putting it in the page or how it 'co-operates' or evokes with the corresponding class. (view.php.)


switch (@$_POST['cart']) {

case $MOD_BAKERY['TXT_ADD_TO_CART']:
// Get item ID and quantity ( -> $value)
$sql_result1 = $database->query("SELECT * FROM " .TABLE_PREFIX ."mod_addPart_order WHERE order_id = '$order_id'");

foreach($_POST as $field => $value) {
// Error message if quantity < 1
if(substr($field,0,4) == "item" && $value < 1) {
$cart_error[] = $MOD_BAKERY['ERR_QUANTITY_ZERO'];
}
if(substr($field,0,4) == "item" && $value > 0) {
$item_id = substr($field,4,strlen($field)-4);
// Get item_id
if (isset($_POST['attribute'.$item_id])) {
$attribute = $_POST['attribute'.$item_id];
// Get item attribute
} else {
$attribute = "none";
// If no attribute is given set it to "none"
}

// Error message if item is in cart already
while ($row1 = $sql_result1->fetchRow()) {
if ($row1['item_id'] == $item_id && $row1['attribute'] == $attribute) {
$cart_error[] = $MOD_BAKERY['ERR_ITEM_EXISTS']; }
}

// Write ordered item data into DB
$sql_result2 = $database->query("SELECT price, sku, tax_rate FROM " .TABLE_PREFIX ."mod_addPart_items WHERE item_id = '$item_id'");
$row2 = $sql_result2->fetchRow();

$sku = $row2['sku'];
$price = $row2['price'];
$tax_rate = $row2['tax_rate'];

$database->query("INSERT INTO " .TABLE_PREFIX ."mod_addPart_order (order_id, item_id, attribute, sku, quantity, price, tax_rate)
VALUES ('$order_id', '$item_id', '$attribute', '$sku', '$value', '$price', '$tax_rate')");
}
}
include('view_cart.php');
return;
break;

So far I've got as far as,

// server-side, co-operating with view.php
i = 0;
item_info = newArray(attribute, item_id);

if(!isset($_POST['item_info'] {
$arrErrors['item_info'] ="error no items selected";

elseif(isset($_POST['item_info'])) {
$item_id = $item_info[i];
i++;
}
}

// client-side, parsed from modify.php and view.php
<form action="[SHOP_URL]" method="post">
<input type="checkbox" name="item_info[ITEM_ID]" value="attribute" />
<input type="submit" name="cart" value="[ADD_TO_CART]" />
</form>

Thank you for your help in advance, any help would be appreciated.

[edited by: jatar_k at 11:49 am (utc) on April 17, 2008]
[edit reason] no urls thanks [/edit]

dreamcatcher

7:46 am on Apr 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld 4bizmedia. :)

dc

4bizmedia

10:57 pm on Apr 20, 2008 (gmt 0)

10+ Year Member



ty :D