woocommerce/includes/class-wc-order-item-coupon.php

180 lines
3.7 KiB
PHP
Raw Normal View History

2016-06-21 19:10:09 +00:00
<?php
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Order Line Item (coupon).
*
2017-03-15 16:36:53 +00:00
* @version 3.0.0
* @since 3.0.0
2016-06-21 19:10:09 +00:00
* @package WooCommerce/Classes
* @author WooCommerce
2016-06-21 19:10:09 +00:00
*/
class WC_Order_Item_Coupon extends WC_Order_Item {
/**
2017-03-15 16:36:53 +00:00
* Order Data array. This is the core order data exposed in APIs since 3.0.0.
* @since 3.0.0
2016-06-21 19:10:09 +00:00
* @var array
*/
2016-11-17 21:30:34 +00:00
protected $extra_data = array(
2016-08-16 11:36:38 +00:00
'code' => '',
'discount' => 0,
'discount_tax' => 0,
2016-06-21 19:10:09 +00:00
);
/*
|--------------------------------------------------------------------------
| Setters
|--------------------------------------------------------------------------
*/
/**
* Set order item name.
2016-11-17 21:30:34 +00:00
*
2016-06-21 19:10:09 +00:00
* @param string $value
2016-08-24 09:46:29 +00:00
* @throws WC_Data_Exception
2016-06-21 19:10:09 +00:00
*/
public function set_name( $value ) {
2016-08-23 14:25:50 +00:00
return $this->set_code( $value );
2016-06-21 19:10:09 +00:00
}
/**
* Set code.
2016-11-17 21:30:34 +00:00
*
2016-06-21 19:10:09 +00:00
* @param string $value
2016-08-24 09:46:29 +00:00
* @throws WC_Data_Exception
2016-06-21 19:10:09 +00:00
*/
public function set_code( $value ) {
2016-11-17 21:30:34 +00:00
$this->set_prop( 'code', wc_clean( $value ) );
2016-06-21 19:10:09 +00:00
}
/**
* Set discount amount.
2016-11-17 21:30:34 +00:00
*
2016-06-21 19:10:09 +00:00
* @param string $value
2016-08-24 09:46:29 +00:00
* @throws WC_Data_Exception
2016-06-21 19:10:09 +00:00
*/
public function set_discount( $value ) {
2016-11-17 21:30:34 +00:00
$this->set_prop( 'discount', wc_format_decimal( $value ) );
2016-06-21 19:10:09 +00:00
}
/**
* Set discounted tax amount.
2016-11-17 21:30:34 +00:00
*
2016-06-21 19:10:09 +00:00
* @param string $value
2016-08-24 09:46:29 +00:00
* @throws WC_Data_Exception
2016-06-21 19:10:09 +00:00
*/
public function set_discount_tax( $value ) {
2016-11-17 21:30:34 +00:00
$this->set_prop( 'discount_tax', wc_format_decimal( $value ) );
2016-06-21 19:10:09 +00:00
}
/*
|--------------------------------------------------------------------------
| Getters
|--------------------------------------------------------------------------
*/
/**
* Get order item type.
2016-11-17 21:30:34 +00:00
*
2016-06-21 19:10:09 +00:00
* @return string
*/
public function get_type() {
2016-06-21 19:10:09 +00:00
return 'coupon';
}
/**
* Get order item name.
2016-11-17 21:30:34 +00:00
*
* @param string $context
2016-06-21 19:10:09 +00:00
* @return string
*/
2016-11-17 21:30:34 +00:00
public function get_name( $context = 'view' ) {
return $this->get_code( $context );
2016-06-21 19:10:09 +00:00
}
/**
* Get coupon code.
2016-11-17 21:30:34 +00:00
*
* @param string $context
2016-06-21 19:10:09 +00:00
* @return string
*/
2016-11-17 21:30:34 +00:00
public function get_code( $context = 'view' ) {
return $this->get_prop( 'code', $context );
2016-06-21 19:10:09 +00:00
}
/**
* Get discount amount.
2016-11-17 21:30:34 +00:00
*
* @param string $context
2016-06-21 19:10:09 +00:00
* @return string
*/
2016-11-17 21:30:34 +00:00
public function get_discount( $context = 'view' ) {
return $this->get_prop( 'discount', $context );
2016-06-21 19:10:09 +00:00
}
/**
* Get discounted tax amount.
*
* @param string $context
*
2016-06-21 19:10:09 +00:00
* @return string
*/
2016-11-17 21:30:34 +00:00
public function get_discount_tax( $context = 'view' ) {
return $this->get_prop( 'discount_tax', $context );
}
/*
|--------------------------------------------------------------------------
| Array Access Methods
|--------------------------------------------------------------------------
|
| For backwards compatibility with legacy arrays.
2016-11-17 21:30:34 +00:00
|
*/
/**
* offsetGet for ArrayAccess/Backwards compatibility.
* @deprecated Add deprecation notices in future release.
* @param string $offset
* @return mixed
*/
public function offsetGet( $offset ) {
if ( 'discount_amount' === $offset ) {
$offset = 'discount';
} elseif ( 'discount_amount_tax' === $offset ) {
$offset = 'discount_tax';
}
return parent::offsetGet( $offset );
}
/**
* offsetSet for ArrayAccess/Backwards compatibility.
* @deprecated Add deprecation notices in future release.
* @param string $offset
* @param mixed $value
*/
public function offsetSet( $offset, $value ) {
if ( 'discount_amount' === $offset ) {
$offset = 'discount';
} elseif ( 'discount_amount_tax' === $offset ) {
$offset = 'discount_tax';
}
parent::offsetSet( $offset, $value );
}
/**
* offsetExists for ArrayAccess
* @param string $offset
* @return bool
*/
public function offsetExists( $offset ) {
if ( in_array( $offset, array( 'discount_amount', 'discount_amount_tax' ) ) ) {
return true;
}
return parent::offsetExists( $offset );
}
2016-06-21 19:10:09 +00:00
}