__("Machine"), self::TYPE_SPARE_PART => __("Spare Part"), self::TYPE_CONSUMABLE => __("Consumable"), self::TYPE_DELIVERY_CHARGE => __("Delivery Charge"), ]; } // 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 getWebsiteUrl(): ?string { return $this->url; } 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, ]; } public function getBrochurePath(): string { return $_ENV["DIR_ROOT"] . "/files/product/" . $this->id . ".pdf"; } public function hasBrochure(): bool { return file_exists($this->getBrochurePath()); } public function deleteBrochure(): bool { return !$this->hasBrochure() || unlink($this->getBrochurePath()); } }