Пример #1
0
 public function testMin()
 {
     $money = Money::fromPennies(1000);
     $money2 = Money::fromPennies(5000);
     $this->assertEqual(Money::min($money, $money2), $money);
     $this->assertEqual(Money::min($money2, $money), $money);
 }
Пример #2
0
 private function getOrderDiscounts($coupons, $shipping)
 {
     $orderDiscounts = array();
     $shippingDiscountAmount = Money::fromFloat(0);
     foreach ($coupons as $id => $coupon) {
         if ($coupon['order_scope_id'] == Coupon::SCOPE_SHIPPING) {
             if (!empty($coupon['discount_percentage'])) {
                 $shippingDiscountAmount = $shipping['total']->copy()->times($coupon['discount_percentage'] / 100);
             } else {
                 if (!empty($coupon['discount_flat'])) {
                     $shippingDiscountAmount = Money::fromString($coupon['discount_flat']);
                 }
             }
             $shippingDiscountAmount = Money::min($shippingDiscountAmount, $shipping['total']);
             $orderDiscounts[$id] = array("name" => $coupon['name'], "amount" => $shippingDiscountAmount, 'scope' => Coupon::SCOPE_SHIPPING);
         }
     }
     return $orderDiscounts;
 }