本文整理汇总了PHP中Discount::get_matching方法的典型用法代码示例。如果您正苦于以下问题:PHP Discount::get_matching方法的具体用法?PHP Discount::get_matching怎么用?PHP Discount::get_matching使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Discount
的用法示例。
在下文中一共展示了Discount::get_matching方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
public function __construct(\Order $order, $context = array())
{
$this->order = $order;
// get qualifying discounts for this order
$this->discounts = \Discount::get_matching($this->order, $context);
$this->modifier = $this->order->getModifier("OrderDiscountModifier", true);
}
示例2: testItemLevelPercentAndAmountDiscounts
function testItemLevelPercentAndAmountDiscounts()
{
OrderDiscount::create(array("Title" => "10% off", "Type" => "Percent", "Percent" => 0.1))->write();
OrderDiscount::create(array("Title" => "\$5 off", "Type" => "Amount", "Amount" => 5))->write();
//check that discount matches order
$matching = Discount::get_matching($this->cart);
$this->assertDOSEquals(array(array("Title" => "10% off"), array("Title" => "\$5 off")), $matching);
$calculator = new Calculator($this->emptycart);
$this->assertEquals(0, $calculator->calculate(), "nothing in cart");
//check that best discount was chosen
$calculator = new Calculator($this->cart);
$this->assertEquals(5, $calculator->calculate(), "\$5 off \$8 is best discount");
$calculator = new Calculator($this->othercart);
$this->assertEquals(20, $calculator->calculate(), "10% off \$400 is best discount");
//total discount calculation
//20 * socks($8) = 160 ...$5 off each = 100
//10 * tshirt($25) = 250 ..$5 off each = 50
//2 * mp3player($200) = 400 ..10% off each = 40
//total discount: 190
$calculator = new Calculator($this->megacart);
$this->assertEquals(190, $calculator->calculate(), "complex savings example");
$this->assertDOSEquals(array(array("Title" => "10% off"), array("Title" => "\$5 off")), $this->megacart->Discounts());
}