/var/www/(Del)hsihk.com/wp-content/plugins/woocommerce/includes/gateways/mijireh/includes/Item.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php

if ( ! defined'ABSPATH' ) ) {
    exit; 
// Exit if accessed directly
}

class 
Mijireh_Item extends Mijireh_Model {

  private function 
_init() {
    
$this->_data = array(
      
'name' => null,
      
'price' => null,
      
'quantity' => 1,
      
'sku' => null
    
);
  }

  private function 
_check_required_fields() {
    if(empty(
$this->_data['name'])) {
      
$this->add_error('item name is required.');
    }

    if(!
is_numeric($this->_data['price'])) {
      
$this->add_error('price must be a number.');
    }
  }

  private function 
_check_quantity() {
    if(
$this->_data['quantity'] < 1) {
      
$this->add_error('quantity must be greater than or equal to 1');
    }
  }

  public function 
__construct() {
    
$this->_init();
  }

  public function 
__get($key) {
    
$value false;
    if(
$key == 'total') {
      
$value $this->_data['price'] * $this->_data['quantity'];
      
$value number_format($value2'.''');
    }
    else {
      
$value parent::__get($key);
    }
    return 
$value;
  }

  public function 
get_data() {
    
$data parent::get_data();
    
$data['total'] = $this->total;
    return 
$data;
  }

  public function 
validate() {
    
$this->_check_required_fields();
    
$this->_check_quantity();
    return 
count($this->_errors) == 0;
  }

}