public function executeCheckoutFinished(sfWebRequest $request) { $cart = timpanyCart::getInstance($this->getUser()); $cart->clear(); $cart->save(); $this->order = Doctrine::getTable('timpanyOrder')->findOneById($this->getUser()->getFlash('timpany_last_order_id')); }
/** * get singleton instance * @param sfUser $sfUser * @return timpanyCart */ public static function getInstance(sfUser $sfUser) { if (is_null(self::$_instance)) { if ($sfUser->isAuthenticated()) { self::$_instance = timpanyUserCartTable::getInstance()->findOneBySfGuardUserId($sfUser->getGuardUser()->getId()); if (false == self::$_instance) { self::$_instance = new timpanyUserCart(); self::$_instance->setSfGuardUserId($sfUser->getGuardUser()->getId()); } } else { self::$_instance = new timpanyCart(); self::$_instance->_user = $sfUser; self::$_instance->_items = $sfUser->getAttribute('cart_items', array(), timpanyCart::SESSION_NS); } } return self::$_instance; }
public function executeCartInfo() { $this->product_count = timpanyCart::getInstance($this->getUser())->getProductCount(); }
/** * timpanyCart tests. */ include dirname(__FILE__) . '/../../../../../test/bootstrap/unit.php'; $t = new lime_test(24); $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true); new sfDatabaseManager($configuration); Doctrine_Core::loadData(dirname(__FILE__) . '/../../fixtures'); $_SERVER['session_id'] = 'test_guest'; $guestDispatcher = new sfEventDispatcher(); $guestSessionPath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'symfony_tests_' . rand(1, 999); $guestStorage = new sfSessionTestStorage(array('session_path' => $guestSessionPath)); $guestUser = new myUser($guestDispatcher, $guestStorage); $product_1 = timpanyProductTable::getInstance()->findOneById(1); $product_2 = timpanyProductTable::getInstance()->findOneById(2); $guestCart = timpanyCart::getInstance($guestUser); $t->is($guestCart->isEmpty(), true, 'cart is empty'); $t->comment('Put one item into cart.'); $guestCart->addProduct($product_1); $t->is($guestCart->isEmpty(), false, 'cart is not empty'); $t->is($guestCart->getItemCount(), 1, '1 item in cart'); $t->is($guestCart->getProductCount(), 1, '1 product in cart'); $t->is($guestCart->getNetSum(), 0.84, 'cart net sum is correct'); $t->is($guestCart->getGrossSum('de'), 0.9, 'cart gross sum is correct'); $t->comment('Put second item into cart.'); $guestCart->addProduct($product_2); $t->is($guestCart->isEmpty(), false, 'cart is not empty'); $t->is($guestCart->getItemCount(), 2, '2 items in cart'); $t->is($guestCart->getProductCount(), 2, '2 products in cart'); $t->is($guestCart->getNetSum(), 0.84, 'cart net sum is correct'); $t->is($guestCart->getGrossSum('de'), 0.9, 'cart gross sum is correct');
public function signOut() { parent::signOut(); timpanyCart::getInstance($this)->clear(); }