docs/api/source-catalog.model.localisation.stock_status.html
| 1: | <?php |
| 2: | namespace Opencart\Catalog\Model\Localisation; |
| 3: | /** |
| 4: | * Class StockStatus |
| 5: | * |
| 6: | * @package Opencart\Catalog\Model\Localisation |
| 7: | */ |
| 8: | class StockStatus extends \Opencart\System\Engine\Model { |
| 9: | /** |
| 10: | * Get Stock Status |
| 11: | * |
| 12: | * @param int $stock_status_id |
| 13: | * |
| 14: | * @return array<string, mixed> |
| 15: | */ |
| 16: | public function getStockStatus(int $stock_status_id): array { |
| 17: | $query = $this->db->query("SELECT * FROM " . DB\_PREFIX . "stock\_status WHERE stock\_status\_id = '" . (int)$stock_status_id . "' AND language_id = '" . (int)$this->config->get('config_language_id') . "'"); |
| 18: | |
| 19: | return $query->row; |
| 20: | } |
| 21: | |
| 22: | /** |
| 23: | * Get Stock Statuses |
| 24: | * |
| 25: | * @param array<string, mixed> $data |
| 26: | * |
| 27: | * @return array<int, array<string, mixed>> |
| 28: | */ |
| 29: | public function getStockStatuses(array $data = []): array { |
| 30: | $sql = "SELECT * FROM " . DB\_PREFIX . "stock\_status WHERE language\_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY name"; |
| 31: | |
| 32: | if (isset($data['order']) && ($data['order'] == 'DESC')) { |
| 33: | $sql .= " DESC"; |
| 34: | } else { |
| 35: | $sql .= " ASC"; |
| 36: | } |
| 37: | |
| 38: | if (isset($data['start']) || isset($data['limit'])) { |
| 39: | if ($data['start'] < 0) { |
| 40: | $data['start'] = 0; |
| 41: | } |
| 42: | |
| 43: | if ($data['limit'] < 1) { |
| 44: | $data['limit'] = 20; |
| 45: | } |
| 46: | |
| 47: | $sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit']; |
| 48: | } |
| 49: | |
| 50: | $key = md5($sql); |
| 51: | |
| 52: | $stock_status_data = $this->cache->get('stock_status.' . $key); |
| 53: | |
| 54: | if (!$stock_status_data) { |
| 55: | $query = $this->db->query($sql); |
| 56: | |
| 57: | $stock_status_data = $query->rows; |
| 58: | |
| 59: | $this->cache->set('stock_status.' . $key, $stock_status_data); |
| 60: | } |
| 61: | |
| 62: | return $stock_status_data; |
| 63: | } |
| 64: | } |
| 65: | |
OpenCart API API documentation generated by ApiGen dev-master