PHP 8.2.31
Preview: AtSpecialPriceRule.php Size: 1.56 KB
//proc/self/root/home/nshryvcy/himaltourism.com/wp-content/themes/adventure-tours/includes/classes/AtSpecialPriceRule.php

<?php
/**
 * Special price rules processing service.
 * Makes price recalculation based on defined price rule.
 *
 * @author    Themedelight
 * @package   Themedelight/AdventureTours
 * @version   3.0.7
 */

class AtSpecialPriceRule extends TdComponent
{
	const TYPE_CONST = 'percent';

	const TYPE_ADD = 'add';

	const TYPE_EXACT = 'exact';

	public $min_valid_price = 0;

	public $type_matches = array(
		'percent' => '`^\d+(\.\d{0,2})?\%$`',
		'add' => '`^(\+|\-)\d+(\.\d{0,2})?$`',
		'exact' => '`^\d+(\.\d{0,2})?$`',
	);

	public function is_valid_rule( $rule ) {
		return $this->get_rule_type( $rule ) ? true : false;
	}

	public function get_rule_type( $rule ) {
		if ( $rule ) {
			$patters = $this->type_matches;
			foreach ($patters as $type => $pattern) {
				if ( preg_match( $pattern, $rule ) ) {
					return $type;
				}
			}
		}
		return null;
	}

	public function process_rule( $rule, $price ) {
		$type = $rule ? $this->get_rule_type( $rule ) : null;
		if ( $type ) {
			return $this->calculate_price_by_rule_type( $rule, $type, $price );
		}

		return $price;
	}

	protected function calculate_price_by_rule_type( $rule, $type, $price ) {
		$result = $price;
		switch ( $type ) {
		case self::TYPE_CONST:
			$result = (string) ( floatval( $rule ) / 100 * $result );
			break;
		case self::TYPE_ADD:
			$result += floatval( $rule );
			$result = (string) $result;
			break;
		case self::TYPE_EXACT:
			$result = $rule;
			break;
		}

		if ( is_numeric( $this->min_valid_price ) && $result < $this->min_valid_price ) {
			return $this->min_valid_price;
		}

		return $result;
	}
}

Directory Contents

Dirs: 0 × Files: 29

Name Size Perms Modified Actions
3.14 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
2.03 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
5.75 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
56.69 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
6.90 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
4.39 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
14.96 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
6.15 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
1.56 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
582 B lrw-r--r-- 2022-11-10 06:13:26
Edit Download
945 B lrw-r--r-- 2022-11-10 06:13:26
Edit Download
2.33 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
2.78 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
3.99 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
5.32 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
9.61 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
20.75 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
22.52 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
1.91 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
2.16 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
6.37 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
4.64 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
4.64 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
6.32 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
4.86 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
12.44 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
3.69 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
5.84 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download
12.11 KB lrw-r--r-- 2022-11-10 06:13:26
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).