</div> <div id="sfcart_center"> <div id="sfcart_breadcrumbs"> <?php cart::display_breadcrumbs($catid); ?> <div style="clear:both"></div> </div> <?php if (isset($product)) { $product->display(); } else { cart::display_products($catid); } ?> <div style="clear:both"></div> </div> <div id="sfcart_right"> <?php cart::display_cart(); ?> </div> <div style="clear:both"></div> </div>
public function executeUpdate(sfWebRequest $request) { $cart = $this->getUser()->getAttribute('cart', new cartCore()); if ($request->getParameter('cart_remove')) { $cart->del_item($request->getParameter('cart_remove')); } if ($request->getParameter('cart_empty')) { $cart->empty_cart(); } $qty = $request->getParameter('productqty'); $id = $request->getParameter('productid'); $name = $request->getParameter('productname'); $price = $request->getParameter('productprice'); $path = $request->getParameter('productpath'); $weight = $request->getParameter('productweight'); $url = $request->getParameter('producturl'); if ($qty != null and $id != null and $name != null and $price != null) { $cartQuantity = 0; foreach ($cart->get_contents() as $item) { if ($item['id'] == $id) { $cartQuantity = $item["qty"]; break; } } $product = Doctrine::getTable('product')->createQuery('a')->where('id=' . $id)->execute(); $qtyInStock = $product[0]['quantity']; $truePrice = $product[0]['price']; $notice = ""; if ($price != $truePrice) { $notice = "<div class='cartwarning'>An error occured. (price has been tampered)</div>"; } elseif ($qtyInStock < $qty + $cartQuantity) { $notice = "<div class='cartwarning'>Sorry, only " . $qtyInStock . " " . $name . " are left in stock.</div>"; } else { $cart->add_item($id, $qty, $price, $name, $weight, $path, $url); $notice = "<div class='cartmessage'>Added " . $qty . " " . $name . " to your cart.</div>"; } if ($request->isXmlHttpRequest()) { cart::display_cart($notice); return true; } else { $this->getUser()->setFlash('notice', sprintf($notice)); } } $this->redirect($request->getReferer()); }