<?php
/**
* (c) itmedia.by <info@itmedia.by>
*/
namespace Submarine\PagesBundle\Entity;
use CatalogBundle\Entity\ProductVariation;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Event\LifecycleEventArgs;
use Doctrine\ORM\Event\PostPersistEventArgs;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Event\PrePersistEventArgs;
use Doctrine\ORM\Mapping as ORM;
use Postroyka\AppBundle\Entity\CronUpdate;
use Postroyka\AppBundle\Entity\PageDefected;
use Postroyka\AppBundle\Redis\RedisBaseProvider;
use Submarine\CoreBundle\Entity\CommentsAwareInterface;
use Submarine\CoreBundle\Entity\OrderAwareInterface;
use Submarine\CoreBundle\Entity\SubmarineEntityInterface;
use Submarine\CoreBundle\Exception\InvalidArgumentException;
use Submarine\CoreBundle\Uploader\AbstractUploadEntity;
use Submarine\FilesBundle\Provider\FilesProvider;
use Submarine\PagesBundle\Entity\Type\PageType;
use Submarine\PagesBundle\Entity\Type\PageValue;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Class Page
* @package Submarine\PagesBundle
*
* @ORM\Entity(repositoryClass="Submarine\PagesBundle\Repository\PageRepository")
*
* @ORM\Table(
* name="submarine_pages",
* indexes={
* @ORM\Index(name="published", columns={"is_enabled", "is_deleted"}),
* @ORM\Index(name="published_at", columns={"published_at"}),
* @ORM\Index(name="url", columns={"url"}),
* @ORM\Index(name="tag", columns={"tag"})
* })
* @ORM\HasLifecycleCallbacks()
*/
class Page extends AbstractUploadEntity implements
SubmarineEntityInterface,
CommentsAwareInterface,
OrderAwareInterface
{
const STOCK_VALUE = "stock";
const IN_STOCK = "in_stock";
const NOT_IN_STOCK = "not_in_stock";
const OUT_PRODUCTION = "out_production";
/**
* ID
* @var int
*
* @ORM\Id()
* @ORM\Column(name="id", type="integer", nullable=false, unique=true)
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* URL
* @var string
*
* @ORM\Column(name="url", type="string", nullable=true)
*/
private $url;
/**
* Имя/ключ документа
*
* @var string
* @ORM\Column(name="tag", type="string", nullable=true)
*/
private $tag;
/**
* Является папкой страница?
* @var bool
*
* @ORM\Column(name="is_directory", type="boolean", nullable=true)
*/
private $directory = false;
/**
* @var string
*
* @ORM\Column(name="title", type="string", nullable=false)
* @Assert\NotBlank()
*/
private $title;
/**
* Описание
* @var string
*
* @ORM\Column(name="description", type="string", nullable=true, length=2048)
*/
private $description;
// --------------- Активность ----------------
/**
* Страница удалена
*
* @var bool
* @ORM\Column(name="is_deleted", type="boolean", nullable=true)
*/
private $deleted = false;
/**
* Страница включена
*
* @var bool
* @ORM\Column(name="is_enabled", type="boolean", nullable=true)
*/
private $enabled = true;
// ------------ Tags ----------------
/**
*
* @var string
*
* @ORM\Column(name="html_title", type="string", nullable=true)
*/
private $metaTitle;
/**
* @var string
*
* @ORM\Column(name="html_meta_description", type="text", nullable=true)
*/
private $metaDescription;
/**
* @var string
*
* @ORM\Column(name="html_meta_keywords", type="string", nullable=true, length=1024)
*/
private $metaKeywords;
// -------------- Связи -----------
/**
* Тип страницы
* @var PageType
*
* @ORM\ManyToOne(targetEntity="Submarine\PagesBundle\Entity\Type\PageType")
* @ORM\JoinColumn(name="type_id", referencedColumnName="id")
*/
private $type;
/**
* Родительские связи страницы
* @var ArrayCollection|Relations[]
*
* @ORM\OneToMany(targetEntity="Submarine\PagesBundle\Entity\Relations", mappedBy="page", cascade={"REMOVE"})
*/
private $parents;
/**
* Дочернмие связи
* @var ArrayCollection|Relations[]
*
* @ORM\OneToMany(targetEntity="Submarine\PagesBundle\Entity\Relations", mappedBy="parent")
*/
private $child;
/**
* Дополнительные поля
* @var ArrayCollection|PageValue[]
*
* @ORM\OneToMany(
* targetEntity="Submarine\PagesBundle\Entity\Type\PageValue",
* mappedBy="page",
* cascade={"ALL"},
* indexBy="field_id",
* )
*/
private $fields;
/**
* Кэширование доп.значения страницы
*
* @var array
* @ORM\Column(name="cached_values", type="array", nullable=true)
*/
private $values = [];
/**
* Тело документа
* @var PageBody
*
* @ORM\ManyToOne(targetEntity="Submarine\PagesBundle\Entity\PageBody", cascade={"ALL"}, inversedBy="pages")
* @ORM\JoinColumn(name="body_id", referencedColumnName="id", nullable=true)
*/
private $pageBody;
/**
* Связанные страницы
* @var Link[]|ArrayCollection
* @ORM\OneToMany(
* targetEntity="Submarine\PagesBundle\Entity\Link",
* mappedBy="parent",
* orphanRemoval=true,
* )
* @ORM\OrderBy({"position"="ASC"})
* @Assert\Valid()
*/
private $linkedPages;
/**
* Связанные страницы в корзине
*
* @var LinkInCart[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="Submarine\PagesBundle\Entity\LinkInCart",
* mappedBy="parent",
* orphanRemoval=true,
* )
* @ORM\OrderBy({"position"="ASC"})
* @Assert\Valid()
*/
private $linkedPagesInCart;
/**
* Сопутствующие товары
*
* @var AccompanyPage[]|ArrayCollection
*
* @ORM\OneToMany(
* targetEntity="Submarine\PagesBundle\Entity\AccompanyPage",
* mappedBy="parent",
* orphanRemoval=true,
* )
* @ORM\OrderBy({"position"="ASC"})
* @Assert\Valid()
*/
private $accompanyPages;
/**
* @ORM\OneToMany(targetEntity="Submarine\PagesBundle\Entity\TitleUrlRelations", mappedBy="page", cascade={"remove", "persist"})
* @var TitleUrlRelations[]|ArrayCollection
*/
private $titleUrlRelations;
// ---------------- Dates ------------
/**
* @var \DateTime
*
* @ORM\Column(name="created_at", type="datetime")
*/
private $createdAt;
/**
* @var \DateTime
*
* @ORM\Column(name="updated_at", type="datetime")
*/
private $updatedAt;
/**
* @var \DateTime
*
* @ORM\Column(name="published_at", type="datetime")
*/
private $publishedAt;
// ---------------- Upload ---------------
/**
* @var File
*/
private $file;
/**
* @var File
*/
private $fileFid;
/**
* @var File|null
*/
private $fileMobileMenu;
/**
* Картинка (путь)
* @var string
*
* @ORM\Column(name="image_path", type="string", nullable=true)
*/
private $image;
/**
* Картинка для фида(путь)
* @var string
*
* @ORM\Column(name="image_path_fid", type="string", nullable=true)
*/
private $imageFid;
// ---------------- Comments ------------
/**
* Количество комментариев
* @ORM\Column(type="integer", unique=false, nullable=true)
* @var integer
*/
private $countComments = 0;
/**
* Количество комментариев
* @ORM\Column(type="boolean", unique=false, nullable=true)
* @var bool
*/
private $allowedComments = false;
/**
* Модерирация кооментариев комментариев
* @ORM\Column(type="boolean", unique=false, nullable=true)
* @var bool
*/
private $moderatedComments = false;
// ---------------- Product --------------
/**
* Стоимость товара
*
* @var float
* @ORM\Column(name="price", type="decimal", precision=15, scale=2, nullable=true)
*/
private $price;
/**
* @var string|null
*
* @Assert\Regex(
* pattern="/^\d+\.?\d*(\;\d+\.?\d*)*$/",
* match=true,
* message="Данные должны быть через ';' (пример: 2.975;3;6)"
* )
*
* @ORM\Column(type="string", nullable=true)
*/
private $multipleDimensions;
/**
* Артикул товара
*
* @var string
* @ORM\Column(name="product_id", type="string", nullable=true, unique=false)
*/
private $productId;
/**
* @ORM\Column(type="string", nullable=true, unique=true)
*/
private ?int $b24Id;
/**
* Количество товаров у категории
*
* @var integer
* @ORM\Column(name="count_products", type="integer", nullable=true, unique=false)
*/
private $countProducts;
/**
* Наличие товара
*
* @var bool
* @ORM\Column(name="is_available", type="boolean", nullable=true)
*/
private $available;
/**
* Распростряняется скидка на товар?
*
* @var bool
* @ORM\Column(name="is_discount", type="boolean", nullable=true)
*/
private $discount;
// ---------------- Virtual ----------------
/**
* @var FilesProvider
*/
private $filesProvider;
/**
* @var bool
*/
private $selected;
/**
* @var Collection
* @ORM\OneToMany(targetEntity="Postroyka\AppBundle\Entity\CronUpdate", mappedBy="page")
*/
private $cronUpdates;
/**
* @ORM\OneToOne(targetEntity="Postroyka\AppBundle\Entity\PageDefected", mappedBy="parent", cascade={"remove", "persist"})
*/
private ?PageDefected $pageDefected;
/**
* Статус товара
*
* @var string
*
* @ORM\Column(name="product_status", type="string", nullable=false, options={"default" : Submarine\PagesBundle\Entity\Page::NOT_IN_STOCK})
*/
private $productStatus;
/**
* @ORM\OneToOne(targetEntity="Submarine\PagesBundle\Entity\PageB24UpdateTime", mappedBy="page", cascade={"remove", "persist"})
*/
private ?PageB24UpdateTime $pageB24UpdateTime;
/**
* Связи с данными по складам
* @var ArrayCollection
*
* @ORM\OneToMany(targetEntity="Submarine\PagesBundle\Entity\PageB24Warehouse", mappedBy="page", cascade={"REMOVE"})
*/
private Collection $pageB24Warehouses;
/**
* Картинка для мобильного меню(путь)
* @var string|null
*
* @ORM\Column(name="image_mobile_menu", type="string", nullable=true)
*/
private $imageMobileMenu;
/**
* Арктикул товара
*
* @var string
*
* @ORM\Column(type="string", nullable=false, unique=true)
*/
private $vendorCode;
// ------------------ Methods ---------------
/**
* Имя сущности
* @return string
*/
public static function entityName()
{
return __CLASS__;
}
public function __construct()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->publishedAt = new \DateTime();
$this->pageBody = new PageBody();
$this->fields = new ArrayCollection();
$this->parents = new ArrayCollection();
$this->linkedPages = new ArrayCollection();
$this->accompanyPages = new ArrayCollection();
$this->linkedPagesInCart = new ArrayCollection();
$this->titleUrlRelations = new ArrayCollection();
$this->cronUpdates = new ArrayCollection();
$this->pageB24Warehouses = new ArrayCollection();
$this->productStatus = self::NOT_IN_STOCK;
$this->pageB24UpdateTime = new PageB24UpdateTime($this);
}
public function __clone()
{
$this->id = null;
}
/**
* @ORM\PreUpdate()
*/
public function preUpdate()
{
$this->updatedAt = new \DateTime();
RedisBaseProvider::clearKeysByPattern('*' . RedisBaseProvider::REDIS_HOMEPAGE_KEY);
RedisBaseProvider::clearKeysByPattern('*' . RedisBaseProvider::CATALOG_PAGE_REDIS_KEY . '*');
RedisBaseProvider::setKey(RedisBaseProvider::REDIS_PRODUCT_UPDATE);
}
/**
* @ORM\PreFlush()
*/
public function preFlush(PreFlushEventArgs $args)
{
if(!$this->vendorCode || !$this->id || strpos($this->vendorCode, (string)$this->id, 3) === false){
$this->vendorCode = rand(100, 999) . str_pad($this->id, 5, "0", STR_PAD_LEFT);
}
}
/**
* ID сущности
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @return PageType
*/
public function getType()
{
return $this->type;
}
/**
* @param PageType $type
*/
public function setType(PageType $type)
{
$this->type = $type;
$this->directory = $type->isDirectory();
$this->allowedComments = $type->isAllowComments();
}
/**
* @return ArrayCollection|Relations[]
*/
public function getParents()
{
return $this->parents;
}
/**
* Родительские страницы
* ВАЖНО!!! Зансение в массиве может быть и null - значит родитель корневая папка
* Page[]
*/
public function getParentPages()
{
$parent = [];
foreach ($this->parents as $rel) {
$parent[] = $rel->getParent();
}
return $parent;
}
// -------------- Состояние страницы ---------------
/**
* @return boolean
*/
public function isDirectory()
{
return $this->directory;
}
/**
* @param boolean $directory
*/
public function setDirectory($directory)
{
$this->directory = $directory;
}
/**
* @return boolean
*/
public function isEnabled()
{
return $this->enabled;
}
/**
* @param boolean $enabled
*/
public function setEnabled($enabled)
{
$this->enabled = $enabled;
}
/**
* @return boolean
*/
public function isDeleted()
{
return $this->deleted;
}
/**
* @param boolean $deleted
*/
public function setDeleted($deleted)
{
$this->deleted = $deleted;
}
// ------------ Идентификация страницы -----------
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl($url)
{
if (0 !== strpos($url, '/')) {
$url = '/' . $url;
}
$this->url = $url;
}
/**
* @return string
*/
public function getTag()
{
return $this->tag;
}
/**
* @param string $key
*/
public function setTag($key)
{
$this->tag = $key;
}
// --------------- Content ---------------
/**
* @return string
*/
public function getTitle()
{
return $this->title;
}
/**
* @param string $title
*/
public function setTitle($title)
{
$this->title = $title;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return string
*/
public function getImage()
{
return $this->image;
}
/**
* @return string
*/
public function getImageFid()
{
return $this->imageFid;
}
/**
* @return string|null
*/
public function getImageMobileMenu(): ?string
{
return $this->imageMobileMenu;
}
/**
* @param string|null $imageMobileMenu
*/
public function setImageMobileMenu(?string $imageMobileMenu): void
{
$this->imageMobileMenu = $imageMobileMenu;
}
/**
* @return PageBody
*/
public function getPageBody()
{
return $this->pageBody;
}
/**
* @param PageBody $body
*/
public function setPageBody(PageBody $body)
{
$this->pageBody = $body;
}
/**
* Тело документа
* @return string
*/
public function getBody()
{
return $this->pageBody->getBody();
}
/**
* Тело документа
*
* @param $pageBody
*/
public function setBody($pageBody)
{
$this->pageBody->setBody($pageBody);
}
/**
* @return ArrayCollection|PageValue[]
*/
public function getFields()
{
return $this->fields;
}
/**
* @param $name
*
* @return PageValue|null
*/
public function getField($name)
{
return $this->fields->get($name);
}
/**
* @param array $values
*/
public function setValues($values)
{
$this->values = [];
foreach ($values as $key => $value) {
$this->setValue($key, $value);
}
}
/**
* Обновление кэша значений
*/
public function updateCacheValues()
{
$values = [];
foreach ($this->fields as $field) {
$values[$field->getField()->getId()] = $field->getValue();
}
$this->values = $values;
}
/**
* @return array
*/
public function getValues()
{
$this->updateCacheValues();
return $this->values;
}
/**
* Установка значения
*
* @param string $name
* @param string $value
* @param bool $strict Если true - будет выдано исключение при попытке сохранить значение для не найденого поля
*
* @throws InvalidArgumentException
*/
public function setValue($name, $value, $strict = false)
{
if ($this->getType()->hasField($name)) {
$field = $this->getField($name);
if (!$field) {
if ($strict) {
throw new InvalidArgumentException(sprintf('Field %s not found', $name));
}
$field = new PageValue($this->getType()->getField($name), $this, $value);
$this->fields->set($name, $field);
} else {
$field->setValue($value);
}
$this->values[$name] = $value;
}
}
/**
* Значение (из кэша)
*
* @param $name
* @param null|string $default
*
* @return mixed
*/
public function getValue($name, $default = null)
{
return isset($this->values[$name]) ? $this->values[$name] : $default;
}
/**
* @return ArrayCollection|Relations[]
*/
public function getChild()
{
return $this->child;
}
/**
* @return ArrayCollection|Link[]
*/
public function getLinkedPages()
{
return $this->linkedPages;
}
/**
* @param ArrayCollection|Link[] $linkedPages
*/
public function setLinkedPages($linkedPages)
{
$this->linkedPages = $linkedPages;
}
/**
* @param Link $linkedPage
*/
public function addLinkedPage(Link $linkedPage)
{
$this->linkedPages->add($linkedPage);
$linkedPage->setParent($this);
}
/**
* @param Link $linkedPage
*/
public function removeLinkedPage(Link $linkedPage)
{
$this->linkedPages->removeElement($linkedPage);
}
/**
* @return ArrayCollection|LinkInCart[]
*/
public function getLinkedPagesInCart()
{
return $this->linkedPagesInCart;
}
/**
* @param ArrayCollection|LinkInCart[] $linkedPagesInCart
*/
public function setLinkedPagesInCart($linkedPagesInCart)
{
$this->linkedPagesInCart = $linkedPagesInCart;
}
/**
* @param LinkInCart $linkedPageInCart
*/
public function addLinkedPageInCart(LinkInCart $linkedPageInCart)
{
$this->linkedPagesInCart->add($linkedPageInCart);
$linkedPageInCart->setParent($this);
}
/**
* @param LinkInCart $linkedPageInCart
*/
public function removeLinkedPageInCart(Link $linkedPageInCart)
{
$this->linkedPagesInCart->removeElement($linkedPageInCart);
}
/**
* @return ArrayCollection|AccompanyPage[]
*/
public function getAccompanyPages()
{
return $this->accompanyPages;
}
/**
* @param ArrayCollection|AccompanyPage[] $accompanyPages
*/
public function setAccompanyPages($accompanyPages): void
{
$this->accompanyPages = $accompanyPages;
}
/**
* @param AccompanyPage $accompanyPage
*/
public function addAccompanyPage(AccompanyPage $accompanyPage)
{
$this->accompanyPages->add($accompanyPage);
$accompanyPage->setParent($this);
}
/**
* @param AccompanyPage $accompanyPage
*/
public function removeAccompanyPage(AccompanyPage $accompanyPage)
{
$this->accompanyPages->removeElement($accompanyPage);
}
/**
* @return TitleUrlRelations[]|ArrayCollection
*/
public function getTitleUrlRelation()
{
return $this->titleUrlRelations;
}
/**
* @param TitleUrlRelations[]|ArrayCollection $titleUrlRelations
*/
public function setTitleUrlRelations($titleUrlRelations): void
{
$this->titleUrlRelations = $titleUrlRelations;
}
/**
* @param TitleUrlRelations $titleUrlRelation
*/
public function addTitleUrlRelation(TitleUrlRelations $titleUrlRelation)
{
$titleUrlRelation->setPage($this);
$this->titleUrlRelations->add($titleUrlRelation);
}
/**
* @param TitleUrlRelations $titleUrlRelation
*/
public function removeTitleUrlRelation(TitleUrlRelations $titleUrlRelation)
{
$this->titleUrlRelations->removeElement($titleUrlRelation);
}
public function getTitleUrlRelationByTitle(string $title): ?TitleUrlRelations
{
foreach ($this->titleUrlRelations as $titleUrlRelation) {
if ($titleUrlRelation->getTitle() == $title) {
return $titleUrlRelation;
}
}
return null;
}
public function getLinkedPagesProducts()
{
return $this->getLinkedProducts($this->getLinkedPages());
}
public function getLinkedPagesInCartProducts()
{
return $this->getLinkedProducts($this->getLinkedPagesInCart());
}
public function getLinkedProducts($links)
{
$linkedProducts = new ArrayCollection();
/** @var SubmarineEntityInterface $link */
foreach ($links as $link){
$linkedProducts->add($link->getPage());
}
return $linkedProducts;
}
// ---------------- Dates -----------------
/**
* @return \DateTime
*/
public function getPublishedAt()
{
return $this->publishedAt;
}
/**
* @param \DateTime $publishedAt
*/
public function setPublishedAt($publishedAt)
{
$this->publishedAt = $publishedAt;
}
/**
* @return \DateTime
*/
public function getCreatedAt()
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt($createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt()
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt($updatedAt)
{
$this->updatedAt = $updatedAt;
}
// ---------------- Tags ------------------
/**
* @return string
*/
public function getMetaTitle()
{
return $this->metaTitle;
}
/**
* @param string $tagTitle
*/
public function setMetaTitle($tagTitle)
{
$this->metaTitle = $tagTitle;
}
/**
* @return string
*/
public function getMetaDescription()
{
return $this->metaDescription;
}
/**
* @param string $tagMetaDescription
*/
public function setMetaDescription($tagMetaDescription)
{
$this->metaDescription = $tagMetaDescription;
}
/**
* @return string
*/
public function getMetaKeywords()
{
return $this->metaKeywords;
}
/**
* @param string $tagMetaKeywords
*/
public function setMetaKeywords($tagMetaKeywords)
{
$this->metaKeywords = $tagMetaKeywords;
}
// -------------------- Comments --------------
/**
* Количество коментариев
* @return integer
*/
public function getCountComments()
{
return $this->countComments;
}
/**
* Установить кол-во комментарием
*
* @param $count
*/
public function setCountComments($count)
{
$this->countComments = $count;
}
/**
* Разрешено комментировать сущность?
* @return bool
*/
public function isAllowedComments()
{
return $this->allowedComments;
}
/**
* @param boolean $allowedComments
*/
public function setAllowedComments($allowedComments)
{
$this->allowedComments = $allowedComments;
}
/**
* Включена премодерация комментариев к сущности?
* @return bool
*/
public function isModeratedComments()
{
return $this->moderatedComments;
}
/**
* @param boolean $moderatedComments
*/
public function setModeratedComments($moderatedComments)
{
$this->moderatedComments = $moderatedComments;
}
/**
* Имя route для просмотра сущности в администраторской части
* Route должен иметь парамер {id}
* @return string|null
*/
public function getRouteNameBackend()
{
return null;
}
// ---------------- Virtual -------------
/**
* @param FilesProvider $filesProvider
*/
public function setFilesProvider($filesProvider)
{
$this->filesProvider = $filesProvider;
}
/**
* Фотогалерея
* @return \Submarine\FilesBundle\Entity\Image[]
*/
public function getImages()
{
return $this->filesProvider->getEntityImages($this);
}
public function getFiles()
{
return $this->filesProvider->getEntityFiles($this);
}
/**
* @return boolean
*/
public function isSelected()
{
return $this->selected;
}
/**
* @param boolean $selected
*/
public function setSelected($selected)
{
$this->selected = $selected;
}
// ------------------ Files ----------------
public function getPathPublic()
{
return 'media/pages/';
}
/**
* Установка файла
*
* @param File $file
*/
public function setFile(File $file = null)
{
$this->file = $file;
}
/**
* Получение файла
* @return File
*/
public function getFile()
{
return $this->file;
}
/**
* Установка файла
*
* @param File $file
*/
public function setFileFid(File $file = null)
{
$this->fileFid = $file;
}
/**
* Получение файла
* @return File
*/
public function getFileFid()
{
return $this->fileFid;
}
/**
* @return File|null
*/
public function getFileMobileMenu(): ?File
{
return $this->fileMobileMenu;
}
/**
* @param File|null $fileMobileMenu
*/
public function setFileMobileMenu(?File $fileMobileMenu): void
{
$this->fileMobileMenu = $fileMobileMenu;
}
/**
* Путь к файлу
*
* @param string $filePath
*/
public function setFilePath($filePath)
{
$this->image = $filePath;
}
/**
* Путь к файлу
* @return string
*/
public function getFilePath()
{
return $this->image;
}
/**
* Путь к файлу фида
*
* @param string $filePath
*/
public function setFilePathFid($filePath)
{
$this->imageFid = $filePath;
}
/**
* Путь к файлу фида
* @return string
*/
public function getFilePathFid()
{
return $this->imageFid;
}
// -------------------- E-commerce ------------------
/**
* Стоимость товара
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* @param float|string $price
*/
public function setPrice($price)
{
if (is_string($price)) {
$price = str_replace([',', ' '], ['.', ''], $price);
}
$this->price = (float)$price;
}
/**
* @return null|string
*/
public function getMultipleDimensions(): ?string
{
return $this->multipleDimensions;
}
/**
* @param null|string $multipleDimensions
*/
public function setMultipleDimensions(?string $multipleDimensions): void
{
$this->multipleDimensions = trim($multipleDimensions);
}
/**
* @return array
*/
public function getArrayMultipleDimensions(): array
{
if(!$this->multipleDimensions){
return [];
}
$parsedValues = [];
foreach (explode(';', $this->multipleDimensions) as $item){
$parsedValues[] = (float)trim($item);
}
return $parsedValues;
}
/**
* Наличие товара
* @return boolean
*/
public function isAvailable()
{
return $this->available;
}
/**
* @param boolean $available
*/
public function setAvailable($available)
{
$this->available = $available;
}
/**
* Распространяется скидка на товар?
* @return bool
*/
public function isDiscount()
{
return $this->discount;
}
/**
* @param boolean $discount
*/
public function setDiscount($discount)
{
$this->discount = $discount;
}
/**
* @return null|int
*/
public function getCountProducts(): ?int
{
return $this->countProducts;
}
/**
* @return bool
*/
public function isHaveProducts(): bool
{
return $this->countProducts !== 0;
}
/**
* @param int $countProducts
*/
public function setCountProducts(int $countProducts): void
{
$this->countProducts = $countProducts;
}
/**
* Артикул товара
* @return string
*/
public function getProductId()
{
return $this->productId;
}
/**
* @return string
*/
public function getProductStatus(): string
{
return $this->productStatus;
}
/**
* @param string $productStatus
*/
public function setProductStatus(string $productStatus): void
{
$this->productStatus = $productStatus;
}
public function inStock()
{
return $this->productStatus === self::IN_STOCK;
}
/**
* @param string $productId
*/
public function setProductId($productId)
{
$this->productId = $productId;
}
/**
* @return Collection
*/
public function getCronUpdates()
{
return $this->cronUpdates;
}
/**
* @param Collection $cronUpdates
*/
public function setCronUpdates($cronUpdates): void
{
$this->cronUpdates = $cronUpdates;
}
/**
* @return PageDefected|null
*/
public function getPageDefected(): ?PageDefected
{
return $this->pageDefected;
}
/**
* @param PageDefected|null $pageDefected
*/
public function setPageDefected(?PageDefected $pageDefected): void
{
$this->pageDefected = $pageDefected;
}
public function hasActivePageDefected() : bool
{
return $this->pageDefected && $this->pageDefected->isActive();
}
/**
* @return PageB24UpdateTime|null
*/
public function getPageB24UpdateTime(): ?PageB24UpdateTime
{
return $this->pageB24UpdateTime;
}
/**
* @param PageB24UpdateTime|null $pageB24UpdateTime
*/
public function setPageB24UpdateTime(?PageB24UpdateTime $pageB24UpdateTime): void
{
$this->pageB24UpdateTime = $pageB24UpdateTime;
}
/**
* @return int|null
*/
public function getB24Id(): ?int
{
return $this->b24Id;
}
/**
* @param int|null $b24Id
*/
public function setB24Id(?int $b24Id): void
{
$this->b24Id = $b24Id;
}
/**
* @return string
*/
public function getVendorCode(): string
{
return $this->vendorCode;
}
/**
* @param string $vendorCode
*/
public function setVendorCode(string $vendorCode): void
{
$this->vendorCode = $vendorCode;
}
public function getPageB24Warehouses(int $WHId = null): ArrayCollection|Collection|null
{
if($WHId){
$wh = $this->getPageB24Warehouses()->filter(function (PageB24Warehouse $pageB24Warehouse) use ($WHId){
return (int)$pageB24Warehouse->getB24WHId() === $WHId;
});
return $wh->count() ? $wh : null;
}
return $this->pageB24Warehouses;
}
public function setPageB24Warehouses(ArrayCollection|Collection $pageB24Warehouses): void
{
$this->pageB24Warehouses = $pageB24Warehouses;
}
public function getNotEmptyPageB24Warehouses(): ArrayCollection|Collection
{
$WHsNotEmpty = new ArrayCollection();
//to fix issue with double WH
/** @var PageB24Warehouse $pageB24Warehouse */
foreach ($this->getPageB24Warehouses() as $pageB24Warehouse){
if($pageB24Warehouse->getCountInStock() > 0) {
$WHsNotEmpty->set($pageB24Warehouse->getB24WHId(), $pageB24Warehouse);
}
}
return $WHsNotEmpty;
}
public function getCronUpdateByType(string $type)
{
/** @var CronUpdate $cronUpdate */
foreach ($this->cronUpdates as $cronUpdate){
if($cronUpdate->getTypeAction() === $type){
return $cronUpdate;
}
}
return new CronUpdate();
}
public function getCatalogLevel($level = 0)
{
if(!$this->parents->first()->getParent()){
return $level;
}
return $this->parents->first()->getParent()->getCatalogLevel($level + 1);
}
public function getMainCatalogPage()
{
$level = $this->getCatalogLevel();
if($level < 2){
return $this;
}
$page = $this;
foreach (range(2, $level) as $index){
$page = $page->parents->first()->getParent();
}
return $page;
}
}