__("Machine"), self::TYPE_SPARE_PART => __("Spare Part"), self::TYPE_CONSUMABLE => __("Consumable"), ]; } // Object methods /** * @return Supplier * @throws Exception */ public function getSupplier(): Supplier { return Supplier::get($this->supplier_id); } public function getSlug(): string { return Util::slug("$this->name $this->id"); } public function getUrl(): string { return sprintf("/products/%s", $this->getSlug()); } public function getDisplayType(): string { return self::getTypeOptions()[$this->type] ?? ""; } public function getDisplayPrice(): string { return number_format($this->price, 2); } public function jsonSerialize(): array { return [ "id" => (int) $this->id, "supplierId" => (int) $this->supplier_id, "name" => $this->name, "sku" => $this->sku, "type" => (int) $this->type, "price" => $this->price, ]; } }