public function addToCart(Product $product, $quantity = 1, $method = 'add') { $cartSession = new Zend_Session_Namespace('shopping_cart'); $request = $this->getRequest(); if ($method == 'add') { $quantity = $cartSession->cartData[$product->getEntityId()]['quantity'] + 1; } $cart = new Application_Model_Zendshop_Cart(); $cart->unserialize($cartSession->cartData); $cartItem = new Application_Model_Zendshop_CartItem(); $cartItem->fromProduct($product); $cartItem->setQuantity($quantity); $cart->setCartItems($cartItem); $cartSession->cartData = $cart->serialize(); $cartSession->setExpirationSeconds(60 * 60 * 48); }
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param Product $obj A Product object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool($obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getEntityId(); } // if key === null ProductPeer::$instances[$key] = $obj; } }
/** * Exclude object from result * * @param Product $product Object to remove from the list of results * * @return ProductQuery The current query, for fluid interface */ public function prune($product = null) { if ($product) { $this->addUsingAlias(ProductPeer::ENTITY_ID, $product->getEntityId(), Criteria::NOT_EQUAL); } return $this; }