Jump to content

esreekay

New Members
  • Posts

    4
  • Joined

  • Last visited

esreekay's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Create page parts */ /** * Return a string, containing list items for each product in cart * * @access public * @param * @return array */ public function create_cart() { // get products currently in cart $products = $this->get(); $data = ''; $form = ''; $total = 0; $data .= '<li class="header_row"><div class="col1">Product Name:</div><div class="col2">Procarb#:</div><div class="col3">Quantity:</div><div class="col4">Meal Price:</div><div class="col5">Total Price:</div></li>'; if ($products != '') { // products to display $line = 1; $shipping = 0; foreach($products as $product) { $item_shipping = $this->get_shipping_cost($product['price']) * $_SESSION['cart'][$product['id']]; $shipping += $item_shipping; // create new item in cart $data .= '<li'; if ($line % 2 == 0) { $data .= ' class="alt"'; } $data .= '><div class="col1">' . $product['name'] . '</div>'; $data .= '<div class="col2"><input name="procarb' . $product['id'] .'" value="'. $_SESSION['cart'][$procarb['id']] .'"></div>'; $data .= '<div class="col3"><input name="product' . $product['id'] .'" value="'. $_SESSION['cart'][$product['id']] .'"></div>'; $data .= '<div class="col4">$' . $product['price'] . '</div>'; $data .= '<div class="col5">$' . $product['price'] * $_SESSION['cart'][$product['id']]* $_SESSION['cart'][$procarb['id']] . '</div></li>'; // create PayPal form fields $form .= '<input type="hidden" name="item_name_' . $line . '" value="' . $product['name'] . '">'; $form .= '<input type="hidden" name="amount_' . $line . '" value="' . number_format($product['price'], 2) . '">'; $form .= '<input type="hidden" name="quantity_' . $line . '" value="' . $_SESSION['cart'][$product['id']] . '">'; $form .= '<input type="hidden" name="shipping_' . $line . '" value="' . $item_shipping . '">'; $total += $product['price'] * $_SESSION['cart'][$product['id']]; $line++; }
  2. Here are some edits I have been trying if you need a laugh. /** * Adds item to the cart * * @access public * @param int, int,int * @return null */ public function add($id, $num = 1, $pronum = 30) { // setup or retrieve cart $cart = array(); if (isset($_SESSION['cart'])) { $cart = $_SESSION['cart']; } // check to see if item is already in cart if (isset($cart[$id])) { // if item is in cart $cart[$id] = $cart[$id] + $num ; } else { // if item is not in cart $cart[$id] = $num && $pronum; } $_SESSION['cart'] = $cart; } /** * Update the quantity of a specific item in the cart * * @access public * @param int, int, int * @return NULL */ public function update($id, $num, $pronum) { if ($num == 0) { unset($_SESSION['cart'][$id]); } else { $_SESSION['cart'][$id] = $num; } if ($pronum == 0) { unset($_SESSION['cart'][$id]); } else { $_SESSION['cart'][$id] = $pronum; } }
  3. Thanks very much for responding! I would like to integrate the Procarb# very much the same as the quantity number. I would like it to add to the cart session array, with a value of 30, by default when an item is added. Then, the user can update either value. One difference is that if a user adds the same product to the cart Id like to generate a new cart row so that a user would be able to submit one row of product A x Procarb# 30 x Quantity: 5. and another row of product A x Procarb# 20 x quantity 5. I think if I better understood the whole life cycle of the Quantity value I could recreate it better. So far I have made updates to the cart model so that I see the heading Procarb# next to Quantity in the rendered cart, there are two inputs there but only one works. I am hitting this message: Notice: Undefined variable: procarb in C:\xampp\htdocs\phpcartoopmvc-projectfiles\app\models\m_cart.php on line 253 Notice: Undefined index: in C:\xampp\htdocs\phpcartoopmvc-projectfiles\app\models\m_cart.php on line 253 Notice: Undefined variable: procarb in C:\xampp\htdocs\phpcartoopmvc-projectfiles\app\models\m_cart.php on line 256 Notice: Undefined index: in C:\xampp\htdocs\phpcartoopmvc-projectfiles\app\models\m_cart.php on line 256 So I am wondering how/where the variable 'product' is defined as the quantity when adding an item to the cart, and how I can make procarb generate in the exact same way and be a first multiplier in calculating the total and allow the user to adjust both numbers in the cart.
  4. I have been working with Ben Falk’s PHP shopping cart series and everything works very well. I am trying to slightly customize the cart array so that it includes a second multiplier value. I am planning to use this cart to place meal orders for a fitness and food service. As part of the service, a customer inputs their Procarb# in order to determine the serving size of their meal based on their lean body mass. So the array of numbers in the cart row that determines the total would be unit price x Procarb# x Quantity: I know that this is doable but I am having a hard time making this edit work as I am new to such dynamic designs. Can anyone help me determine where and how this edit should be made? -Ricky
×
×
  • Create New...