Jump to content
Larry Ullman's Book Forums

jwarrentx

Members
  • Posts

    18
  • Joined

  • Last visited

jwarrentx's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. I know this isn't a question, but.... I just bought PHP6 and MySQL5 for Dynamic Websites and noticed that we share a connection with our university. I too graduated from NMSU. The semester after I graduated, the name change to Truman State University. Nice to see other alumni doing well.
  2. There is actually a descent reason to do this. I have a client who would like a variable to be added to the cart. One which I don't have control over. I have had a hard time deciding how to pass that since it doesn't come directly from the database. If I pass it as information from the cart or wishlist, I won't have to pass it in the url. It seem that this might be a safer way to pass the variable. Would you have another suggestion, or would this provide the most security for the database?
  3. I haven't had an opportunity to change the other Stored Procedures, but these changes will allow the items in the cart to be removed. If this isn't clear, please let me know, and I will rewrite it. Also, if you would like me to post all of the changes made once I have had an opportunity, I would gladly do so. To get the cartId to work instead of the sku, first you will need to change these Stored Procedures: addToCart, removeFromCart, updateCart and getShoppingCartContents. The corresponding Stored Procedures for the Wish List will also need to be updated. I have changed my Stored Procedures from remove_from_cart to camel case: removeFromCart, and when updating the stored procedures, I don't delete the originals, but rather add a description after them so that I can go back if needed, in this case _cartId. First you must change the getShoppingCartContent to get the cartId in the ski rather than the productId in the sku. Here is a sample of the Stored Procedure getShoppingCartContents_cartId: -- ----------------------------- -- getShoppingCartContents_cartId -- -- ----------------------------- DROP PROCEDURE IF EXISTS getShoppingCartContents_cartId; DELIMITER $$ CREATE PROCEDURE getShoppingCartContents_cartId (uid CHAR(32)) BEGIN SELECT CONCAT("O", cartId) AS sku, c.quantity, categories.category, products.name, products.price, products.stock, sales.price AS sale_price, CONCAT(products.name) AS combinedName FROM carts AS c INNER JOIN products ON c.productsId=products.productsId INNER JOIN categories ON categories.categoryId=products.categoryId LEFT OUTER JOIN sales ON (sales.productsId=products.productsId AND ((NOW() BETWEEN sales.start_date AND sales.end_date) OR (NOW() > sales.start_date AND sales.end_date IS NULL)) ) WHERE c.user_session_id=uid AND c.sp_type = 'option1' There are UNION's after this, but the important part is to get the cartId in the SELECT statement. Add that to the UNION arguments. In this case, I replaced the productId with cartId in the sku. Here are the new Stored Procedure for removeFromCart_cartId: -- ----------------------------- -- removeFromCart_cartId -- -- ----------------------------- DROP PROCEDURE IF EXISTS removeFromCart_cartId; DELIMITER $$ CREATE PROCEDURE removeFromCart_cartId (uid CHAR(32), pid int(10)) BEGIN DELETE FROM carts WHERE user_session_id=uid AND pid=cartId; END$$ DELIMITER ; At the top of the page, there is a reference to the function to break the sku into its parts. For this demonstration, I am going to keep the cartId looking like the sku, so the cartId will actually come across as the $pid. When references the stored procedure, it's important to remember that. All that was changed in the removeFromCart_cartId Stored Procedure was pid=cartId. The code in cart.php will also need to be updated to show the new Stored Procedure and to accept the new argument: } elseif (isset ($sp_type, $pid, $_GET['action']) && ($_GET['action'] == 'remove') ) { // Remove it from the cart. $r = mysqli_query($dbc, "CALL removeFromCart_cartId('$uid', '$pid')");
  4. It is, but couldn't that code be updated? I will post my thoughts for the changes tomorrow. My code will look vastly different than that of the book, but the general idea will still be there. I have update the cart code to work with various options and am trying to add one more. It will require either the cart id or another variable for the cart functionality to work. So, here's to cart I'd coding.
  5. Is there any reason that you use the SKU instead of the cart ID to update variables in the shopping cart? Couldn't we get the same results using the cart ID?
  6. I am having a problem with the stock management option. When I add an item to the shopping cart and have more stock than is available, when proceeding tot he shopping cart, the item gets removed from the shopping cart and added to the wish list. When I do this with two items, only one of the items gets removed from the shopping cart and added to the wish list. I have changed the variables, but everything else is working in both the shopping cart and wish list. Any help would be appreciated. Thanks. // Remove any problematic items: if (!empty($remove)) { // Clear the results: mysqli_next_result($dbc); // Loop through the array: foreach ($remove as $sku => $qty) { list($sp_type, $pid) = parse_sku($sku); // Move it to the wish list: $r = mysqli_multi_query($dbc, "CALL addToWishList_sku3('$uid', $pid, '$sku', '$sp_type', $qty);CALL removeFromCart_sku2('$uid', '$sku')"); echo "CALL addToWishList_sku3('$uid', $pid, '$sku', '$sp_type', $qty);CALL removeFromCart_sku2('$uid', '$sku')"; } // End of FOREACH loop. } // End of $remove IF. This is what is printed on the page when I add two items that don't have enough stock to fullfil the order: CALL addToWishList_sku3('3e8413de30798552f88f6f33b533a0be', 4, 'O4', 'other', 127);CALL removeFromCart_sku2('3e8413de30798552f88f6f33b533a0be', 'O4')CALL addToWishList_sku3('3e8413de30798552f88f6f33b533a0be', 3, 'O3', 'other', 127);CALL removeFromCart_sku2('3e8413de30798552f88f6f33b533a0be', 'O3') I have noticed when I add to many items to the example shopping cart that they both get removed from the shopping cart and added to the wish list. This isn't happening on my site. They aren't both removed until you procede to the billing page. Is there something in the code that I am missing? I am using: PHP Version 5.2.14 MYSQL 5.0.77
  7. I think that it's in the array. I amusing $sid for the size. In the database it's sizeId and $op2 (since $cid is taken) for color, and it's colorId in the database. I haven't changed this: foreach ($_POST['quantity'] as $sku => $qty). I believe that's where the problem is. In this code, it only gets the sku (which I haven't changed from your book) and the quantity. Somehow I need to get the sizeId and the colorId. The variables are being sent correctly to the page, there just not populating here. This is the code that I am using in this section of cart.php (it works the same in wishlist.php): } elseif (isset($_POST['quantity'])) { // Update quantities in the cart. // Loop through each item: foreach ($_POST['quantity'] as $sku => $qty) { // Parse the SKU: list($sp_type, $pid) = parse_sku($sku); $sid=$_POST['sizeId']; $op2=$_POST['colorId']; if (isset($sp_type, $pid, $sid, $op2)) { // Determine the quantity: $qty = (filter_var($qty, FILTER_VALIDATE_INT, array('min_range' => 0)) !== false) ? $qty : 1; // Update the quantity in the cart: $r = mysqli_query($dbc, "CALL updateCart('$uid', $pid, '$sid', '$op2', $qty)"); $r = mysqli_query ($dbc, "SELECT name FROM products WHERE productsId=$pid"); while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { if ($op2 !== '0' AND $sid !== '0') { $message = 'You now have changed the quantity of ' . $row['name'] . ', ' . $sid . ', ' . $op2 . ' to ' . $qty . '.'; } elseif ($sid !== '0') { $message = 'You now have changed the quantity of ' . $row['name'] . ', ' . $sid . ' to ' . $qty . '.'; } else { $message = 'You now have changed the quantity of ' . $row['name'] . ' to ' . $qty . '.'; } } } } This also has come up in the billing.php an checkout.php. I am unable to delete the products that do not have enough inventory. I haven't changed that code, because I am trying to figure this out and have been unsuccesful. I believe the problem comes in here: $remove[$row['sku']] = $row['quantity']; How do I pass the sizeId and colorId here? I have tried multiple things and searched online and have been unsuccesful. Thank you for all you do.
  8. Here is a link to a product page: http://jwarrenconsulting.com/baertrax-tshirts/browse/Experiment/2. If you add different products to the page, that's when it stop working. If there are no size or color options, the variable that gets add for sizeId and colorId is 0. That corresponds with the database. Here is some HTML code, please let me know if you need additional code: <form action="<?php echo '' . BASE_URL . ''; ?>cart.php" method="POST"> <table class="cart"> <tr> <th class="Item">Item</th> <th class="Quantity">Quantity</th> <th class="Price">Price</th> <th class="Subtotal">Subtotal</th> <th class="Options">Options</th> </tr> <?php // Display the products: $alternate = "2"; // colour rows // Initialize the total: $total = 0; // Fetch each product: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { // Get the correct price: $price = get_just_price($row['price'], $row['sale_price']); // Calculate the subtotal: $subtotal = $price * $row['quantity']; //zebra colouring for rows if ($alternate == "1") { $colour = "even"; $alternate = "2"; } else { $colour = "odd"; $alternate = "1"; } // Print out a table row: echo ' <tr class="' . $colour . '"> <td class="Item"><a href="' . BASE_URL . 'products.php?sku=' . $row['sku'] . '">' . $row['name'] . ''; if ($row['sizeId'] !== '0') { echo ', ' . $row['sizeId'] . ''; } if ($row['colorId'] !== '0') { echo ', ' . $row['colorId'] . ''; } echo '</a></td> <td class="Quantity"> <input type="text" name="quantity[' . $row['sku'] . ']" value="' . $row['quantity'] . '" size="2" class="small" /> <input type="hidden" name="sizeId" id="sizeId" value="' . $row['sizeId'] . '"/> <input type="hidden" name="colorId" id="colorId" value="' . $row['colorId'] . '"/> </td> <td class="Price">$' . $price . '</td> <td class="Subtotal">$' . number_format($subtotal, 2) . '</td> <td class="Options"><a href="' . BASE_URL . 'wishlist.php?colorId=' . $row['colorId'] . '&sizeId=' . $row['sizeId'] . '&sku=' . $row['sku'] . '&action=move&qty=' . $row['quantity'] .'">Move to Wish List</a><br /><a href="' . BASE_URL . 'cart.php?color=' . $row['colorId'] . '&size=' . $row['sizeId'] . '&sku=' . $row['sku'] . '&action=remove">Remove from Cart</a></td> </tr>'; // Check the stock status: if ($row['stock'] < $row['quantity']) { echo ' <tr class="error"> <td colspan="5" align="center">There are only ' . $row['stock'] . ' left in stock of the ' . $row['name'] . '. Please update the quantity, remove the item entirely, or move it to your wish list.</td> </tr>'; } // Add the subtotal to the total: $total += $subtotal; } // End of WHILE loop. // Add the shipping: $shipping = get_shipping($totalitems); $total += $shipping; echo ' <tr> <th colspan="3" class="Price">Shipping & Handling</th> <th class="Subtotal">$' . $shipping . '</th> <th class="Options"> </th> </tr>'; // Display the total: echo ' <tr> <th colspan="3" class="Price">Total</th> <th class="Subtotal">$' . number_format($total, 2) . '</th> <th class="Options"> </th> </tr>'; ?> </table> <input type="submit" value="Update Quantities" class="button" /> </form>
  9. I have added a size and color option to some of the products. I can get everything to work except for the update cart. Sometimes it will update some items, but not all of them. I changed the code to receive the information, I'm just not sure why it will update some items and not others. Size and color can be 0 if there are no options presented (I send a hidden input field with a value=0). I have some conditions set up to check and see if the value is 0. The options are working fine, and so is everything else. Inside the wishlist and the cart, everything but update is working, including moving the items to their other respective cart and removing them. I also couldn't decipher how it was choosing which ones to update and which ones not to update. Thanks for the help. The stored procedure I am using is: sid = sizeId op2 = colorId DELIMITER $$ CREATE PROCEDURE updateCart (uid CHAR(32), pid MEDIUMINT, sid VARCHAR(6), op2 VARCHAR(6), qty TINYINT) BEGIN IF qty > 0 THEN UPDATE carts SET quantity=qty, date_modified=NOW() WHERE user_session_id=uid AND productsId=pid AND sizeId=sid and colorId=op2; ELSEIF qty = 0 THEN CALL removeFromCart (uid, pid, sid, op2); END IF; END$$ DELIMITER ; The table structure for carts is: CREATE TABLE `carts` ( `cartId` int(10) unsigned NOT NULL AUTO_INCREMENT, `quantity` tinyint(3) unsigned NOT NULL, `user_session_id` char(32) NOT NULL, `productsId` mediumint(8) unsigned NOT NULL, `sizeId` varchar(6) NOT NULL, `colorId` varchar(6) NOT NULL, `date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `date_modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', PRIMARY KEY (`cartId`), UNIQUE KEY `productsId` (`productsId`,`sizeId`,`colorId`), KEY `user_session_id` (`user_session_id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=23 ; I am using: PHP Version 5.2.14 MYSQL 5.0.77 0 Quote MultiQuote Edit
  10. I know this is the current shipping function. How could it be amended to charge a certain amount per item. It would have to count each individual item and how many of each in the cart? function get_shipping($total = 0) { // Set the base handling charges: $shipping = 0.5; // Rate is based upon the total: if ($total < 10) { $rate = .25; } elseif ($total < 20) { $rate = .20; } elseif ($total < 50) { $rate = .18; } elseif ($total < 100) { $rate = .16; } else { $rate = .15; } // Calculate the shipping total: $shipping = $shipping + ($total * $rate); // Return the shipping total: return number_format($shipping, 2); } // End of get_shipping() function I am using: PHP Version 5.2.14 MYSQL 5.0.77
  11. I found it, and it worked. I had to change the sid to CONVERT(sid USING utf8) COLLATE utf8_general_ci also. I want to build code that is reusable for other shopping carts. Will this work in the older version of MySQL that I am using, or will I have to have two different versions of the Stored Procedures?
  12. I'm having a problem on one of the servers that I am using the stored procedures on. I have had luck with another (older) version of php and MySQL, but the following stored procedure won't work on the newer version. Any ideas: CREATE PROCEDURE `addToCart`(uid CHAR(32), pid MEDIUMINT, sid VARCHAR(6), qty TINYINT) BEGIN DECLARE cid INT; SELECT cartId INTO cid FROM carts WHERE user_session_id=uid AND productsId=pid AND sizeId=sid; IF cid > 0 THEN UPDATE carts SET quantity=quantity+qty, date_modified=NOW() WHERE cartId=cid; ELSE INSERT INTO carts (user_session_id, productsId, sizeId, quantity) VALUES (uid, pid, sid, qty); END IF; END The problem seems to be in user_session_id=uid and sizeId=sid. If I use sizeId='$sid', the sizeId works. But if I use user_session_id='$uid', it doesn't. This is the error I get if I use the code above: Illegal mix of collations (utf8_general_ci,IMPLICIT) and (utf8_unicode_ci,IMPLICIT) for operation '=' An error occurred in script '/home/baertrax/public_html/eshop/cart.php' on line 87: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given On one server that is working, I am using: PHP Version 5.2.14 MYSQL 5.0.77 On another server where it is not working, I am using: PHP Version 5.2.17 MySQL 5.1.56
  13. I have added a shirt size option into browse.pho. I can send the size to cart.php since it invokes the form.unfortunately, the wishlist is just a link. I can't send the size to wishlist.php as it is now. I believe that I need to make it a submit button also. How can I have both as submit buttons, but send them to different pages? I would prefer to stay away from JavaScript options. I am using: MYSQL 5.0.77 PHP Version 5.2.14
  14. I am getting this error message when running the email_receipt.php script: An error occurred in script '/home/content/j/w/a/jwarrenn1/html/texas-overland-outfitters/library/Zend/Mail.php' on line 972: date() [function.date]: It is not safe to rely on the system's timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Denver' for 'MST/-7.0/no DST' instead I did not change any code from the book and have tried both the full and minimal versions of the Zend Framework. There isn't any mention of changing any of the code in the Zend Framework library folder. Is there something that I am missing? I am using: MYSQL 5.0.77 PHP Version 5.2.14 I have tried both: Zend Framework 1.11 minimal (as suggested in the book) & Zend Framework 1.11 full
  15. I am using: MYSQL 5.0.77 PHP Version 5.2.14 Sorry for not including that before.
×
×
  • Create New...