src/Flexy/ShopBundle/Entity/Shipping/ShippingRule.php line 17

  1. <?php
  2. namespace App\Flexy\ShopBundle\Entity\Shipping;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Flexy\ShopBundle\Repository\Shipping\ShippingRuleRepository;
  5. use App\Flexy\ShopBundle\Validator\UniqueShippingRule;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ApiResource]
  8. #[ORM\Entity(repositoryClassShippingRuleRepository::class)]
  9. #[UniqueShippingRule(
  10.     shippingMethodProperty"shippingMethod",
  11.     factorTypeProperty"factorType",
  12.     message"Shipping rule with these values already exists."
  13. )]
  14. class ShippingRule implements \Stringable
  15. {
  16.     #[ORM\Id]
  17.     #[ORM\GeneratedValue]
  18.     #[ORM\Column(type'integer')]
  19.     private $id;
  20.     #[ORM\Column(type'string'length255)]
  21.     private string $name "";
  22.     /**
  23.      *
  24.      * @example The minimum value depend on the typeCalculation and valueCalculation 
  25.      */
  26.     #[ORM\Column(type'float')]
  27.     private ?float $min null;
  28.     /**
  29.      *
  30.      * @example The maximum value depend on the typeCalculation and valueCalculation 
  31.      */
  32.     #[ORM\Column(type'float')]
  33.     private ?float $max null;
  34.     #[ORM\Column(type'integer'nullabletrue)]
  35.     private ?int $priority null;
  36.     #[ORM\ManyToOne(targetEntityShippingMethod::class, inversedBy'shippingRules')]
  37.     private ?\App\Flexy\ShopBundle\Entity\Shipping\ShippingMethod $shippingMethod null;
  38.     /**
  39.      *
  40.      * @example [amount|percent|amount-per-unit]
  41.      */
  42.     #[ORM\Column(type'string'length255)]
  43.     private ?string $typeCalculation null;
  44.     /**
  45.      *
  46.      * @example The related value to the type of calculation
  47.      */
  48.     #[ORM\Column(type'float')]
  49.     private ?float $valueCalculation null;
  50.     /**
  51.      *
  52.      * @example [price|distance|volume|weight|dimension] The factor calculated for this rule
  53.      */
  54.     #[ORM\Column(length255nullabletrue)]
  55.     private ?string $factorType "price";
  56.     /**
  57.      *
  58.      * @example [add|substract|replace] the method of calculation applied
  59.      */
  60.     #[ORM\Column(length255nullabletrue)]
  61.     private ?string $adjustmentType "replace";
  62.     public function __toString(): string
  63.     {
  64.         return $this->factorType" -" .$this->typeCalculation." : ".$this->valueCalculation.", (Min ".$this->min.") (Max ".$this->max.")";
  65.     }
  66.     public function __construct()
  67.     {
  68.     }
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function getName(): ?string
  74.     {
  75.         return $this->name;
  76.     }
  77.     public function setName(string $name): self
  78.     {
  79.         $this->name $name;
  80.         return $this;
  81.     }
  82.     public function getMin(): ?float
  83.     {
  84.         return $this->min;
  85.     }
  86.     public function setMin(float $min): self
  87.     {
  88.         $this->min $min;
  89.         return $this;
  90.     }
  91.     public function getMax(): ?float
  92.     {
  93.         return $this->max;
  94.     }
  95.     public function setMax(float $max): self
  96.     {
  97.         $this->max $max;
  98.         return $this;
  99.     }
  100.     public function getPriority(): ?int
  101.     {
  102.         return $this->priority;
  103.     }
  104.     public function setPriority(int $priority): self
  105.     {
  106.         $this->priority $priority;
  107.         return $this;
  108.     }
  109.     public function getShippingMethod(): ?ShippingMethod
  110.     {
  111.         return $this->shippingMethod;
  112.     }
  113.     public function setShippingMethod(?ShippingMethod $shippingMethod): self
  114.     {
  115.         $this->shippingMethod $shippingMethod;
  116.         return $this;
  117.     }
  118.     public function getTypeCalculation(): ?string
  119.     {
  120.         return $this->typeCalculation;
  121.     }
  122.     public function setTypeCalculation(string $typeCalculation): self
  123.     {
  124.         $this->typeCalculation $typeCalculation;
  125.         return $this;
  126.     }
  127.     public function getValueCalculation(): ?float
  128.     {
  129.         return $this->valueCalculation;
  130.     }
  131.     public function setValueCalculation(float $valueCalculation): self
  132.     {
  133.         $this->valueCalculation $valueCalculation;
  134.         return $this;
  135.     }
  136.     public function getFactorType(): ?string
  137.     {
  138.         return $this->factorType;
  139.     }
  140.     public function setFactorType(?string $factorType): self
  141.     {
  142.         $this->factorType $factorType;
  143.         return $this;
  144.     }
  145.     public function getAdjustmentType(): ?string
  146.     {
  147.         return $this->adjustmentType;
  148.     }
  149.     public function setAdjustmentType(?string $adjustmentType): self
  150.     {
  151.         $this->adjustmentType $adjustmentType;
  152.         return $this;
  153.     }
  154. }