|
- <?php
-
- namespace Lc\ShopBundle\Model;
-
- use Doctrine\ORM\Mapping as ORM;
- use Lc\ShopBundle\Context\PriceInterface;
- use Lc\ShopBundle\Context\ProductPropertyInterface;
- use Lc\ShopBundle\Context\SortableInterface;
- use Lc\ShopBundle\Services\Price;
-
- /**
- * @ORM\MappedSuperclass()
- */
- abstract class Product extends AbstractEntity implements SortableInterface, ProductPropertyInterface, PriceInterface
- {
- use SortableTrait;
- use ProductPropertyTrait;
-
- /**
- * @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", inversedBy="products")
- * @ORM\JoinColumn(nullable=false)
- */
- protected $productFamily;
-
- /**
- * @ORM\Column(type="string", length=255, nullable=true)
- */
- protected $title;
-
- public function getPriceInherited()
- {
- if($this->price) {
- return $this->price;
- }
- else {
- return $this->productFamily->getPrice();
- }
- }
-
- public function getUnitInherited()
- {
- if($this->unit) {
- return $this->unit;
- }
- else{
- return $this->productFamily->getUnit();
- }
- }
-
- public function getTitleInherited()
- {
- if($this->title){
- return $this->title;
- }
- else{
- return $this->productFamily->getTitle();
- }
- }
-
- public function getQuantityInherited()
- {
- if($this->quantity) {
- return $this->quantity;
- }
- else{
- return $this->productFamily->getQuantity();
- }
- }
-
- public function getQuantityLabelInherited()
- {
- $quantity = $this->getQuantityInherited() ;
- $unit = $this->getUnitInherited() ;
- return $quantity.$unit->getWordingShort() ;
- }
-
- public function getAvailableQuantityInherited()
- {
- if($this->productFamily->getBehaviorCountStock()) {
- return $this->availableQuantity;
- }
- else{
- return $this->productFamily->getAvailableQuantity();
- }
- }
-
- public function getTaxRateInherited()
- {
- if($this->productFamily->getTaxRate()) {
- return $this->productFamily->getTaxRate();
- }
- else{
- return $this->productFamily->getMerchant()->getTaxRate()->getValue();
- }
- }
-
- public function getProductFamily(): ?ProductFamily
- {
- return $this->productFamily;
- }
-
- public function setProductFamily(?ProductFamily $productFamily): self
- {
- $this->productFamily = $productFamily;
-
- return $this;
- }
-
- public function getTitle(): ?string
- {
- return $this->title;
- }
-
- public function setTitle(?string $title): self
- {
- $this->title = $title;
-
- return $this;
- }
- }
|