当前位置: 首页>>代码示例>>PHP>>正文


PHP Discount::get_matching方法代码示例

本文整理汇总了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);
 }
开发者ID:burnbright,项目名称:silverstripe-shop-discount,代码行数:7,代码来源:Calculator.php

示例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());
 }
开发者ID:helpfulrobot,项目名称:silvershop-discounts,代码行数:23,代码来源:CalculatorTest.php


注:本文中的Discount::get_matching方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。