<?php
namespace App\Entity\Shop\Shop;
use App\Entity\BaseEntity;
use App\Entity\BaseSite\Domain;
use App\Entity\BaseSite\Plan\AddOn;
use App\Entity\BaseSite\Plan\Plan;
use App\Entity\Generic\Customer\Customer;
use App\Entity\Generic\User;
use App\Entity\Shop\Accounting\Transaction;
use App\Entity\Shop\Blog\Article;
use App\Entity\Shop\Blog\Category;
use App\Entity\Shop\Blog\Tag;
use App\Entity\Shop\Cart\Cart;
use App\Entity\Shop\Cart\CartItem;
use App\Entity\Shop\Cart\CartItemAttribute;
use App\Entity\Shop\Menu\Menu;
use App\Entity\Shop\Order\Coupon;
use App\Entity\Shop\Order\Discount;
use App\Entity\Shop\Order\Order;
use App\Entity\Shop\Order\ShippingMethod;
use App\Entity\Shop\Page\Page;
use App\Entity\Shop\PostType\PostType;
use App\Entity\Shop\Product\Product;
use App\Entity\Shop\Product\ProductAttribute;
use App\Entity\Shop\Product\ProductAttributeValue;
use App\Entity\Shop\Product\ProductCategory;
use App\Entity\Shop\Setting;
use App\Entity\Shop\Ticket\Ticket;
use App\Repository\Shop\Shop\ShopRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
#[ORM\Entity(repositoryClass: ShopRepository::class)]
#[UniqueEntity(fields: ['subdomain'], message: 'این نام کاربری فروشگاه از قبل موجود می باشد')]
class Shop extends BaseEntity
{
#[ORM\Id]
#[ORM\Column(type: 'guid', unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: UuidGenerator::class)]
private ?string $id;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\Column(length: 255, unique: true)]
private ?string $subdomain = null;
#[ORM\Column]
private ?float $shopBalance = null;
#[ORM\ManyToOne(inversedBy: 'shops')]
#[ORM\JoinColumn(nullable: false)]
private ?User $owner = null;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Customer::class)]
private Collection $customers;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Product::class)]
private Collection $products;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: ProductAttribute::class)]
private Collection $productAttributes;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: ProductAttributeValue::class)]
private Collection $productAttributeValues;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Discount::class)]
private Collection $discounts;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Cart::class)]
private Collection $carts;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: CartItem::class)]
private Collection $cartItems;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: CartItemAttribute::class)]
private Collection $cartItemAttributes;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Coupon::class)]
private Collection $coupons;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Order::class)]
private Collection $orders;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: ShippingMethod::class)]
private Collection $shippingMethods;
#[ORM\Column(length: 255, nullable: true)]
private ?string $theme = null;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: ProductCategory::class)]
private Collection $productCategories;
#[ORM\Column(nullable: true)]
private ?array $analyticsData = null;
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $expiredAt = null;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: PostType::class)]
private Collection $postTypes;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Menu::class)]
private Collection $menus;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Setting::class)]
private Collection $settings;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Page::class)]
private Collection $pages;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Article::class)]
private Collection $articles;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Category::class)]
private Collection $categories;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Tag::class)]
private Collection $tags;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Ticket::class)]
private Collection $tickets;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Transaction::class)]
private Collection $transactions;
#[ORM\Column(type: Types::BIGINT)]
private ?string $trafficUsage = null;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: Domain::class)]
private Collection $domains;
#[ORM\ManyToOne(inversedBy: 'shops')]
private ?Plan $currentPlan = null;
#[ORM\OneToMany(mappedBy: 'shop', targetEntity: AddOn::class)]
private Collection $addOns;
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $planStartedAt = null;
public function subdomainAddress()
{
return $this->subdomain.'.poooshe.com';
}
public function __construct()
{
$this->setTrafficUsage(0);
parent::__construct();
$now = new \DateTimeImmutable();
$this->setExpiredAt($now->modify("+7 days"));
$this->setPlanStartedAt($now);
$this->shopBalance = 0;
$this->customers = new ArrayCollection();
$this->products = new ArrayCollection();
$this->productAttributes = new ArrayCollection();
$this->productAttributeValues = new ArrayCollection();
$this->discounts = new ArrayCollection();
$this->carts = new ArrayCollection();
$this->cartItems = new ArrayCollection();
$this->cartItemAttributes = new ArrayCollection();
$this->coupons = new ArrayCollection();
$this->orders = new ArrayCollection();
$this->shippingMethods = new ArrayCollection();
$this->productCategories = new ArrayCollection();
$this->postTypes = new ArrayCollection();
$this->menus = new ArrayCollection();
$this->settings = new ArrayCollection();
$this->pages = new ArrayCollection();
$this->articles = new ArrayCollection();
$this->categories = new ArrayCollection();
$this->tags = new ArrayCollection();
$this->tickets = new ArrayCollection();
$this->transactions = new ArrayCollection();
$this->domains = new ArrayCollection();
$this->addOns = new ArrayCollection();
}
public function getId(): ?string
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getSubdomain(): ?string
{
return $this->subdomain;
}
public function setSubdomain(string $subdomain): static
{
$this->subdomain = $subdomain;
return $this;
}
public function getShopBalance(): ?float
{
return $this->shopBalance;
}
public function setShopBalance(float $shopBalance): static
{
$this->shopBalance = $shopBalance;
return $this;
}
public function getOwner(): ?User
{
return $this->owner;
}
public function setOwner(?User $owner): static
{
$this->owner = $owner;
return $this;
}
/**
* @return Collection<int, Customer>
*/
public function getCustomers(): Collection
{
return $this->customers;
}
public function addCustomer(Customer $customer): static
{
if (!$this->customers->contains($customer)) {
$this->customers->add($customer);
$customer->setShop($this);
}
return $this;
}
public function removeCustomer(Customer $customer): static
{
if ($this->customers->removeElement($customer)) {
// set the owning side to null (unless already changed)
if ($customer->getShop() === $this) {
$customer->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Product>
*/
public function getProducts(): Collection
{
return $this->products;
}
public function addProduct(Product $product): static
{
if (!$this->products->contains($product)) {
$this->products->add($product);
$product->setShop($this);
}
return $this;
}
public function removeProduct(Product $product): static
{
if ($this->products->removeElement($product)) {
// set the owning side to null (unless already changed)
if ($product->getShop() === $this) {
$product->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductAttribute>
*/
public function getProductAttributes(): Collection
{
return $this->productAttributes;
}
public function addProductAttribute(ProductAttribute $productAttribute): static
{
if (!$this->productAttributes->contains($productAttribute)) {
$this->productAttributes->add($productAttribute);
$productAttribute->setShop($this);
}
return $this;
}
public function removeProductAttribute(ProductAttribute $productAttribute): static
{
if ($this->productAttributes->removeElement($productAttribute)) {
// set the owning side to null (unless already changed)
if ($productAttribute->getShop() === $this) {
$productAttribute->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, ProductAttributeValue>
*/
public function getProductAttributeValues(): Collection
{
return $this->productAttributeValues;
}
public function addProductAttributeValue(ProductAttributeValue $productAttributeValue): static
{
if (!$this->productAttributeValues->contains($productAttributeValue)) {
$this->productAttributeValues->add($productAttributeValue);
$productAttributeValue->setShop($this);
}
return $this;
}
public function removeProductAttributeValue(ProductAttributeValue $productAttributeValue): static
{
if ($this->productAttributeValues->removeElement($productAttributeValue)) {
// set the owning side to null (unless already changed)
if ($productAttributeValue->getShop() === $this) {
$productAttributeValue->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Discount>
*/
public function getDiscounts(): Collection
{
return $this->discounts;
}
public function addDiscount(Discount $discount): static
{
if (!$this->discounts->contains($discount)) {
$this->discounts->add($discount);
$discount->setShop($this);
}
return $this;
}
public function removeDiscount(Discount $discount): static
{
if ($this->discounts->removeElement($discount)) {
// set the owning side to null (unless already changed)
if ($discount->getShop() === $this) {
$discount->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Cart>
*/
public function getCarts(): Collection
{
return $this->carts;
}
public function addCart(Cart $cart): static
{
if (!$this->carts->contains($cart)) {
$this->carts->add($cart);
$cart->setShop($this);
}
return $this;
}
public function removeCart(Cart $cart): static
{
if ($this->carts->removeElement($cart)) {
// set the owning side to null (unless already changed)
if ($cart->getShop() === $this) {
$cart->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, CartItem>
*/
public function getCartItems(): Collection
{
return $this->cartItems;
}
public function addCartItem(CartItem $cartItem): static
{
if (!$this->cartItems->contains($cartItem)) {
$this->cartItems->add($cartItem);
$cartItem->setShop($this);
}
return $this;
}
public function removeCartItem(CartItem $cartItem): static
{
if ($this->cartItems->removeElement($cartItem)) {
// set the owning side to null (unless already changed)
if ($cartItem->getShop() === $this) {
$cartItem->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, CartItemAttribute>
*/
public function getCartItemAttributes(): Collection
{
return $this->cartItemAttributes;
}
public function addCartItemAttribute(CartItemAttribute $cartItemAttribute): static
{
if (!$this->cartItemAttributes->contains($cartItemAttribute)) {
$this->cartItemAttributes->add($cartItemAttribute);
$cartItemAttribute->setShop($this);
}
return $this;
}
public function removeCartItemAttribute(CartItemAttribute $cartItemAttribute): static
{
if ($this->cartItemAttributes->removeElement($cartItemAttribute)) {
// set the owning side to null (unless already changed)
if ($cartItemAttribute->getShop() === $this) {
$cartItemAttribute->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Coupon>
*/
public function getCoupons(): Collection
{
return $this->coupons;
}
public function addCoupon(Coupon $coupon): static
{
if (!$this->coupons->contains($coupon)) {
$this->coupons->add($coupon);
$coupon->setShop($this);
}
return $this;
}
public function removeCoupon(Coupon $coupon): static
{
if ($this->coupons->removeElement($coupon)) {
// set the owning side to null (unless already changed)
if ($coupon->getShop() === $this) {
$coupon->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Order>
*/
public function getOrders(): Collection
{
return $this->orders;
}
public function addOrder(Order $order): static
{
if (!$this->orders->contains($order)) {
$this->orders->add($order);
$order->setShop($this);
}
return $this;
}
public function removeOrder(Order $order): static
{
if ($this->orders->removeElement($order)) {
// set the owning side to null (unless already changed)
if ($order->getShop() === $this) {
$order->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, ShippingMethod>
*/
public function getShippingMethods(): Collection
{
return $this->shippingMethods;
}
public function addShippingMethod(ShippingMethod $shippingMethod): static
{
if (!$this->shippingMethods->contains($shippingMethod)) {
$this->shippingMethods->add($shippingMethod);
$shippingMethod->setShop($this);
}
return $this;
}
public function removeShippingMethod(ShippingMethod $shippingMethod): static
{
if ($this->shippingMethods->removeElement($shippingMethod)) {
// set the owning side to null (unless already changed)
if ($shippingMethod->getShop() === $this) {
$shippingMethod->setShop(null);
}
}
return $this;
}
public function getTheme(): ?string
{
if ($this->theme == null){
return 'default';
}
return $this->theme;
}
public function setTheme(?string $theme): static
{
$this->theme = $theme;
return $this;
}
/**
* @return Collection<int, ProductCategory>
*/
public function getProductCategories(): Collection
{
return $this->productCategories;
}
public function addProductCategory(ProductCategory $productCategory): static
{
if (!$this->productCategories->contains($productCategory)) {
$this->productCategories->add($productCategory);
$productCategory->setShop($this);
}
return $this;
}
public function removeProductCategory(ProductCategory $productCategory): static
{
if ($this->productCategories->removeElement($productCategory)) {
// set the owning side to null (unless already changed)
if ($productCategory->getShop() === $this) {
$productCategory->setShop(null);
}
}
return $this;
}
public function getAnalyticsData(): ?array
{
return $this->analyticsData;
}
public function setAnalyticsData(?array $analyticsData): static
{
$this->analyticsData = $analyticsData;
return $this;
}
public function getExpiredAt(): ?\DateTimeImmutable
{
return $this->expiredAt;
}
public function setExpiredAt(?\DateTimeImmutable $expiredAt): static
{
$this->expiredAt = $expiredAt;
return $this;
}
/**
* @return Collection<int, PostType>
*/
public function getPostTypes(): Collection
{
return $this->postTypes;
}
public function addPostType(PostType $postType): static
{
if (!$this->postTypes->contains($postType)) {
$this->postTypes->add($postType);
$postType->setShop($this);
}
return $this;
}
public function removePostType(PostType $postType): static
{
if ($this->postTypes->removeElement($postType)) {
// set the owning side to null (unless already changed)
if ($postType->getShop() === $this) {
$postType->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Menu>
*/
public function getMenus(): Collection
{
return $this->menus;
}
public function addMenu(Menu $menu): static
{
if (!$this->menus->contains($menu)) {
$this->menus->add($menu);
$menu->setShop($this);
}
return $this;
}
public function removeMenu(Menu $menu): static
{
if ($this->menus->removeElement($menu)) {
// set the owning side to null (unless already changed)
if ($menu->getShop() === $this) {
$menu->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Setting>
*/
public function getSettings(): Collection
{
return $this->settings;
}
public function addSetting(Setting $setting): static
{
if (!$this->settings->contains($setting)) {
$this->settings->add($setting);
$setting->setShop($this);
}
return $this;
}
public function removeSetting(Setting $setting): static
{
if ($this->settings->removeElement($setting)) {
// set the owning side to null (unless already changed)
if ($setting->getShop() === $this) {
$setting->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Page>
*/
public function getPages(): Collection
{
return $this->pages;
}
public function addPage(Page $page): static
{
if (!$this->pages->contains($page)) {
$this->pages->add($page);
$page->setShop($this);
}
return $this;
}
public function removePage(Page $page): static
{
if ($this->pages->removeElement($page)) {
// set the owning side to null (unless already changed)
if ($page->getShop() === $this) {
$page->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Article>
*/
public function getArticles(): Collection
{
return $this->articles;
}
public function addArticle(Article $article): static
{
if (!$this->articles->contains($article)) {
$this->articles->add($article);
$article->setShop($this);
}
return $this;
}
public function removeArticle(Article $article): static
{
if ($this->articles->removeElement($article)) {
// set the owning side to null (unless already changed)
if ($article->getShop() === $this) {
$article->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Category>
*/
public function getCategories(): Collection
{
return $this->categories;
}
public function addCategory(Category $category): static
{
if (!$this->categories->contains($category)) {
$this->categories->add($category);
$category->setShop($this);
}
return $this;
}
public function removeCategory(Category $category): static
{
if ($this->categories->removeElement($category)) {
// set the owning side to null (unless already changed)
if ($category->getShop() === $this) {
$category->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Tag>
*/
public function getTags(): Collection
{
return $this->tags;
}
public function addTag(Tag $tag): static
{
if (!$this->tags->contains($tag)) {
$this->tags->add($tag);
$tag->setShop($this);
}
return $this;
}
public function removeTag(Tag $tag): static
{
if ($this->tags->removeElement($tag)) {
// set the owning side to null (unless already changed)
if ($tag->getShop() === $this) {
$tag->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Ticket>
*/
public function getTickets(): Collection
{
return $this->tickets;
}
public function addTicket(Ticket $ticket): static
{
if (!$this->tickets->contains($ticket)) {
$this->tickets->add($ticket);
$ticket->setShop($this);
}
return $this;
}
public function removeTicket(Ticket $ticket): static
{
if ($this->tickets->removeElement($ticket)) {
// set the owning side to null (unless already changed)
if ($ticket->getShop() === $this) {
$ticket->setShop(null);
}
}
return $this;
}
/**
* @return Collection<int, Transaction>
*/
public function getTransactions(): Collection
{
return $this->transactions;
}
public function addTransaction(Transaction $transaction): static
{
if (!$this->transactions->contains($transaction)) {
$this->transactions->add($transaction);
$transaction->setShop($this);
}
return $this;
}
public function removeTransaction(Transaction $transaction): static
{
if ($this->transactions->removeElement($transaction)) {
// set the owning side to null (unless already changed)
if ($transaction->getShop() === $this) {
$transaction->setShop(null);
}
}
return $this;
}
public function getTrafficUsage(): ?string
{
return $this->trafficUsage;
}
public function setTrafficUsage(string $trafficUsage): static
{
$this->trafficUsage = $trafficUsage;
return $this;
}
public function getCurrentPlanString()
{
if ($this->currentPlan){
return $this->currentPlan->getTitle();
}else{
return '';
}
}
/**
* @return Collection<int, Domain>
*/
public function getDomains(): Collection
{
return $this->domains;
}
public function addDomain(Domain $domain): static
{
if (!$this->domains->contains($domain)) {
$this->domains->add($domain);
$domain->setShop($this);
}
return $this;
}
public function removeDomain(Domain $domain): static
{
if ($this->domains->removeElement($domain)) {
// set the owning side to null (unless already changed)
if ($domain->getShop() === $this) {
$domain->setShop(null);
}
}
return $this;
}
public function getCurrentPlan(): ?Plan
{
return $this->currentPlan;
}
public function setCurrentPlan(?Plan $currentPlan): static
{
$this->currentPlan = $currentPlan;
return $this;
}
/**
* @return Collection<int, AddOn>
*/
public function getAddOns(): Collection
{
return $this->addOns;
}
public function addAddOn(AddOn $addOn): static
{
if (!$this->addOns->contains($addOn)) {
$this->addOns->add($addOn);
$addOn->setShop($this);
}
return $this;
}
public function removeAddOn(AddOn $addOn): static
{
if ($this->addOns->removeElement($addOn)) {
// set the owning side to null (unless already changed)
if ($addOn->getShop() === $this) {
$addOn->setShop(null);
}
}
return $this;
}
public function getPlanStartedAt(): ?\DateTimeInterface
{
return $this->planStartedAt;
}
public function setPlanStartedAt(?\DateTimeInterface $planStartedAt): static
{
$this->planStartedAt = $planStartedAt;
return $this;
}
}