<?php
namespace Slivki\Entity;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use JsonSerializable;
use Doctrine\Common\Collections\Criteria;
use Slivki\Entity\Media\GiftCertificatePdfBgMedia;
use Slivki\Entity\Media\OfferAppTeaserMedia;
use Slivki\Entity\Media\OfferDeliveryZoneMedia;
use Slivki\Entity\Media\OfferMailingTeaserMedia;
use Slivki\Entity\Media\OfferMapLogoMedia;
use Slivki\Entity\Media\OfferMobileTeaserMedia;
use Slivki\Entity\Media\OfferTeaserMedia;
use Slivki\Entity\Media\OfferTopBlockMedia;
use Slivki\Entity\Media\OfferTopBlockMobileMedia;
use Slivki\Entity\Media\OnlineOrderPopupLogoMedia;
use Slivki\Enum\Offer\OfferOnlineOrderDevice;
use Slivki\Enum\Offer\OfferOnlineOrderType;
use Slivki\Enum\Offer\OfferStatus;
use Slivki\Util\CommonUtil;
use Slivki\Util\Iiko\Dominos;
use function in_array;
use function count;
class Offer extends Entity implements JsonSerializable
{
const TEASER_MEDIA_TYPE = "bsns-market-action-teaser-media";
const TEASER_MEDIA_PATH = "/public/znijki-media/initial/default/1009921/";
const DETAIL_MEDIA_PATH = "/public/znijki-media/initial/default/1009921/";
const SHOP_MEDIA_PATH = "/public/znijki-media/initial/default/1009921/";
const SUPPLIER_MEDIA_PATH = "/public/znijki-media/initial/default/1009921/";
const DESCRIPTION_IMAGES_PATH = '/public/ximage/';
const PETROL_OFFER_ID = 142938;
public const DREAMLAND_OFFER_ID = 141563;
public const DREAMLAND_NEW_OFFER_ID = 281797;
public const WHITE_LOTUS_OFFER_ID = 141075;
public const OBLAKA_SALON_OFFER_ID = 139498;
public const OBLAKA_ULTRASOUND_OFFER_ID = 279947;
public const BLACK_START_BURGER_OFFER_ID = 283384;
public const DOMINOS = 168243;
public const JASMIN_OFFER_ID = 247462;
public const TEST_CERTIFICATE_OFFER_ID = 286127;
const FITNESS_WORLD_OFFER_ID = 141207;
const KFC_OFFER_ID = 239232;
const CAR_SHARING_OFFER_ID = 275103;
const BOOKING_OFFER_ID = 275216;
const SUSHI_HOUSE_OFFER_ID = 131201;
const FREESTYLE_OFFER_ID = 137760;
const HEROPARK_OFFER_ID = 142436;
const TYPE_DEFAULT = 0;
const TYPE_ONLINE_ORDER = 1;
const TYPE_TRIPLE = 2;
const TYPE_ONLINE_ORDER_ONLY = 3;
const TYPE_TIRE = 4;
const TYPE_GIFT_CERTIFICATE = 5;
const TYPE_GIFT_CERTIFICATE_DISABLE_CODE = 6;
const TYPE_DOMINOS = 7;
const TYPE_FREE_PER_DAY = 8;
const BEAUTY_OFFERS = [self::OBLAKA_SALON_OFFER_ID, self::OBLAKA_ULTRASOUND_OFFER_ID, 132400, 239378, 245043, 138907, 132242, 138583, 142192,
243406, 135251, 132690, 139305, 141075, self::JASMIN_OFFER_ID]; // Марсель, Белый лотос.
const SOSEDI_OFFER_ID = 283793;
const MARSEL_OFFER_ID = 141075;
public const FREESTYLE_CERTIFICATE_OFFER_ID = 283213;
public const FREESTYLE_OFFER_IDS = [
self::FREESTYLE_CERTIFICATE_OFFER_ID,
137906,
138755,
136284,
];
public const MINSK_WORLD_CERTIFICATE_OFFER_ID = 288763;
public const FREESTYLE_CERTIFICATE_START_QR_CODES_DATE = '2021-03-25';
public const YANDEX_ALISA_OFFER_ID = 290406;
public const SMART_GOODS_OFFER_ID = 290491;
public const TL24_OFFER_ID = 291548;
public const ROYAL_PLAZA_EVENTS_OFFER_ID = 290238;
public const ROYAL_PLAZA_PSYCHOLOGIST_OFFER_ID = 291114;
public const IZUMI_OFFER_ID = 141144;
public const OUSHEN_OFFER_ID = 289105;
public const PLANETA_OFFER_ID = 135977;
public const IDEALMED_OFFER_ID = 141086;
public const PONPUSHKA_OFFER_ID = 292879;
public const MARSEL_MASSAGE_OFFER_ID = 140351;
protected $creator;
protected $title;
protected ?string $meOnMapName = null;
protected $explanationText;
protected $regularPrice;
protected $offerPrice;
protected $price;
protected $oldPrice;
protected $discount;
protected $activeSince;
protected $activeTill;
protected $codeActiveTill;
protected $active;
protected $hidden;
protected $paid;
protected $free;
// TODO: null is temporary while cache reloaded
protected ?bool $withoutCodes;
protected $showPriceInConditions;
protected $additionalPercents;
protected $showAltOffers;
protected $showCurrencies;
protected $address;
protected $searchPosition;
protected $activeSearchPosition;
protected $categories;
protected $medias;
protected $seo;
/**
* @var iterable<EntityDescription>|null
*/
protected ?iterable $descriptions;
protected $teaserMedias;
protected $mobileTeaserMedias;
protected $appTeaserMedias;
protected $topBlockMedias;
protected $topBlockMobileMedias;
protected $mailingTeaserMedias;
protected Collection $onlineOrderPopupLogoMedias;
protected $hotFeedIconMedia;
protected $detailMeidas;
protected $shopMedias;
protected $offerCodePools;
protected $offerOrders;
protected ?int $lastCodePoolStartPurchaseCount = null;
protected $usedCodesCount;
protected $geoLocations;
protected $phoneNumbers;
protected $directors;
protected $directorID;
protected $captionName;
protected $captionColor;
protected $activeCurrencyCalculator;
protected $bankCurrency;
protected $bankCurrencyID;
protected $luceneReindex;
protected $codeCost;
protected $codeCostByCount;
protected $rating;
protected $lastModified;
protected $manager;
protected $defaultCategoryID;
protected $companyName;
protected $giftCertificates;
protected $hint;
protected $review;
protected $onReview;
protected $renewedOn;
protected $defaultCity;
protected $teaserLogoWidth;
protected $teaserLogoHeight;
protected $hideNoveltyLabel;
protected $hideBannersInComments;
protected $extensions;
protected $sumForFreeDelivery;
protected $deliveryPrice;
protected $antitags;
protected $createdOn;
protected $allowedBuyOnlyCode;
protected $buyCodeButtonText;
protected $buyItemsButtonText;
protected $freeCodesCount;
protected $reservedCodesCount;
protected $shareClick;
protected $inFreeCategory;
protected $fakeFreeCodesCount;
protected $categoriIDs;
protected $purchaseKoeff;
protected $giftCertificateOffer;
protected $supplierPhotoMedias;
protected $version;
protected $supplierCategoryData;
protected $telegramBotShow;
protected $telegramBotPosition;
protected $onlineOrderAllowed;
protected $mobileAppOnlineOrderAllowed;
protected $buyCodeDisable;
private $phoneCoverClick;
private $productFastDelivery;
private $brandboxEnabled;
private $offerDeliveryZone;
private $offerFoodDeliveryZone;
protected $hideInApp;
protected ?Collection $onlineOrderSettings;
protected $giftCertificatePdfBgMedias;
protected Collection $mapLogoMedias;
protected Collection $deliveryZoneMedias;
private $discountDeliveryPopup;
private $discountPickupPopup;
private $externalOfferLink;
private $isShowExternalOfferLink;
protected $hideFeatures;
private $deliveryTimeTeaser = null;
private ?\DateTimeImmutable $onlineOrderAllowedRemovedAt = null;
private ?string $regionalCaptionName = null;
private ?string $regionalCaptionColor = null;
private ?string $foodcourtInfoTeaser = null;
private ?string $foodcourtInfoColorTeaser = null;
private bool $isIncludedInBeauty = false;
private bool $qrCodes = false;
private bool $recurrentDisabled = false;
private bool $availableOnFood = false;
private bool $onlineAutoOpened = false;
private bool $foodcourtLogoEnabled = false;
private bool $onlineOrderGiftEnabled = false;
private bool $buyCodeInAppOnly = false;
private bool $showProductsInOfferDescription = false;
private bool $checkAddressInOfferMenu = false;
private bool $showMapIconInApp = true;
private ?array $allowedOnlineOrderTypes = null;
private string $titleFontColor = '#000000';
private bool $separateTabForCertificatesInApp = true;
private ?float $mapPrice = null;
private ?int $mapRating = null;
private ?int $defaultCityId = null;
private ?string $directorName = null;
private ?string $telegram = null;
private ?string $viber = null;
private ?string $messengerCallBack = null;
public function __construct()
{
$this->productFastDelivery = new ArrayCollection();
$this->offerDeliveryZone = new ArrayCollection();
$this->offerFoodDeliveryZone = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->medias = new ArrayCollection();
$this->descriptions = new ArrayCollection();
$this->detailMeidas = [];
$this->shopMedias = [];
$this->supplierPhotoMedias = new ArrayCollection();
$this->offerCodePools = new ArrayCollection();
$this->geoLocations = new ArrayCollection();
$this->phoneNumbers = new ArrayCollection();
$this->directors = new ArrayCollection();
$this->giftCertificates = new ArrayCollection();
$this->extensions = new ArrayCollection();
$this->antitags = new ArrayCollection();
$this->createdOn = new DateTime();
$this->renewedOn = new DateTime();
$this->categoriIDs = [];
$this->version = 0;
$this->teaserMedias = new ArrayCollection();
$this->mobileTeaserMedias = new ArrayCollection();
$this->appTeaserMedias = new ArrayCollection();
$this->giftCertificatePdfBgMedias = new ArrayCollection();
$this->mapLogoMedias = new ArrayCollection();
$this->deliveryZoneMedias = new ArrayCollection();
$this->mailingTeaserMedias = new ArrayCollection();
$this->topBlockMedias = new ArrayCollection();
$this->topBlockMobileMedias = new ArrayCollection();
$this->onlineOrderPopupLogoMedias = new ArrayCollection();
$this->onlineOrderSettings = new ArrayCollection();
$this->rating = 0;
}
public function getPrice() {
return $this->price;
}
public function setPrice($price) {
$this->price = $price;
}
public function getOldPrice() {
return $this->oldPrice;
}
public function setOldPrice($oldPrice) {
$this->oldPrice = $oldPrice;
}
/**
* @return User
*/
public function getCreator() {
return $this->creator;
}
public function setCreator(User $creator) {
$this->creator = $creator;
}
public function getLastModified() {
return $this->lastModified;
}
public function setLastModified($lastModified) {
$this->lastModified = $lastModified;
}
public function addCategory(Category $category) {
if (!$this->categories->contains($category)) {
$this->categories->add($category);
if ($category->getID() == Category::NEW_OFFER_CATEGORY_ID) {
$this->renewedOn = new \DateTime();
}
return true;
}
return false;
}
public function removeCategory(Category $category) {
$this->categories->removeElement($category);
}
public function hasCategory($categoryID) {
if ($this->categoriIDs && count($this->categoriIDs) > 0) {
foreach ($this->categoriIDs as $id) {
if ($categoryID == $id) {
return true;
}
}
return false;
}
foreach ($this->categories as $categoryItem) {
if ($categoryID == $categoryItem->getID()) {
return true;
}
}
return false;
}
public function hasCategoryType($categoryTypeID) {
foreach ($this->categories as $categoryItem) {
if ($categoryTypeID == $categoryItem->getTypeID()) {
return true;
}
}
return false;
}
public function hasNotDefaultCityCategory() {
foreach ($this->categories as $category) {
if ($category->getCity() and $category->getCity()->getID() != City::DEFAULT_CITY_ID) {
return true;
}
}
return false;
}
public function addDescription(EntityDescription $description) {
if (!$this->descriptions->contains($description)) {
$this->descriptions->add($description);
}
}
public function getTitle() {
return $this->title;
}
public function setTitle($title) {
$this->title = $title;
}
public function getMeOnMapName(): ?string
{
return $this->meOnMapName;
}
public function setMeOnMapName(?string $meOnMapName): void
{
$this->meOnMapName = $meOnMapName;
}
public function getExplanationText() {
return $this->explanationText;
}
public function setExplanationText($explanationText) {
$this->explanationText = $explanationText;
}
public function getRegularPrice() {
$price = $this->regularPrice;
if ($this->isActiveCurrencyCalculator() && is_numeric($price)) {
$bankCurrency = $this->getBankCurrency();
$price *= $bankCurrency->getRate();
$price = number_format($price, 0, '.', ' ') . ' руб.';
}
return $price;
}
public function getRawRegularPrice() {
return $this->regularPrice;
}
public function setRegularPrice($regularPrice) {
$this->regularPrice = $regularPrice;
}
public function getOfferPrice() {
$price = $this->offerPrice;
if ($this->isActiveCurrencyCalculator() && is_numeric($price)) {
$bankCurrency = $this->getBankCurrency();
$price *= $bankCurrency->getRate();
$price = number_format($price, 0, '.', ' ') . ' руб.';
}
return $price;
}
public function getRawOfferPrice() {
return $this->offerPrice;
}
public function setOfferPrice($offerPrice) {
$this->offerPrice = $offerPrice;
}
public function getDiscount() {
return $this->discount;
}
public function setDiscount($discount) {
$this->discount = $discount;
}
public function getHint() {
return $this->hint;
}
public function setHint($hint) {
$this->hint = $hint;
}
public function getDiscountLabelText() {
if (mb_strlen($this->discount) > 0 && is_numeric(mb_substr($this->discount, 0, 1))) {
return '-' . $this->discount;
}
return $this->discount;
}
public function getActiveSince() {
return $this->activeSince;
}
public function setActiveSince($activeSince) {
$this->activeSince = $activeSince;
}
/**
* @return \DateTime
*/
public function getActiveTill()
{
return $this->activeTill;
}
public function setActiveTill($activeTill) {
$this->activeTill = $activeTill;
}
public function getCodeActiveTill() {
return $this->codeActiveTill;
}
public function setCodeActiveTill($codeActiveTill) {
$this->codeActiveTill = $codeActiveTill;
}
public function isActive() {
return $this->active;
}
public function setActive($active) {
$this->active = $active;
}
public function isHidden() {
return $this->hidden;
}
public function setHidden($hidden) {
$this->hidden = $hidden;
}
public function isPaid() {
return $this->paid;
}
public function setPaid($paid) {
$this->paid = $paid;
}
public function isFree() {
return $this->free;
}
public function setFree($free) {
$this->free = $free;
}
public function getCaptionName() {
return $this->captionName;
}
public function setCaptionName($captionName) {
$this->captionName = $captionName;
}
public function getCaptionColor() {
return $this->captionColor;
}
public function setCaptionColor($captionColor) {
$this->captionColor = $captionColor;
}
public function getRegionalCaptionName(): ?string
{
return $this->regionalCaptionName;
}
public function setRegionalCaptionName(?string $regionalCaptionName): void
{
$this->regionalCaptionName = $regionalCaptionName;
}
public function getRegionalCaptionColor(): ?string
{
return $this->regionalCaptionColor;
}
public function setRegionalCaptionColor(?string $regionalCaptionColor): void
{
$this->regionalCaptionColor = $regionalCaptionColor;
}
/**
* @deprecated
*/
public function isOnlineOrderAllowed() {
return $this->onlineOrderAllowed;
}
public function setOnlineOrderAllowed($onlineOrderAllowed) {
$this->onlineOrderAllowed = $onlineOrderAllowed;
}
public function isMobileAppOnlineOrderAllowed() {
return $this->mobileAppOnlineOrderAllowed;
}
public function setMobileAppOnlineOrderAllowed($mobileAppOnlineOrderAllowed) {
$this->mobileAppOnlineOrderAllowed = $mobileAppOnlineOrderAllowed;
}
public function getOnlineOrderAllowedRemovedAt(): ?\DateTimeImmutable
{
return $this->onlineOrderAllowedRemovedAt;
}
public function setOnlineOrderAllowedRemovedAt(?\DateTimeImmutable $onlineOrderAllowedRemovedAt): void
{
$this->onlineOrderAllowedRemovedAt = $onlineOrderAllowedRemovedAt;
}
// TODO: null is temporary while cache reloaded
public function isWithoutCodes(): ?bool
{
return $this->withoutCodes;
}
// TODO: null is temporary while cache reloaded
public function setWithoutCodes(?bool $withoutCodes): void
{
$this->withoutCodes = (bool) $withoutCodes;
}
public function isShowPriceInConditions() {
return $this->showPriceInConditions;
}
public function setShowPriceInConditions($showPriceInConditions) {
$this->showPriceInConditions = $showPriceInConditions;
}
public function isShowAltOffers() {
return $this->showAltOffers;
}
public function setShowAltOffers($showAltOffers) {
$this->showAltOffers = $showAltOffers;
}
public function isActiveCurrencyCalculator() {
return $this->activeCurrencyCalculator;
}
public function setActiveCurrencyCalculator($activeCurrencyCalculator) {
$this->activeCurrencyCalculator = $activeCurrencyCalculator;
}
public function getBankCurrencyID() {
return $this->bankCurrencyID;
}
public function setBankCurrencyID($bankCurrencyID) {
$this->bankCurrencyID = $bankCurrencyID;
}
/**
* @return BankCurrency
*/
public function getBankCurrency() {
return $this->bankCurrency;
}
public function setBankCurrency(BankCurrency $bankCurrency = null) {
$this->bankCurrency = $bankCurrency;
}
public function getAdditionalPercents() {
return $this->additionalPercents;
}
public function setAdditionalPercents($additionalPercents) {
$this->additionalPercents = $additionalPercents;
}
public function getShowCurrencies() {
return $this->showCurrencies;
}
public function setShowCurrencies($showCurrencies) {
$this->showCurrencies = $showCurrencies;
}
public function getAddress() {
return $this->address;
}
public function setAddress($address) {
$this->address = $address;
}
public function getSearchPosition() {
return $this->searchPosition;
}
public function setSearchPosition($searchPosition) {
$this->searchPosition = $searchPosition;
}
public function isActiveSearchPosition() {
return $this->activeSearchPosition;
}
public function setActiveSearchPosition($activeCearchPosition) {
$this->activeSearchPosition = $activeCearchPosition;
}
public function getGeoLocations() {
return $this->geoLocations;
}
public function setGeoLocation(ArrayCollection $geoLocations) {
$this->geoLocations = $geoLocations;
}
public function getGeoLocationById(int $id): ?GeoLocation
{
foreach ($this->geoLocations as $geoLocation) {
if ($id === $geoLocation->getID()) {
return $geoLocation;
}
}
return null;
}
public function getGeoLocationsSortedByDistanceToLocation($location) {
if (!is_array($location)) {
return $this->geoLocations;
}
$iterator = $this->getGeoLocations()->getIterator();
$iterator->uasort(function ($geoLocation1, $geoLocation2) use ($location) {
$distance1 = CommonUtil::getDistance($location[0], $location[1], $geoLocation1->getLatitude(), $geoLocation1->getLongitude(), 'K');
$distance2 = CommonUtil::getDistance($location[0], $location[1], $geoLocation2->getLatitude(), $geoLocation2->getLongitude(), 'K');
return $distance1 < $distance2 ? -1 : 1;
});
return new ArrayCollection(iterator_to_array($iterator));
}
public function addGeoLocation(GeoLocation $geoLocation) {
if (!$this->geoLocations->contains($geoLocation)) {
$this->geoLocations->add($geoLocation);
}
}
public function addProductFastDelivery(ProductFastDelivery $productFastDelivery)
{
if (!$this->productFastDelivery->contains($productFastDelivery)) {
$productFastDelivery->setOffer($this);
$this->productFastDelivery->add($productFastDelivery);
}
}
public function addOfferDeliveryZone(OfferDeliveryZone $offerDeliveryZone)
{
if (!$this->offerDeliveryZone->contains($offerDeliveryZone)) {
$offerDeliveryZone->setOffer($this);
$this->offerDeliveryZone->add($offerDeliveryZone);
}
}
public function getProductFastDelivery() {
return $this->productFastDelivery;
}
public function getPhoneNumbers() {
return $this->phoneNumbers;
}
public function setPhoneNumbers(ArrayCollection $phoneNumbers) {
$this->phoneNumbers = $phoneNumbers;
}
public function getPhoneNumbersWithoutGeoLocations() {
$phoneNumberWithLocationIDList = [];
foreach ($this->getGeoLocations() as $geoLocation) {
foreach ($geoLocation->getPhoneNumbers() as $phoneNumber) {
$phoneNumberWithLocationIDList[] = $phoneNumber->getID();
}
}
$phoneNumbersWithoutGeoLocations = [];
foreach ($this->phoneNumbers as $phoneNumber) {
if (!in_array($phoneNumber->getID(), $phoneNumberWithLocationIDList)) {
$phoneNumbersWithoutGeoLocations[] = $phoneNumber;
}
}
return $phoneNumbersWithoutGeoLocations;
}
public function addPhoneNumber(PhoneNumber $phoneNumber) {
if (!$this->phoneNumbers->contains($phoneNumber)) {
$phoneNumber->setOffer($this);
$this->phoneNumbers->add($phoneNumber);
return true;
}
return false;
}
public function removePhoneNumberByID($phoneNumberID) {
foreach ($this->phoneNumbers as $phoneNumber) {
if ($phoneNumber->getID() == $phoneNumberID) {
$this->phoneNumbers->removeElement($phoneNumber);
$phoneNumber->setOffer(null);
}
}
}
/**
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getCategories() {
return $this->categories;
}
public function getCategoriesByType($type) {
$result = new ArrayCollection();
foreach ($this->categories as $category) {
if ($category->getTypeID() == $type) {
$result->add($category);
}
}
return $result;
}
public function getCategoriesByCity($cityID) {
$categories = new ArrayCollection();
foreach ($this->categories as $category) {
if ($category->getCity()->getID() == $cityID) {
$categories->add($category);
}
}
return $categories;
}
/**
* @deprecated
*/
public function setCategories(ArrayCollection $categories) {
$this->categories = $categories;
}
/**
* @return \Doctrine\Common\Collections\ArrayCollection
*/
public function getMedias() {
return $this->medias;
}
public function setMedias($medias) {
$this->medias = $medias;
}
/**
* @return \Slivki\Entity\Seo
*/
public function getSeo() {
return $this->seo;
}
public function setSeo(Seo $seo) {
$seo->setResourceURL("Slivki:Default:details");
$this->seo = $seo;
}
public function setDescriptions($descriptions) {
$this->descriptions = $descriptions;
}
public function getDescriptions() {
return $this->descriptions;
}
public function getDescriptionByType($descriptionType) {
/** @var \Slivki\Entity\EntityDescription $description */
foreach ($this->descriptions as $description) {
if ($description->getTypeID() == $descriptionType) {
return $description->getDescription();
}
}
return "";
}
public function getConditions() {
return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_CONDITIONS_ID);
}
public function getFeatures() {
return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_FEATURES_ID);
}
public function getLocation() {
return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_LOCATION_ID);
}
public function getLogo() {
return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_LOGO_ID);
}
public function getLegal() {
return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_LEGAL_ID);
}
public function getDescriptionList(): array
{
return array_filter(
array(...$this->descriptions),
static fn (EntityDescription $description): bool => EntityDescription::TYPE_OFFER_DESCRIPTION_ID === $description->getTypeID(),
);
}
public function getCommonWorkingHours() {
return $this->getDescriptionByType(EntityDescription::TYPE_OFFER_WORKING_HOURS_ID);
}
public function addTeaserMedia(OfferTeaserMedia $teaserMedia) {
if (!$this->teaserMedias->contains($teaserMedia)) {
$this->teaserMedias->add($teaserMedia);
$teaserMedia->setOffer($this);
}
}
public function getTeaserMedia(): ?OfferTeaserMedia
{
return $this->teaserMedias->count() > 0 ? $this->teaserMedias->first() : null;
}
public function getTeaserMedias() {
return $this->teaserMedias;
}
public function setTeaserMedias(ArrayCollection $medias) {
$this->teaserMedias = $medias;
}
public function removeTeaserMedia(OfferTeaserMedia $teaserMedia) {
$this->teaserMedias->removeElement($teaserMedia);
}
public function addMobileTeaserMedia(OfferMobileTeaserMedia $mobileTeaserMedia) {
if (!$this->mobileTeaserMedias->contains($mobileTeaserMedia)) {
$this->mobileTeaserMedias->add($mobileTeaserMedia);
$mobileTeaserMedia->setOffer($this);
}
}
/** @return null|OfferMobileTeaserMedia */
public function getMobileTeaserMedia() {
return $this->mobileTeaserMedias->first();
}
public function getMobileTeaserMedias() {
return $this->mobileTeaserMedias;
}
public function setMobileTeaserMedias(ArrayCollection $medias) {
$this->mobileTeaserMedias = $medias;
}
public function removeMobileTeaserMedia(OfferMobileTeaserMedia $mobileTeaserMedia) {
$this->mobileTeaserMedias->removeElement($mobileTeaserMedia);
}
public function addAppTeaserMedia(OfferAppTeaserMedia $appTeaserMedia) {
if (!$this->appTeaserMedias->contains($appTeaserMedia)) {
$this->appTeaserMedias->add($appTeaserMedia);
$appTeaserMedia->setOffer($this);
}
}
public function getAppTeaserMedia(): ?OfferAppTeaserMedia
{
return $this->appTeaserMedias->count() > 0 ? $this->appTeaserMedias->first() : null;
}
public function getAppTeaserMedias() {
return $this->appTeaserMedias;
}
public function setAppTeaserMedias(ArrayCollection $medias) {
$this->appTeaserMedias = $medias;
}
public function removeAppTeaserMedia(OfferAppTeaserMedia $appTeaserMedia) {
$this->appTeaserMedias->removeElement($appTeaserMedia);
}
public function addGiftCertificatePdfBgMedia(GiftCertificatePdfBgMedia $giftCertificatePdfBgMedia) {
if (!$this->giftCertificatePdfBgMedias->contains($giftCertificatePdfBgMedia)) {
$this->giftCertificatePdfBgMedias->add($giftCertificatePdfBgMedia);
$giftCertificatePdfBgMedia->setOffer($this);
}
}
/** @return null|GiftCertificatePdfBgMedia */
public function getGiftCertificatePdfBgMedia() {
return $this->giftCertificatePdfBgMedias->first();
}
public function getGiftCertificatePdfBgMedias() {
return $this->giftCertificatePdfBgMedias;
}
public function setGiftCertificatePdfBgMedias(ArrayCollection $medias) {
$this->giftCertificatePdfBgMedias = $medias;
}
public function removeGiftCertificatePdfBgMedia(GiftCertificatePdfBgMedia $giftCertificatePdfBgMedia) {
$this->giftCertificatePdfBgMedias->removeElement($giftCertificatePdfBgMedia);
}
public function getOnlineOrderSettings(): ?OnlineOrderSettings
{
return $this->onlineOrderSettings->count() > 0 ? $this->onlineOrderSettings->first() : null;
}
public function setOnlineOrderSettings(OnlineOrderSettings $onlineOrderSettings): void
{
$onlineOrderSettings->setOffer($this);
$this->onlineOrderSettings = new ArrayCollection([$onlineOrderSettings]);
}
public function getOnlineOrderSettingsJSON(): ?array
{
$onlineOrderSettings = $this->getOnlineOrderSettings();
if (null === $onlineOrderSettings) {
return null;
}
return $onlineOrderSettings->jsonSerialize();
}
public function addMapLogoMedia(OfferMapLogoMedia $media): void
{
if (!$this->mapLogoMedias->contains($media)) {
$this->mapLogoMedias->add($media);
$media->setOffer($this);
}
}
public function getMapLogoMedia(): ?OfferMapLogoMedia
{
return $this->mapLogoMedias->count() > 0 ? $this->mapLogoMedias->first() : null;
}
public function getMapLogoMedias(): Collection
{
return $this->mapLogoMedias;
}
public function setMapLogoMedias(ArrayCollection $mapLogoMedias): void
{
$this->mapLogoMedias = $mapLogoMedias;
}
public function removeMapLogoMedia(OfferMapLogoMedia $media): void
{
$this->mapLogoMedias->removeElement($media);
}
public function addDeliveryZoneMedia(OfferDeliveryZoneMedia $media): void
{
if (!$this->deliveryZoneMedias->contains($media)) {
$this->deliveryZoneMedias->add($media);
$media->setOffer($this);
}
}
public function getDeliveryZoneMedia(): ?OfferDeliveryZoneMedia
{
return $this->deliveryZoneMedias->count() > 0 ? $this->deliveryZoneMedias->first() : null;
}
public function getDeliveryZoneMedias(): Collection
{
return $this->deliveryZoneMedias;
}
public function setDeliveryZoneMedias(ArrayCollection $deliveryZoneMedias): void
{
$this->deliveryZoneMedias = $deliveryZoneMedias;
}
public function removeDeliveryZoneMedia(OfferDeliveryZoneMedia $media): void
{
$this->deliveryZoneMedias->removeElement($media);
}
public function addTopBlockMedia(OfferTopBlockMedia $topBlockMedia) {
if (!$this->topBlockMedias->contains($topBlockMedia)) {
$this->topBlockMedias->add($topBlockMedia);
$topBlockMedia->setOffer($this);
}
}
public function getTopBlockMedia(): ?OfferTopBlockMedia
{
return $this->topBlockMedias->count() > 0 ? $this->topBlockMedias->first() : null;
}
public function getTopBlockMedias() {
return $this->topBlockMedias;
}
public function setTopBlockMedias(ArrayCollection $medias) {
$this->topBlockMedias = $medias;
}
public function removeTopBlockMedia(OfferTopBlockMedia $topBlockMedia) {
$this->topBlockMedias->removeElement($topBlockMedia);
}
public function addTopBlockMobileMedia(OfferTopBlockMobileMedia $topBlockMobileMedia) {
if (!$this->topBlockMobileMedias->contains($topBlockMobileMedia)) {
$this->topBlockMobileMedias->add($topBlockMobileMedia);
$topBlockMobileMedia->setOffer($this);
}
}
public function getTopBlockMobileMedia(): ?OfferTopBlockMobileMedia
{
return $this->topBlockMobileMedias->count() > 0 ? $this->topBlockMobileMedias->first() : null;
}
public function getTopBlockMobileMedias() {
return $this->topBlockMobileMedias;
}
public function setTopBlockMobileMedias(ArrayCollection $medias) {
$this->topBlockMobileMedias = $medias;
}
public function removeTopBlockMobileMedia(OfferTopBlockMobileMedia $topBlockMobileMedia) {
$this->topBlockMobileMedias->removeElement($topBlockMobileMedia);
}
public function addOnlineOrderPopupLogoMedia(OnlineOrderPopupLogoMedia $onlineOrderPopupLogoMedia): void
{
if (!$this->onlineOrderPopupLogoMedias->contains($onlineOrderPopupLogoMedia)) {
$this->onlineOrderPopupLogoMedias = new ArrayCollection();
$this->onlineOrderPopupLogoMedias->add($onlineOrderPopupLogoMedia);
$onlineOrderPopupLogoMedia->setOffer($this);
}
}
public function getOnlineOrderPopupLogoMedia(): ?OnlineOrderPopupLogoMedia
{
return false === $this->onlineOrderPopupLogoMedias->first() ? null : $this->onlineOrderPopupLogoMedias->first();
}
/**
* @return Collection<OnlineOrderPopupLogoMedia>
*/
public function getOnlineOrderPopupLogoMedias(): Collection
{
return $this->onlineOrderPopupLogoMedias;
}
public function setOnlineOrderPopupLogoMedias(ArrayCollection $medias): void
{
$this->onlineOrderPopupLogoMedias = $medias;
}
public function removeOnlineOrderPopupLogoMedia(OnlineOrderPopupLogoMedia $onlineOrderPopupLogoMedia): void
{
$this->topBlockMedias->removeElement($onlineOrderPopupLogoMedia);
}
public function addMailingTeaserMedia(OfferMailingTeaserMedia $mailingTeaserMedia = null) {
if (!$this->mailingTeaserMedias->contains($mailingTeaserMedia)) {
$this->mailingTeaserMedias->add($mailingTeaserMedia);
$mailingTeaserMedia->setOffer($this);
}
}
/** @return null|OfferMailingTeaserMedia */
public function getMailingTeaserMedia() {
return $this->mailingTeaserMedias->first();
}
public function getMailingTeaserMedias() {
return $this->mailingTeaserMedias;
}
public function setMailingTeaserMedias(ArrayCollection $medias) {
$this->mailingTeaserMedias = $medias;
}
public function removeMailingTeaserMedia(OfferMailingTeaserMedia $mailingTeaserMedia) {
$this->mailingTeaserMedias->removeElement($mailingTeaserMedia);
}
public function setHotFeedIconMedia(Media $hotFeedIconMedia = null) {
$this->hotFeedIconMedia = $hotFeedIconMedia;
}
/**
* @return null|Media
*/
public function getHotFeedIconMedia() {
return $this->hotFeedIconMedia;
}
public function setDetailMeidas(array $mediaList) {
$this->detailMeidas = $mediaList;
}
public function getDetailMedias() {
return $this->detailMeidas;
}
public function setShopMedias(array $mediaList) {
$this->shopMedias = $mediaList;
}
public function getShopMedias(): array
{
return $this->shopMedias ?? [];
}
public function addShopMedias(Media $media) {
if (!$this->shopMedias->contains($media)) {
$this->shopMedias->add($media);
}
}
public function setSupplierPhotoMedias(array $mediaList) {
$this->supplierPhotoMedias = $mediaList;
}
public function getSupplierPhotoMedias() {
return $this->supplierPhotoMedias;
}
public function getOfferCodePools() {
return $this->offerCodePools;
}
public function setOfferCodePools(ArrayCollection $offerCodePools) {
$this->offerCodePools = $offerCodePools;
}
/**
* @return bool|OfferCodePool
*/
public function getLastActiveCodePool() {
/** @var \Slivki\Entity\OfferCodePool $offerCodePool */
foreach ($this->offerCodePools->toArray() as $offerCodePool) {
if ($offerCodePool->isActive()) {
return $offerCodePool;
}
}
return false;
}
public function setCodePool(OfferCodePool $codePool) {
if ($this->offerCodePools->count() == 0) {
$this->offerCodePools->add($codePool);
}
foreach ($this->offerCodePools as $key => $pool) {
if ($pool->getID() == $codePool->getID()) {
$this->offerCodePools->set($key, $codePool);
}
}
$this->usedCodesCount = $this->getUsedCodesCount(true);
$this->fakeFreeCodesCount = $this->getFakeFreeCodesCount(true);
$this->freeCodesCount = $this->getFreeCodesCount(true);
$this->reservedCodesCount = $this->getReservedCodesCount(true);
$this->setLastCodePoolStartPurchaseCount();
$this->lastCodePoolStartPurchaseCount = $this->getLastCodePoolStartPurchaseCount();
}
public function getOfferOrders() {
return $this->offerOrders;
}
public function setOfferOrders(ArrayCollection $offerOrders) {
$this->offerOrders = $offerOrders;
}
public function getUsedCodesCount($reload = false) {
if ($this->usedCodesCount != null && !$reload) {
return $this->usedCodesCount;
}
$lastActiveCodePool = $this->getLastActiveCodePool();
if (!$lastActiveCodePool) {
$this->usedCodesCount = 0;
return 0;
}
$usedCodes = trim($lastActiveCodePool->getCodesUsed(), "\n");
if ($usedCodes == '') {
$this->usedCodesCount = 0 + $lastActiveCodePool->getUsedCodesCountFake();
return $this->usedCodesCount;
}
$this->usedCodesCount = count(explode("\n", $usedCodes)) + $lastActiveCodePool->getUsedCodesCountFake();
return $this->usedCodesCount;
}
public function getLastCodePoolStartPurchaseCount(): int
{
if (null === $this->lastCodePoolStartPurchaseCount) {
$this->setLastCodePoolStartPurchaseCount();
}
return $this->lastCodePoolStartPurchaseCount;
}
public function setLastCodePoolStartPurchaseCount(): void
{
$lastActiveCodePool = $this->getLastActiveCodePool();
if (!$lastActiveCodePool) {
$this->lastCodePoolStartPurchaseCount = 0;
return;
}
$this->lastCodePoolStartPurchaseCount = $lastActiveCodePool->getUsedCodesCountFake();
}
public function getUsedCodesCountForPastOffer() {
$this->usedCodesCount = 0;
if ($this->offerCodePools->count() > 0) {
$codePool = $this->offerCodePools->last();
if ($codePool) {
$usedCodes = trim($codePool->getCodesUsed(), "\n");
if ($usedCodes == '') {
return 0;
}
return count(explode("\n", $usedCodes)) + $codePool->getUsedCodesCountFake();
}
}
return 0;
}
public function setUsedCodesCount($usedCodesCount) {
$this->usedCodesCount = $usedCodesCount;
}
public function getFreeCodesCount($reload = false) {
if ($this->freeCodesCount != null && !$reload) {
return $this->freeCodesCount;
}
$lastActiveCodePool = $this->getLastActiveCodePool();
if (!$lastActiveCodePool) {
$this->freeCodesCount = 0;
return 0;
}
$this->freeCodesCount = $lastActiveCodePool->getFreeCodesCount();
return $this->freeCodesCount;
}
public function hasFreeCodes(): bool
{
return $this->getFreeCodesCount() > 0;
}
public function getReservedCodesCount($reload = false) {
if ($this->reservedCodesCount != null && !$reload) {
return $this->reservedCodesCount;
}
$lastActiveCodePool = $this->getLastActiveCodePool();
if (!$lastActiveCodePool) {
$this->reservedCodesCount = 0;
return 0;
}
$this->reservedCodesCount = $lastActiveCodePool->getReservedCodesCount();
return $this->reservedCodesCount;
}
public function getFakeFreeCodesCount($reload = false) {
if ($this->fakeFreeCodesCount != null && !$reload) {
return $this->fakeFreeCodesCount;
}
$codePool = $this->getLastActiveCodePool();
if (!$codePool) {
$this->fakeFreeCodesCount = 0;
return 0;
}
$this->fakeFreeCodesCount = $this->getUsedCodesCount() + $codePool->getFreeCodesCount();
return $this->fakeFreeCodesCount;
}
public function getDirectors() {
return $this->directors;
}
public function findFirstDirector(): ?Director
{
return false === $this->directors->first() ? null : $this->directors->first();
}
public function getDirectorID() {
if ($this->directorID !== null) {
return $this->directorID;
}
if ($this->directors->count()) {
$directorID = $this->directors->first()->getID();
$this->directorID = $directorID;
return $directorID;
}
return null;
}
public function getCodesCountByUser(User $user) {
$criteria = Criteria::create()->where(Criteria::expr()->eq("user", $user));
$offerOrders = $this->offerOrders->matching($criteria);
$codesCount = 0;
/** @var OfferOrder $offerOrder */
foreach($offerOrders as $offerOrder) {
$offerOrderStatus = $offerOrder->getStatus();
if ($offerOrderStatus == OfferOrder::STATUS_CONFIRM) {
$codesCount += $offerOrder->getCodesCount();
}
}
return $codesCount;
}
public function isLuceneReindex() {
return $this->luceneReindex;
}
public function setLuceneReindex($luceneReindex) {
$this->luceneReindex = $luceneReindex;
}
public function getCodeCost() {
return $this->codeCost;
}
public function setCodeCost($codeCost) {
$this->codeCost = $codeCost;
}
public function getCodeCostByCount() {
return $this->codeCostByCount;
}
public function setCodeCostByCount($codeCostByCount) {
$this->codeCostByCount = $codeCostByCount;
}
public function isInFreeCodesCategory() {
if ($this->inFreeCategory != null) {
return $this->inFreeCategory;
}
foreach ($this->categories as $category) {
if ($category->getID() == Category::FREE_CODES_CATEGORY_ID || $category->getTypeID() == Category::FREE_CATEGORY_TYPE) {
$this->inFreeCategory = true;
return true;
}
}
$this->inFreeCategory = false;
return false;
}
/**
* @return boolean
*/
public function isInActivePeriod() {
$activeSince = $this->getActiveSince();
$activeTill = $this->getActiveTill();
$timeNow = new \DateTime();
if(!$activeSince instanceof \DateTime || !$activeTill instanceof \DateTime) {
return false;
}
return $activeSince <= $timeNow && $activeTill > $timeNow;
}
public function isVisible(): bool
{
return $this->isActive() && $this->isInActivePeriod() && !$this->isHidden();
}
/**
* @return boolean
* @deprecated
*/
public function isInVisiblePeriod() {
return !$this->hidden;
}
public function getRating() {
return $this->rating;
}
public function setRating($rating) {
$this->rating = $rating;
}
/**
* @return User
*/
public function getManager() {
return $this->manager;
}
public function setManager(User $manager) {
$this->manager = $manager;
}
public function getDefaultCategoryID() {
return $this->defaultCategoryID;
}
public function setDefaultCategoryID($categoryID) {
$this->defaultCategoryID = $categoryID;
}
public function getCompanyName() {
return $this->companyName;
}
public function setCompanyName($companyName) {
$this->companyName = $companyName;
}
public function isTelegramBotShow() {
return $this->telegramBotShow;
}
public function setTelegramBotShow($telegramBotShow) {
$this->telegramBotShow = $telegramBotShow;
}
public function getTelegramBotPosition() {
return $this->telegramBotPosition;
}
public function setTelegramBotPosition($telegramBotPosition) {
$this->telegramBotPosition = $telegramBotPosition;
}
public function getGiftCertificates() {
return $this->giftCertificates;
}
public function getActiveGiftCertificates() {
$criteria = Criteria::create()->where(Criteria::expr()->eq('active', true))->andWhere(Criteria::expr()->eq('hidden', false));
return $this->giftCertificates->matching($criteria);
}
public function isGiftCertificateOffer() {
if ($this->giftCertificateOffer != null) {
return $this->giftCertificateOffer;
}
$this->giftCertificateOffer = $this->getActiveGiftCertificates()->count() > 0;
return $this->giftCertificateOffer;
}
public function setGiftCertificates(Collection $giftCertificates) {
$this->giftCertificates = $giftCertificates;
}
public function addGiftCertificate(GiftCertificate $giftCertificate) {
if (!$this->giftCertificates->contains($giftCertificate)) {
$this->giftCertificates->add($giftCertificate);
$giftCertificate->setOffer($this);
}
}
public function isNeedReview() {
return $this->review;
}
public function setNeedReview($review) {
$this->review = $review;
}
public function isOnReview() {
return $this->onReview;
}
public function setOnReview($onReview) {
$this->onReview = $onReview;
}
public function getRenewedOn() {
return $this->renewedOn;
}
public function setRenewedOn(\DateTime $renewedOn) {
$this->renewedOn = $renewedOn;
}
/** @return City */
public function getDefaultCity() {
return $this->defaultCity;
}
public function setDefaultCity(City $defaultCity) {
$this->defaultCity = $defaultCity;
}
public function getDefaultCityId(): ?int
{
return $this->defaultCityId;
}
public function setDefaultCityId(?int $defaultCityId): void
{
$this->defaultCityId = $defaultCityId;
}
public function getTeaserLogoWidth() {
return $this->teaserLogoWidth;
}
public function setTeaserLogoWidth($teaserLogoWidth) {
$this->teaserLogoWidth = $teaserLogoWidth;
}
public function getTeaserLogoHeight() {
return $this->teaserLogoHeight;
}
public function setTeaserLogoHeight($teaserLogoHeight) {
$this->teaserLogoHeight = $teaserLogoHeight;
}
public function isHideNoveltyLabel() {
return $this->hideNoveltyLabel;
}
public function setHideNoveltyLabel($hideNoveltyLabel) {
$this->hideNoveltyLabel = $hideNoveltyLabel;
}
public function isHideBannersInComments() {
return $this->hideBannersInComments;
}
public function setHideBannersInComments($hideBannersInComments) {
$this->hideBannersInComments = $hideBannersInComments;
}
public function getExtensions() {
return $this->extensions;
}
public function setExtensions(ArrayCollection $extensions) {
$this->extensions = $extensions;
}
/**
* @return FoodOfferExtension[]|ArrayCollection
*/
public function getFoodExtensions() {
$foodExtensions = new ArrayCollection();
if (!$this->extensions) {
return $foodExtensions;
}
foreach ($this->extensions as $extension) {
if ($extension instanceof FoodOfferExtension && !$extension instanceof FoodOfferOptionExtension) {
$foodExtensions->add($extension);
}
}
return $foodExtensions;
}
public function getTireExtensions() {
$tireExtensions = new ArrayCollection();
foreach ($this->extensions as $extension) {
if ($extension instanceof TireOfferExtension) {
$tireExtensions->add($extension);
}
}
return $tireExtensions;
}
public function getFoodOptionExtensions() {
$foodOptionExtensions = new ArrayCollection();
foreach ($this->extensions as $extension) {
if ($extension instanceof FoodOfferOptionExtension) {
$foodOptionExtensions->add($extension);
}
}
return $foodOptionExtensions;
}
public function getItems() {
$items = new ArrayCollection();
if (!$this->extensions) {
return $items;
}
foreach ($this->extensions as $extension) {
if ($extension instanceof ItemOfferExtension) {
$items->add($extension);
}
}
return $items;
}
public function addExtension(OfferExtension $extension) {
if (!$this->extensions->contains($extension)) {
$this->extensions->add($extension);
$extension->setOffer($this);
}
}
public function getSumForFreeDelivery() {
return $this->sumForFreeDelivery;
}
public function setSumForFreeDelivery($sumForFreeDelivery) {
$this->sumForFreeDelivery = $sumForFreeDelivery;
}
public function getDeliveryPrice() {
return $this->deliveryPrice;
}
public function setDeliveryPrice($deliveryPrice) {
$this->deliveryPrice = $deliveryPrice;
}
/**
* @return ArrayCollection
*/
public function getAntiTags() {
return $this->antitags;
}
public function addAntiTag(AntiTag $antitag) {
if (!$this->antitags->contains($antitag)) {
$antitag->addOffer($this);
$this->antitags->add($antitag);
}
}
public function deleteAntiTag(AntiTag $antitag) {
$this->antitags->removeElement($antitag);
}
public function hasAntiTag(AntiTag $antitag) {
return $this->antitags->contains($antitag);
}
public function getCreatedOn() {
return $this->createdOn;
}
public function setCreatedOn($createdOn) {
$this->createdOn = $createdOn;
}
public function isAllowedBuyOnlyCode() {
return $this->allowedBuyOnlyCode;
}
public function setAllowedBuyOnlyCode($allowedBuyOnlyCode) {
$this->allowedBuyOnlyCode = $allowedBuyOnlyCode;
}
public function getBuyCodeButtonText() {
return $this->buyCodeButtonText;
}
public function setBuyCodeButtonText($buyCodeButtonText) {
$this->buyCodeButtonText = $buyCodeButtonText;
}
public function getBuyItemsButtonText() {
return $this->buyItemsButtonText;
}
public function setBuyItemsButtonText($buyItemsButtonText) {
$this->buyItemsButtonText = $buyItemsButtonText;
}
public function setShareClick($shareClick) {
$this->shareClick = $shareClick;
}
public function getShareClick() {
return $this->shareClick;
}
public function getOfferDeliveryZone(): ?Collection
{
return $this->offerDeliveryZone;
}
public function getPurchaseKoeff() {
return $this->purchaseKoeff;
}
public function setPurchaseKoeff($purchaseKoeff) {
$this->purchaseKoeff = $purchaseKoeff;
}
public function getVersion() {
return $this->version;
}
public function setVersion($version) {
$this->version = $version;
}
public function getSupplierCategoryData() {
return $this->supplierCategoryData;
}
public function setSupplierCategoryData($supplierCategoryData) {
$this->supplierCategoryData = $supplierCategoryData;
}
public function isQrCodes(): bool
{
return $this->qrCodes;
}
public function setQrCodes(bool $qrCodes): void
{
$this->qrCodes = $qrCodes;
}
public function isRecurrentDisabled(): bool
{
return $this->recurrentDisabled;
}
public function setRecurrentDisabled(bool $recurrentDisabled): void
{
$this->recurrentDisabled = $recurrentDisabled;
}
public function isAvailableOnFood(): bool
{
return $this->availableOnFood;
}
public function setAvailableOnFood(bool $availableOnFood): void
{
$this->availableOnFood = $availableOnFood;
}
public function getAllowedOnlineOrderTypes(): ?array
{
return $this->allowedOnlineOrderTypes;
}
public function setAllowedOnlineOrderTypes(?array $allowedOnlineOrderTypes): void
{
$this->allowedOnlineOrderTypes = $allowedOnlineOrderTypes;
}
public function getTitleFontColor(): string
{
return $this->titleFontColor;
}
public function setTitleFontColor(string $titleFontColor): void
{
$this->titleFontColor = $titleFontColor;
}
public function getCategoriesIds(): array
{
$categoryIds = [];
foreach ($this->categories as $category) {
$categoryIds[] = $category->getID();
}
return $categoryIds;
}
public function jsonSerialize(): array
{
$categoryIDs = [];
foreach ($this->categories as $category) {
$categoryIDs[] = $category->getID();
}
return [
'ID' => $this->ID,
'title' => $this->title,
'defaultCityId' => $this->getDefaultCity() !== null ? $this->getDefaultCity()->getID(): $this->defaultCityId,
'meOnMapName' => $this->meOnMapName,
'explanationText' => $this->explanationText,
'active' => $this->active,
'hidden' => $this->hidden,
'discount' => $this->discount,
'regularPrice' => $this->regularPrice,
'offerPrice' => $this->offerPrice,
'address' => $this->address,
'codeCost' => $this->codeCost,
'codeCostByCount' => $this->codeCostByCount,
'additionalPercents' => $this->additionalPercents,
'showPriceInConditions' => $this->showPriceInConditions,
'showAltOffers' => $this->showAltOffers,
'free' => $this->free,
'captionName' => $this->captionName,
'captionColor' => $this->captionColor,
'titleFontColor' => $this->titleFontColor,
'regionalCaptionName' => $this->regionalCaptionName,
'regionalCaptionColor' => $this->regionalCaptionColor,
'withoutCodes' => $this->withoutCodes,
'activeCurrencyCalculator' => $this->activeCurrencyCalculator,
'bankCurrencyID' => $this->bankCurrencyID,
'rawRegularPrice' => $this->getRawRegularPrice(),
'rawOfferPrice' => $this->getRawOfferPrice(),
'activeSearchPosition' => $this->activeSearchPosition,
'searchPosition' => $this->searchPosition,
'defaultCategoryID' => $this->defaultCategoryID,
'companyName' => $this->companyName,
'hint' => $this->hint ?: '',
'price' => $this->price,
'oldPrice' => $this->oldPrice,
'teaserLogoWidth' => $this->teaserLogoWidth,
'teaserLogoHeight' => $this->teaserLogoHeight,
'hideNoveltyLabel' => $this->hideNoveltyLabel,
'hideBannersInComments' => $this->hideBannersInComments,
'onlineOrderAllowed' => $this->onlineOrderAllowed,
'mobileAppOnlineOrderAllowed' => $this->mobileAppOnlineOrderAllowed,
'buyCodeDisable' => $this->buyCodeDisable,
'hideInApp' => $this->hideInApp,
'brandboxEnabled' => $this->brandboxEnabled,
'allowedBuyOnlyCode' => $this->allowedBuyOnlyCode,
'buyCodeButtonText' => $this->buyCodeButtonText,
'buyItemsButtonText' => $this->buyItemsButtonText,
'activeSince' => $this->activeSince,
'activeTill' => $this->activeTill,
'freeCodesCount' => $this->getFreeCodesCount(),
'reservedCodesCount' => $this->getReservedCodesCount(),
'inFreeCategory' => $this->isInFreeCodesCategory(),
'bankCurrency' => $this->bankCurrency,
'codeActiveTill' => $this->codeActiveTill,
'usedCodesCount' => $this->getUsedCodesCount(),
'fakeFreeCodesCount' => $this->getFakeFreeCodesCount(),
'lastCodePoolStartPurchaseCount' => $this->getLastCodePoolStartPurchaseCount(),
'categoryIDs' => $categoryIDs,
'purchaseKoeff' => $this->purchaseKoeff,
'giftCertificateOffer' => $this->isGiftCertificateOffer(),
'supplierCategoryData' => $this->supplierCategoryData,
'telegramBotShow' => $this->telegramBotShow,
'discountDeliveryPopup' => $this->getDiscountDeliveryPopup(),
'discountPickupPopup' => $this->getDiscountPickupPopup(),
'deliveryTimeTeaser' => $this->getDeliveryTimeTeaser(),
'foodcourtInfoTeaser' => $this->getFoodcourtInfoTeaser(),
'foodcourtInfoColorTeaser' => $this->getFoodcourtInfoColorTeaser(),
'externalOfferLink' => $this->getExternalOfferLink(),
'isShowExternalOfferLink' => $this->getIsShowExternalOfferLink(),
'hideFeatures' => $this->hideFeatures,
'isIncludedInBeauty' => $this->isIncludedInBeauty,
'qrCodes' => $this->qrCodes,
'recurrentDisabled' => $this->recurrentDisabled,
'availableOnFood' => $this->availableOnFood,
'onlineAutoOpened' => $this->onlineAutoOpened,
'foodcourtLogoEnabled' => $this->foodcourtLogoEnabled,
'onlineOrderGiftEnabled' => $this->onlineOrderGiftEnabled,
'onlineOrderSettings' => $this->getOnlineOrderSettingsJSON(),
'directorID' => $this->getDirectorID(),
'rating' => $this->rating,
'buyCodeInAppOnly' => $this->buyCodeInAppOnly,
'allowedOnlineOrderTypes' => $this->allowedOnlineOrderTypes,
'showProductsInOfferDescription' => $this->showProductsInOfferDescription,
'separateTabForCertificatesInApp' => $this->separateTabForCertificatesInApp,
'checkAddressInOfferMenu' => $this->checkAddressInOfferMenu,
'showMapIconInApp' => $this->showMapIconInApp,
'telegram' => $this->telegram,
'viber' => $this->viber,
'messengerCallBack' => $this->messengerCallBack,
];
}
public function fromJSON($data)
{
$this->freeCodesCount = $data->freeCodesCount;
$this->reservedCodesCount = $data->reservedCodesCount;
$this->lastCodePoolStartPurchaseCount = $data->lastCodePoolStartPurchaseCount ?? 0;
$this->usedCodesCount = $data->usedCodesCount;
$this->fakeFreeCodesCount = $data->fakeFreeCodesCount;
$this->inFreeCategory = $data->inFreeCategory;
$this->activeSince = new \DateTime($data->activeSince->date);
$this->activeTill = new \DateTime($data->activeTill->date);
$this->codeActiveTill = new \DateTime($data->codeActiveTill->date);
if (isset($data->categoryIDs)) {
$this->categoriIDs = $data->categoryIDs;
}
if (isset($data->giftCertificateOffer)) {
$this->giftCertificateOffer = $data->giftCertificateOffer;
}
if (isset($data->bankCurrency) && isset($data->bankCurrency->ID)) {
$bankCurrency = new BankCurrency();
$bankCurrency->setID($data->bankCurrency->ID);
$bankCurrency->setRate($data->bankCurrency->rate);
$bankCurrency->setCurrency($data->bankCurrency->currency);
$bankCurrency->setSign($data->bankCurrency->sign);
$this->bankCurrency = $bankCurrency;
}
if (isset($data->onlineOrderSettings) && isset($data->onlineOrderSettings->ID)) {
$onlineOrderSettings = new OnlineOrderSettings();
$onlineOrderSettings->setID($data->onlineOrderSettings->ID);
$onlineOrderSettings->setMinDeliverySum($data->onlineOrderSettings->minDeliverySum);
$onlineOrderSettings->setMinSumForFreeDelivery($data->onlineOrderSettings->minSumForFreeDelivery);
$onlineOrderSettings->setDeliveryPrice($data->onlineOrderSettings->deliveryPrice);
$onlineOrderSettings->setPickupEnabled($data->onlineOrderSettings->pickupEnabled);
$onlineOrderSettings->setDeliveryEnabled($data->onlineOrderSettings->deliveryEnabled);
$onlineOrderSettings->setAllowedPaymentMethods($data->onlineOrderSettings->allowedPaymentMethods);
$onlineOrderSettings->setOrderPeriodInDays($data->onlineOrderSettings->orderPeriodInDays);
$onlineOrderSettings->setPickupDiscountPercent($data->onlineOrderSettings->pickupDiscountPercent);
$onlineOrderSettings->setEmail($data->onlineOrderSettings->email);
$onlineOrderSettings->setSplitPayment($data->onlineOrderSettings->splitPayment);
$onlineOrderSettings->setDomain($data->onlineOrderSettings->domain);
$onlineOrderSettings->setSchedule($data->onlineOrderSettings->schedule);
$onlineOrderSettings->setDeliveryTimeFrom($data->onlineOrderSettings->deliveryTimeFrom);
$onlineOrderSettings->setDeliveryTimeTill($data->onlineOrderSettings->deliveryTimeTill);
$onlineOrderSettings->setDeliverySchedule($data->onlineOrderSettings->deliverySchedule);
$onlineOrderSettings->setDeliveryLeadType($data->onlineOrderSettings->deliveryLeadType);
$onlineOrderSettings->setDeliveryLeadTime($data->onlineOrderSettings->deliveryLeadTime);
$onlineOrderSettings->setDeliveryIntervalBetweenOrdersType($data->onlineOrderSettings->deliveryIntervalBetweenOrdersType);
$onlineOrderSettings->setDeliveryIntervalBetweenOrdersTime($data->onlineOrderSettings->deliveryIntervalBetweenOrdersTime);
$onlineOrderSettings->setDeliveryDisableType($data->onlineOrderSettings->deliveryDisableType);
$onlineOrderSettings->setDeliveryDisableTime($data->onlineOrderSettings->deliveryDisableTime);
$onlineOrderSettings->setDeliveryNearlyEnabled($data->onlineOrderSettings->deliveryNearlyEnabled);
$onlineOrderSettings->setDeliveryPriceInfo($data->onlineOrderSettings->deliveryPriceInfo ?? null);
$onlineOrderSettings->setDeliveryWorkingTime($data->onlineOrderSettings->deliveryWorkingTime ?? null);
$onlineOrderSettings->setPickupCookingTime($data->onlineOrderSettings->pickupCookingTime ?? null);
$this->setOnlineOrderSettings($onlineOrderSettings);
}
if (isset($data->directorID)) {
$this->directorID = $data->directorID;
}
}
public function isBuyCodeDisable() {
return $this->buyCodeDisable;
}
public function setBuyCodeDisable($buyCodeDisable) {
$this->buyCodeDisable = $buyCodeDisable;
}
public function isHideInApp() {
return $this->hideInApp;
}
public function setHideInApp($hideInApp) {
$this->hideInApp = $hideInApp;
}
public function getBrandboxEnabled() {
return $this->brandboxEnabled;
}
public function setBrandboxEnabled($brandboxEnabled): void {
$this->brandboxEnabled = $brandboxEnabled;
}
public function getDiscountPickupPopup(): ?string
{
return $this->discountPickupPopup;
}
public function setDiscountPickupPopup(?string $discountPickupPopup): void
{
$this->discountPickupPopup = $discountPickupPopup;
}
public function getExternalOfferLink(): ?string
{
return $this->externalOfferLink;
}
public function setExternalOfferLink(?string $externalOfferLink): void
{
$this->externalOfferLink = $externalOfferLink;
}
public function getIsShowExternalOfferLink()
{
return $this->isShowExternalOfferLink;
}
public function setIsShowExternalOfferLink($isShowExternalOfferLink): void
{
$this->isShowExternalOfferLink = $isShowExternalOfferLink;
}
public function getDiscountDeliveryPopup(): ?string
{
return $this->discountDeliveryPopup;
}
public function setDiscountDeliveryPopup(?string $discountDeliveryPopup): void
{
$this->discountDeliveryPopup = $discountDeliveryPopup;
}
public function isFoodOnlineOrderAllowedOnSite(): bool
{
return $this->isOnlineOrderAllowedByDeviceAndType(
OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::SITE),
OfferOnlineOrderType::byValue(OfferOnlineOrderType::FOOD)
);
}
public function isFoodOnlineOrderAllowedOnApp(): bool
{
return $this->isOnlineOrderAllowedByDeviceAndType(
OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::APP),
OfferOnlineOrderType::byValue(OfferOnlineOrderType::FOOD)
);
}
public function isGiftCertificateOnlineOrderAllowedOnSite(): bool
{
return $this->isOnlineOrderAllowedByDeviceAndType(
OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::SITE),
OfferOnlineOrderType::byValue(OfferOnlineOrderType::GIFT_CERTIFICATE)
);
}
public function isGiftCertificateOnlineOrderAllowedOnApp(): bool
{
return $this->isOnlineOrderAllowedByDeviceAndType(
OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::APP),
OfferOnlineOrderType::byValue(OfferOnlineOrderType::GIFT_CERTIFICATE)
);
}
public function isTireOnlineOrderAllowedOnSite(): bool
{
return $this->isOnlineOrderAllowedByDeviceAndType(
OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::SITE),
OfferOnlineOrderType::byValue(OfferOnlineOrderType::TIRE)
);
}
public function isTireOnlineOrderAllowedOnApp(): bool
{
return $this->isOnlineOrderAllowedByDeviceAndType(
OfferOnlineOrderDevice::byValue(OfferOnlineOrderDevice::APP),
OfferOnlineOrderType::byValue(OfferOnlineOrderType::TIRE)
);
}
public function isOneOfOnlineOrderAllowedOnApp(): bool
{
if (null === $this->allowedOnlineOrderTypes) {
return false;
}
return \count($this->allowedOnlineOrderTypes[OfferOnlineOrderDevice::APP]) > 0;
}
public function isOneOfOnlineOrderAllowedOnSite(): bool
{
if (null === $this->allowedOnlineOrderTypes) {
return false;
}
return \count($this->allowedOnlineOrderTypes[OfferOnlineOrderDevice::SITE]) > 0;
}
public function getAllowedOnlineOrderTypesOnApp(): ?array
{
if (null === $this->allowedOnlineOrderTypes || 0 === count($this->allowedOnlineOrderTypes[OfferOnlineOrderDevice::APP])) {
return null;
}
return $this->allowedOnlineOrderTypes[OfferOnlineOrderDevice::APP];
}
private function isOnlineOrderAllowedByDeviceAndType(OfferOnlineOrderDevice $device, OfferOnlineOrderType $type): bool
{
if (null === $this->allowedOnlineOrderTypes) {
return false;
}
return in_array($type->getValue(), $this->allowedOnlineOrderTypes[$device->getValue()], true);
}
public function getOfferType(bool $isBoughtFreeCode = false): int
{
$offerType = self::TYPE_DEFAULT;
if (in_array($this->getID(), Dominos::OFFER_IDS_MINSK_AND_REGIONS, true)) {
return self::TYPE_DOMINOS;
}
if ($this->isFoodOnlineOrderAllowedOnApp()) {
return $this->isBuyCodeDisable() ? self::TYPE_ONLINE_ORDER_ONLY : self::TYPE_ONLINE_ORDER;
}
if ($this->isGiftCertificateOnlineOrderAllowedOnApp()) {
return $this->isBuyCodeDisable() ? self::TYPE_GIFT_CERTIFICATE_DISABLE_CODE : self::TYPE_GIFT_CERTIFICATE;
}
if ($this->getID() === self::PETROL_OFFER_ID) {
return self::TYPE_TRIPLE;
}
if ($this->getTireExtensions()->count() > 0) {
return self::TYPE_TIRE;
}
if (!$isBoughtFreeCode && ($this->isInFreeCodesCategory() || $this->isFree())) {
return self::TYPE_FREE_PER_DAY;
}
return $offerType;
}
public function isHideFeatures() {
return $this->hideFeatures;
}
public function setHideFeatures($hideFeatures) {
$this->hideFeatures = $hideFeatures;
}
public function getFirstGeoLocation(): GeoLocation
{
return $this->geoLocations->first();
}
public function getDeliveryTimeTeaser(): ?string
{
return $this->deliveryTimeTeaser;
}
public function setDeliveryTimeTeaser(?string $deliveryTimeTeaser): void
{
$this->deliveryTimeTeaser = $deliveryTimeTeaser;
}
public function isExternalOfferLinkAndShow(): bool
{
return null !== $this->externalOfferLink && $this->isShowExternalOfferLink;
}
public function isNotAccess(): bool
{
return !$this->isActive() || $this->isHidden() || !$this->isInActivePeriod() || $this->isBuyCodeDisable();
}
public function getFoodcourtInfoTeaser(): ?string
{
return $this->foodcourtInfoTeaser;
}
public function setFoodcourtInfoTeaser(?string $foodcourtInfoTeaser): void
{
$this->foodcourtInfoTeaser = $foodcourtInfoTeaser;
}
public function getFoodcourtInfoColorTeaser(): ?string
{
return $this->foodcourtInfoColorTeaser;
}
public function setFoodcourtInfoColorTeaser(?string $foodcourtInfoColorTeaser): void
{
$this->foodcourtInfoColorTeaser = $foodcourtInfoColorTeaser;
}
public function isIncludedInBeauty(): bool
{
return $this->isIncludedInBeauty;
}
public function setIsIncludedInBeauty(bool $isIncludedInBeauty): void
{
$this->isIncludedInBeauty = $isIncludedInBeauty;
}
public function getStatus(): OfferStatus
{
return $this->isVisible() ? OfferStatus::byValue(OfferStatus::ACTIVATED) : OfferStatus::byValue(OfferStatus::DEACTIVATED);
}
public function getCity(): ?City
{
foreach ($this->categories as $category) {
if ($category->getID() === $this->getDefaultCategoryID()) {
return $category->getCity();
}
}
$category = $this->categories->first();
return false === $category ? null : $category->getCity();
}
public function isOnlineAutoOpened(): bool
{
return $this->onlineAutoOpened;
}
public function setOnlineAutoOpened(bool $onlineAutoOpened): void
{
$this->onlineAutoOpened = $onlineAutoOpened;
}
public function isFoodcourtLogoEnabled(): bool
{
return $this->foodcourtLogoEnabled;
}
public function setFoodcourtLogoEnabled(bool $foodcourtLogoEnabled): void
{
$this->foodcourtLogoEnabled = $foodcourtLogoEnabled;
}
public function isOnlineOrderGiftEnabled(): bool
{
return $this->onlineOrderGiftEnabled;
}
public function setOnlineOrderGiftEnabled(bool $onlineOrderGiftEnabled): void
{
$this->onlineOrderGiftEnabled = $onlineOrderGiftEnabled;
}
public function isBuyCodeInAppOnly(): bool
{
return $this->buyCodeInAppOnly;
}
public function setBuyCodeInAppOnly(bool $buyCodeInAppOnly): void
{
$this->buyCodeInAppOnly = $buyCodeInAppOnly;
}
public function isShowProductsInOfferDescription(): bool
{
return $this->showProductsInOfferDescription;
}
public function setShowProductsInOfferDescription(bool $showProductsInOfferDescription): void
{
$this->showProductsInOfferDescription = $showProductsInOfferDescription;
}
public function isCheckAddressInOfferMenu(): bool
{
return $this->checkAddressInOfferMenu;
}
public function setCheckAddressInOfferMenu(bool $checkAddressInOfferMenu): void
{
$this->checkAddressInOfferMenu = $checkAddressInOfferMenu;
}
public function isShowMapIconInApp(): bool
{
return $this->showMapIconInApp;
}
public function setShowMapIconInApp(bool $showMapIconInApp): void
{
$this->showMapIconInApp = $showMapIconInApp;
}
public function isDuplicateCodesEnable(): bool
{
return in_array($this->ID, [
self::CAR_SHARING_OFFER_ID,
280939,
289045,
289751,
self::TL24_OFFER_ID,
294815,
],
true,
);
}
public function getCityByFirstCategory(): ?City
{
return $this->categories->count() > 0 ? $this->categories->first()->getCity() : null;
}
public function isSeparateTabForCertificatesInApp(): bool
{
return $this->separateTabForCertificatesInApp;
}
public function setSeparateTabForCertificatesInApp(bool $separateTabForCertificatesInApp): void
{
$this->separateTabForCertificatesInApp = $separateTabForCertificatesInApp;
}
public function getMapPrice(): ?float
{
return $this->mapPrice;
}
public function updateMapPrice(?float $mapPrice): void
{
$this->mapPrice = $mapPrice;
}
public function getMapRating(): ?int
{
return $this->mapRating;
}
public function updateMapRating(?int $mapRating): void
{
$this->mapRating = $mapRating;
}
public function getSumInCurrency(float $sum): ?float
{
return $this->isActiveCurrencyCalculator() && null !== $this->getBankCurrency()
? $sum / $this->getBankCurrency()->getRate()
: null;
}
public function getDirectorName(): ?string
{
if (null !== $this->directorName) {
return $this->directorName;
}
if ($this->directors->count() > 0) {
$directorName = $this->directors->first()->getName();
$this->directorName = $directorName;
return $directorName;
}
return null;
}
public function getOfferFoodDeliveryZoneNames(): array
{
if (null === $this->offerFoodDeliveryZone) {
return [];
}
$sortedZoneNames = [];
foreach ($this->offerFoodDeliveryZone->toArray() as $zone) {
$sortedZoneNames[$zone->getPosition()] = $zone->getName();
}
return $sortedZoneNames;
}
public function getTelegram(): ?string
{
return $this->telegram;
}
public function getViber(): ?string
{
return $this->viber;
}
public function setTelegram(?string $telegram): void
{
$this->telegram = $telegram;
}
public function setViber(?string $viber): void
{
$this->viber = $viber;
}
public function getMessengerCallBack(): ?string
{
return $this->messengerCallBack;
}
public function setMessengerCallBack(?string $messengerCallBack): void
{
$this->messengerCallBack = $messengerCallBack;
}
public function isBundleOffer(): bool
{
return in_array($this->getID(), [self::MARSEL_MASSAGE_OFFER_ID, self::FREESTYLE_CERTIFICATE_OFFER_ID], true);
}
}