public function calculateDiscount(Coupon $coupon, Cart $cart) { $config = $coupon->getConfig(); $over = $config['over']; $percent = $config['percent']; $total = $cart->totalExcludingTax(); if ($total > $over) { $discount = $total - $total * (1 - $percent / 100); $cart->setDiscount($discount); } }
/** * @param Cart $cart * @param string $cartItemId * @param int $amount */ protected function handlePOSTUpdateAmount($cart, $cartItemId, $amount) { if (!$cart->has($cartItemId)) { return; } if ($amount === 0) { $cart->remove($cartItemId); } else { $cart->update($cartItemId, 'quantity', intval($amount)); } }
public function testRestoreExceptions() { $exceptionCounter = 0; $store = m::mock('Cart\\Storage\\Store'); $store->shouldReceive('get')->times(6)->andReturn('!foo!', serialize('bar'), serialize(array('id' => 'foo')), serialize(array('items' => array())), serialize(array('id' => array(), 'items' => array())), serialize(array('items' => 'foo', 'id' => 'foo'))); $cart = new Cart('foo', $store); for ($i = 1; $i <= 6; $i++) { try { $cart->restore(); } catch (CartRestoreException $e) { $exceptionCounter++; } } $this->assertEquals($exceptionCounter, 6); }
public function getTotal() { return $this->cart->total() + $this->cart->icann() - $this->cart->getDiscount(); }
/** * @param string $id * @param Store $store * @param float $shippingCosts * @param float $shippingTax */ public function __construct($id, Store $store, $shippingCosts, $shippingTax) { $this->shippingCosts = $shippingCosts; $this->shippingTax = $shippingTax; parent::__construct($id, $store); }
/** * @param Cart $cart * @param Translator $i18n */ protected function addTemplateFakeData($cart, $i18n) { $cart->add(new CartItem(array('name' => $i18n->translate('fake.cartItem1.name'), 'pageId' => null, 'price' => 100, 'tax' => 19, 'variant' => null))); $cart->add(new CartItem(array('name' => $i18n->translate('fake.cartItem2.name'), 'pageId' => null, 'price' => 150, 'tax' => 27, 'variant' => null))); $cart->add(new CartItem(array('name' => $i18n->translate('fake.cartItem3.name'), 'pageId' => null, 'price' => 200, 'tax' => 38, 'variant' => null))); }