/** * @dataProvider testApplicableProvider * @group coupon */ public function testApplicable($period, $products, $applied) { $term = new Term($period); $term->setPrice(12.0); $product = new \Cart\Catalog\Product(); $product->setId(24); $product->getBilling()->addTerm($term); $catalog = new Catalog(); $item = $catalog->getCartItem($product); $cart = $this->getCart(); $cart->add($item); $total = $cart->total(); $coupon = new Coupon('COUPON'); $coupon->setProducts($products); $coupon->setType('PercentDiscount'); $coupon->setConfig(['percent' => 50]); $coupon->calculateDiscount($cart); $this->assertEquals($total != $cart->total(), $applied); }
public function import(array $array) { foreach ($array as $p) { $coupon = new Coupon(); $coupon->setCode($p['code']); $coupon->setType($p['type']); if (isset($p['products']) && !empty($p['products'])) { $coupon->setProducts($p['products']); } if (isset($p['config']) && !empty($p['config'])) { $coupon->setConfig($p['config']); } if (isset($p['valid_from']) && !empty($p['valid_from'])) { $coupon->setValidFrom($p['valid_from']); } if (isset($p['valid_until']) && !empty($p['valid_until'])) { $coupon->setValidUntil($p['valid_until']); } $this->addCoupon($coupon); } }