Пример #1
0
 static function _get_product_discount($amount, $products, $cart_items, $type = 'amount')
 {
     $discount = 0;
     if (!empty($products)) {
         foreach ($products as $key) {
             if (self::_check_in_items($key, $cart_items)) {
                 if ($type == 'amount') {
                     if ($cart_items[$key]['price'] > $amount) {
                         $discount += $amount;
                     } else {
                         $discount += $cart_items[$key]['price'];
                     }
                 } elseif ($type == 'percent') {
                     if ($amount > 100) {
                         $amount = 100;
                     }
                     $discount += $cart_items[$key]['price'] / 100 * $amount;
                 }
             }
         }
     }
     if (!empty($cart_items)) {
         foreach ($cart_items as $key => $value) {
             $booking_id = TravelerObject::get_orgin_booking_id($key);
             if (in_array($booking_id, $products)) {
                 if ($type == 'amount') {
                     if ($value['price'] > $amount) {
                         $discount += $amount;
                     } else {
                         $discount += $value['price'];
                     }
                 } elseif ($type == 'percent') {
                     if ($amount > 100) {
                         $amount = 100;
                     }
                     $discount += $value['price'] / 100 * $amount;
                 }
             }
         }
     }
     return $discount;
 }