Skip to content

Commit 0102909

Browse files
author
Ben Dubuisson
committed
add get registers call
1 parent dd32515 commit 0102909

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

src/VendAPI/VendAPI.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,26 @@ public function getProducts($options = array())
100100

101101
return $this->apiGetProducts($path);
102102
}
103+
104+
/**
105+
* Get all active registers
106+
*
107+
* @param array $options .. optional
108+
* @return array
109+
*/
110+
public function getRegisters($options = array())
111+
{
112+
$path = '';
113+
if (count($options)) {
114+
foreach ($options as $k => $v) {
115+
$v = urlencode($v); // ensure values with spaces etc are encoded properly
116+
$path .= '/'.$k.'/'.$v;
117+
}
118+
}
119+
120+
return $this->apiGetRegisters($path);
121+
}
122+
103123
/**
104124
* Get all sales
105125
*
@@ -213,6 +233,25 @@ private function apiGetSales($path)
213233

214234
return $sales;
215235
}
236+
/**
237+
* @param $path
238+
* @return array
239+
* @throws Exception
240+
*/
241+
private function apiGetRegisters($path)
242+
{
243+
$result = $this->_request('/api/registers'.$path);
244+
if (!isset($result->registers) || !is_array($result->registers)) {
245+
throw new Exception("Error: Unexpected result for request");
246+
}
247+
$sales = array();
248+
foreach ($result->register_sales as $s) {
249+
$sales[] = new VendSale($s, $this);
250+
}
251+
252+
return $sales;
253+
}
254+
216255
/**
217256
* Save vendproduct object to vend
218257
* @param object $product

0 commit comments

Comments
 (0)