function testEventOnRemovePosition() { $this->setUp(); $cart = new EShoppingCart(); $this->testVar = false; $cart->attachEventHandler('onRemovePosition', array($this, 'testEventHandler')); $book = Book::model()->findByPk(1); $cart->put($book); $cart->remove($book->getId()); $this->assertTrue($cart->hasEvent('onRemovePosition')); $this->assertTrue($cart->hasEventHandler('onRemovePosition')); $this->assertTrue($this->testVar); }
public function actionSwitchDostavka() { $cart = new EShoppingCart(); $cart->init(); if ($_POST['dostavka'] == "on") { $productInCart = new ProductInCart(); $productInCart->name = $_POST['Доставка']; $productInCart->id = 100; $productInCart->count = 1; $productInCart->priceForThisCount = 200; //Цена доставки!!! $cart->put($productInCart); } else { $cart->remove(100); } $totalPrice = 0; $positions = $cart->getPositions(); foreach ($positions as $position) { $totalPrice += $position->priceForThisCount; } echo $totalPrice; }