src/Entity/Order/OrderItem.php line 21

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Entity\Order;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Mezcalito\SyliusFileUploadPlugin\Model\FileInterface;
  8. use Mezcalito\SyliusFileUploadPlugin\Model\FilesAwareTrait;
  9. use Sylius\Component\Core\Model\OrderItem as BaseOrderItem;
  10. use Mezcalito\SyliusFileUploadPlugin\Model\FilesAwareInterface;
  11. use Symfony\Component\HttpFoundation\File\UploadedFile;
  12. /**
  13.  * @ORM\Entity
  14.  * @ORM\Table(name="sylius_order_item")
  15.  */
  16. class OrderItem extends BaseOrderItem implements OrderItemInterfaceFilesAwareInterface
  17. {
  18.     use FilesAwareTrait {
  19.         FilesAwareTrait::__construct as private initializeFilesCollection;
  20.     }
  21.     /**
  22.      * @ORM\Column(name="is_gift", type="boolean")
  23.      */
  24.     private $gift false;
  25.     /**
  26.      * @ORM\Column(name="note", type="text", nullable=true)
  27.      */
  28.     private $note;
  29.     /**
  30.      * @ORM\OneToMany(targetEntity="App\Entity\Order\OrderItemFileInterface", mappedBy="owner", orphanRemoval=true, cascade={"all"})
  31.      * @var Collection|FileInterface[]
  32.      */
  33.     protected $files;
  34.     /**
  35.      * @var ArrayCollection|UploadedFile[]
  36.      */
  37.     private $filesUploaded;
  38.     public function __construct()
  39.     {
  40.         parent::__construct();
  41.         $this->initializeFilesCollection();
  42.         $this->filesUploaded = new ArrayCollection();
  43.     }
  44.     public function isGift(): bool
  45.     {
  46.         return $this->gift;
  47.     }
  48.     public function setGift(bool $gift): void
  49.     {
  50.         $this->gift $gift;
  51.     }
  52.     public function getNote(): ?string
  53.     {
  54.         return $this->note;
  55.     }
  56.     public function setNote(?string $note): void
  57.     {
  58.         $this->note $note;
  59.     }
  60.     public function getFilesUploaded()
  61.     {
  62.         return $this->filesUploaded;
  63.     }
  64.     public function setFilesUploaded($filesUploaded): void
  65.     {
  66.         $this->filesUploaded $filesUploaded;
  67.     }
  68.     public function removeFileUploaded(UploadedFile $uploadedFile): void
  69.     {
  70.         $this->filesUploaded->removeElement($uploadedFile);
  71.     }
  72.     public function setQuantity(?int $quantity): void
  73.     {
  74.         $this->quantity $quantity;
  75.         $this->recalculateUnitsTotal();
  76.     }
  77.     public function recalculateUnitsTotal(): void
  78.     {
  79.         $total $this->quantity $this->unitPrice;
  80.         $variant $this->getVariant();
  81.         $product $variant->getProduct();
  82.         $brand $product->getBrand();
  83.         $setupDefault $variant->getOptionValueByCode('setup-charge-1');
  84.         $typeOptionValue $variant->getOptionValueByOptionCode('type');
  85.         if ($brand && $brand->getSetupDefault() && $setupDefault) {
  86.             $total += ($brand->getSetupDefault() * 100000);
  87.         }
  88.         if ($brand && $brand->getPlatePerColor() && $variant->getOptionValueByCode('new-matrix') && $typeOptionValue) {
  89.             $colors = ['1-color' => 1'2-color' => 2'3-color' => 3'4-color' => 4'5-color' => 5'6-color' => 6'7-color' => 7'8-color' => 8];
  90.             $total += ($brand->getPlatePerColor() * $colors[$typeOptionValue->getCode()] * 100000);
  91.         } else if ($brand && $brand->getPlateDefault() && $variant->getOptionValueByCode('new-matrix')) {
  92.             $total += ($brand->getPlateDefault() * 100000);
  93.         }
  94.         $this->unitsTotal $total;
  95.         $this->recalculateTotal();
  96.     }
  97. }