<?php/** * Base Order Item Model * * @author Bertin van den Ham <b.vandenham@visualmedia.nl> * @author Vincent van Waasbergen <v.vanwaasbergen@visualmedia.nl> */namespace VisualMedia\OrderBundle\Model;use VisualMedia\LisaBundle\Component\Interfaces\EntityInterface;use VisualMedia\OrderBundle\Entity\BaseOrderItem;use VisualMedia\ProductBundle\Entity\BaseProduct;/** * Base Order Item Model */abstract class BaseOrderItemModel{ /** * Entity * @var EntityInterface */ protected $entity; /** * Get Item Hash * * @return string */ public function getItemHash(): string { return md5(implode('-', array( $this->getEntity()->getId(), ))); } /** * Get Total * * @return float */ public function getTotal(): float { return $this->getAmount() * $this->getPrice(); } /** * Get Entity * * @return EntityInterface */ public function getEntity(): ?EntityInterface { return $this->entity; } /** * Set Entity * * @param EntityInterface $entity * * @return void */ public function setEntity(?EntityInterface $entity): void { $this->entity = $entity; } /** * Get Order * * @return BaseOrderModel */ public function getOrder(): ?BaseOrderModel { return $this->order; } /** * Set Order * * @param BaseOrderModel $order * * @return void */ public function setOrder(?BaseOrderModel $order): void { $this->order = $order; } /** * Get Reference * * @return string|null */ public function getReference(): ?string { return $this->reference; } /** * Set Reference * * @param string|null $reference */ public function setReference(?string $reference): void { $this->reference = $reference; } /** * Get Product * * @return BaseProduct|null */ public function getProduct(): ?BaseProduct { return $this->product; } /** * Set Product * * @param BaseProduct|null $product */ public function setProduct(BaseProduct $product = null): void { $this->product = $product; } /** * Get Reference Data * * @return array|null */ public function getReferenceData(): ?array { if(null !== $data = $this->referenceData) { return json_decode($data, true); } return $data; } /** * Set Reference Data * * @param array $referenceData */ public function setReferenceData(?array $referenceData): void { if($referenceData !== null) { $referenceData = json_encode($referenceData); } $this->referenceData = $referenceData; } /** * Get Amount * * @return int|null */ public function getAmount(): ?int { return $this->amount; } /** * Set Amount * * @param int $amount */ public function setAmount(int $amount): void { $this->amount = $amount; } /** * Get Price * * @return float */ public function getPrice(): ?float { return $this->price; } /** * Set Price * * @param float $price */ public function setPrice(?float $price): void { $this->price = $price; } /** * Get Vat * * @return float */ public function getVat(): ?float { return $this->vat; } /** * Set Vat * * @param float $vat */ public function setVat(?float $vat): void { $this->vat = $vat; } /** * IsFree * * @return bool */ public function isFree(): bool { return $this->free; } /** * SetFree * * @param bool $free */ public function setFree(bool $free): void { $this->free = $free; } /** * GetFree * * @return bool */ public function getFree(): bool { return $this->isFree(); }}