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: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102:
<?php
namespace Apptus\ESales\Connector;
/**
* An order line in a sale order.
*
*/
class OrderLine {
/** @internal */
public $key;
/** @internal */
public $keyType;
/** @internal */
public $annotations = array ();
/**
* @internal
*/
public function __construct($key, $keyType) {
$this->key = $key;
$this->keyType = $keyType;
}
/**
* Adds information about the current price (the price displayed in the shop) for each unit
* to this order line.
*
* @param float|int The price, in units of the market currency.
* @return OrderLine The line itself.
* @deprecated Current unit price is ignored by eSales. Use {@see putUnitSellingPrice()} instead.
*/
public function putCurrentUnitPrice($price) {
$this->setAnnotation('current_price', $price);
return $this;
}
/**
* Adds information about the cost (what it costs for the shop to acquire the product, including VAT) for each unit
* to this order line.
*
* Note: Some parts of eSales might behave strangely if cost is included in some, but not all, notified orders.
*
* @param float|int The cost, in units of the market currency.
* @return OrderLine The line itself.
*/
public function putUnitCost($price) {
$this->setAnnotation('cost', $price);
return $this;
}
/**
* Adds information about the selling price (the actual price that the customer pays, including VAT
* but excluding delivery costs) for each unit to this order line.
*
* @param float|int The price, in units of the market currency.
* @return OrderLine The line itself.
*/
public function putUnitSellingPrice($price) {
$this->setAnnotation('selling_price', $price);
return $this;
}
/**
* Adds information about the quantity. Default quantity is 1.
*
* @param int
* The number of units, a positive non-zero integer.
* @throws \InvalidArgumentException if quantity is not an integer.
* @return OrderLine The line itself.
*/
public function putQuantity($units) {
if (is_int($units)) {
$this->annotations['quantity'] = (string) $units;
} else {
$valueType = gettype($units) === 'object' ? get_class($units) : gettype($units);
throw new \InvalidArgumentException('Invalid value type. Expected integer, got ' . $valueType);
}
return $this;
}
/**
* Cast to string and work around that casting floats are locale dependent.
*
* @internal
* @param string
* Annotation type to set.
* @throws \InvalidArgumentException if value is not an integer or a float.
* @param float|int Value.
*/
private function setAnnotation($type, $value) {
if (is_int($value)) {
$this->annotations[$type] = (string) $value;
} elseif (is_float($value)) {
$this->annotations[$type] = sprintf('%F', $value); // %F is not locale aware (i.e. will never return 1,3)
// but it will always output 6 decimals (e.g. 0.000000 or 5.200000)
} else {
$valueType = gettype($value) === 'object' ? get_class($value) : gettype($value);
throw new \InvalidArgumentException('Invalid value type. Expected float or integer, got ' . $valueType);
}
}
}