386 lines
8.8 KiB
PHP
386 lines
8.8 KiB
PHP
<?php
|
|
|
|
namespace KupShop\CatalogBundle\Entity;
|
|
|
|
use KupShop\CatalogBundle\Util\ProductAvailabilityUtil;
|
|
use KupShop\ComponentsBundle\Entity\Thumbnail;
|
|
use KupShop\KupShopBundle\Arrayable;
|
|
use KupShop\KupShopBundle\Util\Price\Price;
|
|
|
|
#[\AllowDynamicProperties]
|
|
class Variation implements \ArrayAccess, Arrayable
|
|
{
|
|
private int $id;
|
|
private int $idProduct;
|
|
private array $labels;
|
|
private array $values;
|
|
private ?string $code;
|
|
private ?int $ean;
|
|
private ?string $title;
|
|
private int $inStore;
|
|
private ?int $inStoreSuppliers = null;
|
|
private ?int $forecastedPieces = null;
|
|
private ?\DateTimeImmutable $forecastedDeliveryDate;
|
|
private int $deliveryTime;
|
|
private ?Price $price;
|
|
private ?string $priceBuy;
|
|
private ?Price $priceForDiscount;
|
|
private string $figure;
|
|
private \DateTimeImmutable $updated;
|
|
private \DateTimeImmutable $dateAdded;
|
|
private ?float $weight;
|
|
private ?float $width;
|
|
private ?float $height;
|
|
private ?float $depth;
|
|
private ?int $bonusPoints;
|
|
private ?array $data;
|
|
private ?int $photo;
|
|
|
|
private const ARRAY_MAPPING = [
|
|
'id_product' => 'idProduct',
|
|
'in_store' => 'inStore',
|
|
'delivery_time' => 'deliveryTimeText',
|
|
'delivery_time_index' => 'deliveryTime',
|
|
'delivery_time_text' => 'deliveryTimeText',
|
|
'delivery_time_raw' => 'deliveryTimeRaw',
|
|
'price_for_discount' => 'priceForDiscount',
|
|
'date_added' => 'dateAdded',
|
|
'bonus_points' => 'bonusPoints',
|
|
'productPrice' => 'price',
|
|
'price_buy' => 'priceBuy',
|
|
'in_store_suppliers' => 'inStoreSuppliers',
|
|
];
|
|
|
|
public function getId(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
public function setId(int $id): void
|
|
{
|
|
$this->id = $id;
|
|
}
|
|
|
|
public function getIdProduct(): int
|
|
{
|
|
return $this->idProduct;
|
|
}
|
|
|
|
public function setIdProduct(int $idProduct): void
|
|
{
|
|
$this->idProduct = $idProduct;
|
|
}
|
|
|
|
public function getLabels(): array
|
|
{
|
|
return $this->labels;
|
|
}
|
|
|
|
public function setLabels(array $labels): void
|
|
{
|
|
$this->labels = $labels;
|
|
}
|
|
|
|
public function getValues(): array
|
|
{
|
|
return $this->values;
|
|
}
|
|
|
|
public function setValues(array $values): void
|
|
{
|
|
$this->values = $values;
|
|
}
|
|
|
|
public function getCode(): ?string
|
|
{
|
|
return $this->code;
|
|
}
|
|
|
|
public function setCode(?string $code): void
|
|
{
|
|
$this->code = $code;
|
|
}
|
|
|
|
public function getEan(): ?int
|
|
{
|
|
return $this->ean;
|
|
}
|
|
|
|
public function setEan(?int $ean): void
|
|
{
|
|
$this->ean = $ean;
|
|
}
|
|
|
|
public function getTitle(): ?string
|
|
{
|
|
return $this->title;
|
|
}
|
|
|
|
public function setTitle(?string $title): void
|
|
{
|
|
$this->title = $title;
|
|
}
|
|
|
|
public function getInStore(): int
|
|
{
|
|
return $this->inStore;
|
|
}
|
|
|
|
public function setInStore(int $inStore): void
|
|
{
|
|
$this->inStore = $inStore;
|
|
}
|
|
|
|
public function getInStoreSuppliers(): ?int
|
|
{
|
|
return $this->inStoreSuppliers;
|
|
}
|
|
|
|
public function setInStoreSuppliers(?int $inStoreSuppliers): void
|
|
{
|
|
$this->inStoreSuppliers = $inStoreSuppliers;
|
|
}
|
|
|
|
public function getForecastedPieces(): ?int
|
|
{
|
|
return $this->forecastedPieces;
|
|
}
|
|
|
|
public function setForecastedPieces(int|string|null $forecastedPieces): void
|
|
{
|
|
$this->forecastedPieces = $forecastedPieces === null ? null : ((int) $forecastedPieces);
|
|
}
|
|
|
|
public function getForecastedDeliveryDate(): ?\DateTimeImmutable
|
|
{
|
|
return $this->forecastedDeliveryDate;
|
|
}
|
|
|
|
public function setForecastedDeliveryDate(?\DateTimeImmutable $forecastedDeliveryDate): void
|
|
{
|
|
$this->forecastedDeliveryDate = $forecastedDeliveryDate;
|
|
}
|
|
|
|
public function getTotalAvailablePieces(): int
|
|
{
|
|
return ProductAvailabilityUtil::getAvailablePieces($this->inStore, $this->inStoreSuppliers);
|
|
}
|
|
|
|
public function getDeliveryTime(): int
|
|
{
|
|
[$deliveryTime] = ProductAvailabilityUtil::getDeliveryTime($this->deliveryTime, $this->inStore, $this->inStoreSuppliers);
|
|
|
|
return $deliveryTime;
|
|
}
|
|
|
|
public function getDeliveryTimeText(): string
|
|
{
|
|
[, $deliveryTimeText] = ProductAvailabilityUtil::getDeliveryTime($this->deliveryTime, $this->inStore, $this->inStoreSuppliers);
|
|
|
|
return $deliveryTimeText;
|
|
}
|
|
|
|
public function isSoldOut(): bool
|
|
{
|
|
return $this->getTotalAvailablePieces() <= 0;
|
|
}
|
|
|
|
public function getDeliveryTimeRaw(): int
|
|
{
|
|
return $this->deliveryTime;
|
|
}
|
|
|
|
public function setDeliveryTime(int $deliveryTime): void
|
|
{
|
|
$this->deliveryTime = $deliveryTime;
|
|
}
|
|
|
|
public function getPrice(): ?Price
|
|
{
|
|
return $this->price;
|
|
}
|
|
|
|
public function setPrice(?Price $price): void
|
|
{
|
|
$this->price = $price;
|
|
}
|
|
|
|
public function getPriceBuy(): ?string
|
|
{
|
|
return $this->priceBuy;
|
|
}
|
|
|
|
public function setPriceBuy(?string $priceBuy): void
|
|
{
|
|
$this->priceBuy = $priceBuy;
|
|
}
|
|
|
|
public function getPriceForDiscount(): ?Price
|
|
{
|
|
return $this->priceForDiscount;
|
|
}
|
|
|
|
public function setPriceForDiscount(?Price $priceForDiscount): void
|
|
{
|
|
$this->priceForDiscount = $priceForDiscount;
|
|
}
|
|
|
|
public function getFigure(): string
|
|
{
|
|
return $this->figure;
|
|
}
|
|
|
|
public function setFigure(string $figure): void
|
|
{
|
|
$this->figure = $figure;
|
|
}
|
|
|
|
public function getUpdated(): \DateTimeImmutable
|
|
{
|
|
return $this->updated;
|
|
}
|
|
|
|
public function setUpdated(string $updated): void
|
|
{
|
|
$this->updated = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $updated);
|
|
}
|
|
|
|
public function getDateAdded(): \DateTimeImmutable
|
|
{
|
|
return $this->dateAdded;
|
|
}
|
|
|
|
public function setDateAdded(string $dateAdded): void
|
|
{
|
|
$this->dateAdded = \DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $dateAdded);
|
|
}
|
|
|
|
public function getWeight(): ?float
|
|
{
|
|
return $this->weight;
|
|
}
|
|
|
|
public function setWeight(float|string|null $weight): void
|
|
{
|
|
$this->weight = $weight === null ? null : ((float) $weight);
|
|
}
|
|
|
|
public function getWidth(): ?float
|
|
{
|
|
return $this->width;
|
|
}
|
|
|
|
public function setWidth(float|string|null $width): void
|
|
{
|
|
$this->width = $width === null ? null : ((float) $width);
|
|
}
|
|
|
|
public function getHeight(): ?float
|
|
{
|
|
return $this->height;
|
|
}
|
|
|
|
public function setHeight(float|string|null $height): void
|
|
{
|
|
$this->height = $height === null ? null : ((float) $height);
|
|
}
|
|
|
|
public function getDepth(): ?float
|
|
{
|
|
return $this->depth;
|
|
}
|
|
|
|
public function setDepth(float|string|null $depth): void
|
|
{
|
|
$this->depth = $depth === null ? null : ((float) $depth);
|
|
}
|
|
|
|
public function getBonusPoints(): ?int
|
|
{
|
|
return $this->bonusPoints;
|
|
}
|
|
|
|
public function setBonusPoints(?int $bonusPoints): void
|
|
{
|
|
$this->bonusPoints = $bonusPoints;
|
|
}
|
|
|
|
public function getData(): ?array
|
|
{
|
|
return $this->data;
|
|
}
|
|
|
|
public function setData(?array $data): void
|
|
{
|
|
$this->data = $data;
|
|
}
|
|
|
|
public function getPhoto(): ?int
|
|
{
|
|
return $this->photo;
|
|
}
|
|
|
|
public function setPhoto(?int $photo): void
|
|
{
|
|
$this->photo = $photo;
|
|
}
|
|
|
|
public function getThumbnail(): ?Thumbnail
|
|
{
|
|
if (empty($this->photo)) {
|
|
return null;
|
|
}
|
|
|
|
return new Thumbnail((string) $this->photo, $this->title, $this->updated->format('Y-m-d H:i:s'));
|
|
}
|
|
|
|
public function offsetExists(mixed $offset): bool
|
|
{
|
|
return array_key_exists($offset, self::ARRAY_MAPPING)
|
|
|| isset($this->{$offset});
|
|
}
|
|
|
|
public function offsetGet(mixed $offset): mixed
|
|
{
|
|
if (isset(self::ARRAY_MAPPING[$offset])) {
|
|
$offset = self::ARRAY_MAPPING[$offset];
|
|
}
|
|
|
|
if (method_exists($this, 'get'.$offset)) {
|
|
return $this->{'get'.$offset}();
|
|
}
|
|
|
|
return $this->{$offset};
|
|
}
|
|
|
|
public function offsetSet(mixed $offset, mixed $value): void
|
|
{
|
|
if (isset(self::ARRAY_MAPPING[$offset])) {
|
|
$offset = self::ARRAY_MAPPING[$offset];
|
|
}
|
|
|
|
if (method_exists($this, 'set'.$offset)) {
|
|
$this->{'set'.$offset}($value);
|
|
|
|
return;
|
|
}
|
|
|
|
$this->{$offset} = $value;
|
|
}
|
|
|
|
public function offsetUnset(mixed $offset): void
|
|
{
|
|
throw new \LogicException();
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
$snakeCase = array_map(
|
|
fn (string $propertyName) => $this->{$propertyName} ?? null,
|
|
self::ARRAY_MAPPING,
|
|
);
|
|
|
|
return array_merge(get_object_vars($this), $snakeCase);
|
|
}
|
|
}
|