Пример #1
0
 public function executeCheckoutFinished(sfWebRequest $request)
 {
     $cart = tpyCart::getInstance($this->getUser());
     $cart->clear();
     $cart->save();
     $this->order = Doctrine::getTable('tpyOrder')->findOneById($this->getUser()->getFlash('timpany_last_order_id'));
 }
Пример #2
0
 /**
  * get singleton instance
  * @param sfUser $sfUser
  * @return tpyCart
  */
 public static function getInstance(sfUser $sfUser)
 {
     if (is_null(self::$_instance)) {
         if ($sfUser->isAuthenticated()) {
             self::$_instance = tpyUserCartTable::getInstance()->findOneBySfGuardUserId($sfUser->getGuardUser()->getId());
             if (false == self::$_instance) {
                 self::$_instance = new tpyUserCart();
                 self::$_instance->setSfGuardUserId($sfUser->getGuardUser()->getId());
             }
         } else {
             self::$_instance = new tpyCart();
             self::$_instance->_user = $sfUser;
             self::$_instance->_items = $sfUser->getAttribute('cart_items', array(), tpyCart::SESSION_NS);
         }
     }
     return self::$_instance;
 }
Пример #3
0
/**
 * tpyCart tests.
 */
include dirname(__FILE__) . '/../../../../../test/bootstrap/unit.php';
//$configuration = ProjectConfiguration::getApplicationConfiguration( 'frontend', 'test', true);
new sfDatabaseManager($configuration);
$t = new lime_test(24);
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 aSecurityUser($guestDispatcher, $guestStorage);
$product_1 = tpyProductTable::getInstance()->findOneById(1);
$product_2 = tpyProductTable::getInstance()->findOneById(2);
$guestCart = tpyCart::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');