PluginProbe
Tiered Pricing Table for WooCommerce / 8.0.2
Tiered Pricing Table for WooCommerce v8.0.2
8.0.2 7.1.7 7.1.5 7.1.4 7.1.1 6.5.0 6.4.0 6.1.0 trunk 1.0 1.1 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.3.0 2.3.1 2.3.2 2.3.3 All 91 releases
← All changes | src/PricingRule.php +47 -13 6.4.0 → 8.0.2 View file →
@@ -1,23 +1,28 @@
1 1 <?php namespace TierPricingTable;
2 2
3 +use WC_Product;
4 +
3 5 class PricingRule {
4 6
5 - protected $minimum = null;
6 - protected $rules = array();
7 - protected $type = 'fixed';
8 - protected $productId;
7 + protected ?int $minimum = null;
8 + protected ?bool $mixAndMatchMinQuantity = null;
9 + protected array $rules = array();
10 + protected string $type = 'fixed';
11 + protected int $productId;
9 12
10 - public $provider = 'product';
11 - public $providerData = array();
13 + protected ?WC_product $product = null;
12 14
13 - protected $modificationLog = array();
15 + public string $provider = 'product';
16 + public array $providerData = array();
14 17
15 - public $data = array();
18 + protected array $modificationLog = array();
16 19
17 - public $customColumnsData = array();
20 + public array $data = array();
18 21
19 - public $pricingData = array(
22 + public array $customColumnsData = array();
23 +
24 + public array $pricingData = array(
20 25 'regular_price' => null,
21 26 'sale_price' => null,
22 27 'discount' => null,
23 28 'pricing_type' => null, // fixed or percentage
@@ -24,10 +29,15 @@
24 29 'tax_status' => null,
25 30 'tax_class' => null,
26 31 );
27 32
28 - public function __construct( $productId ) {
29 - $this->productId = intval( $productId );
33 + public function __construct( $productOrId ) {
34 + if ( $productOrId instanceof WC_Product ) {
35 + $this->product = $productOrId;
36 + $this->productId = $productOrId->get_id();
37 + } else {
38 + $this->productId = intval( $productOrId );
39 + }
30 40 }
31 41
32 42 public function getProductId(): int {
33 43 return $this->productId;
@@ -32,8 +42,17 @@
32 42 public function getProductId(): int {
33 43 return $this->productId;
34 44 }
35 45
46 + public function getProduct(): ?WC_Product {
47 + if ( $this->product === null ) {
48 + $product = wc_get_product( $this->productId );
49 + $this->product = $product ?: null;
50 + }
51 +
52 + return $this->product;
53 + }
54 +
36 55 public function getMinimum( $forceValue = false ): ?int {
37 56
38 57 if ( $forceValue ) {
39 58 return $this->minimum ?: 1;
@@ -45,8 +64,23 @@
45 64 public function setMinimum( ?int $minimum ) {
46 65 $this->minimum = $minimum > 0 ? $minimum : null;
47 66 }
48 67
68 + public function isMixAndMatchMinQuantity(): ?bool {
69 + if ( $this->mixAndMatchMinQuantity ) {
70 + $product = $this->getProduct();
71 + if ( ! $product || ( ! $product->is_type( 'variable' ) && ! $product->is_type( 'variation' ) ) ) {
72 + return false;
73 + }
74 + }
75 +
76 + return $this->mixAndMatchMinQuantity;
77 + }
78 +
79 + public function setMixAndMatchMinQuantity( ?bool $mixAndMatch ) {
80 + $this->mixAndMatchMinQuantity = $mixAndMatch;
81 + }
82 +
49 83 public function getRules(): array {
50 84 return $this->rules;
51 85 }
52 86
@@ -78,8 +112,8 @@
78 112 public function logPricingModification( string $modification ) {
79 113 $this->modificationLog[] = $modification;
80 114 }
81 115
82 - public function getPricingLog() {
116 + public function getPricingLog(): array {
83 117 return $this->modificationLog;
84 118 }
85 119 }