Преглед на файлове

debut declinaison

reduction
Fab преди 4 години
родител
ревизия
11cca1822a
променени са 4 файла, в които са добавени 77 реда и са изтрити 8 реда
  1. +7
    -0
      ShopBundle/Controller/Admin/AdminController.php
  2. +13
    -7
      ShopBundle/Form/ProductType.php
  3. +18
    -1
      ShopBundle/Model/Product.php
  4. +39
    -0
      ShopBundle/Model/ProductFamily.php

+ 7
- 0
ShopBundle/Controller/Admin/AdminController.php Целия файл

@@ -377,6 +377,13 @@ class AdminController extends EasyAdminController
)
);

$formBuilder->add('products', CollectionType::class, array(
'entry_type'=> ProductType::class,
'allow_add'=>true,
'prototype'=> true
)
);

return $formBuilder;
}


+ 13
- 7
ShopBundle/Form/ProductType.php Целия файл

@@ -3,8 +3,10 @@
namespace Lc\ShopBundle\Form;

use CKSource\Bundle\CKFinderBundle\Form\Type\CKFinderFileChooserType;
use Doctrine\ORM\EntityManagerInterface;
use FOS\CKEditorBundle\Form\Type\CKEditorType;
use Lc\ShopBundle\Context\ProductFamilyInterface;
use Lc\ShopBundle\Context\ProductInterface;
use Lc\ShopBundle\Context\TaxRateInterface;
use function PHPSTORM_META\type;
use Symfony\Component\Form\AbstractType;
@@ -13,22 +15,26 @@ use Symfony\Component\OptionsResolver\OptionsResolver;

class ProductType extends AbstractType
{
protected $em;

public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('title')
->add('image', CKFinderFileChooserType::class, array(
'block_name' => 'ckfinder_file_chooser_widget'
))
->add('description', CKEditorType::class)
->add('supplier')
->add('productCategories');
->add('step')
->add('weight')
->add('step')
->add('price');
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => ProductFamilyInterface::class,
'data_class' => $this->em->getClassMetadata(ProductInterface::class)->getName(),
]);
}
}

+ 18
- 1
ShopBundle/Model/Product.php Целия файл

@@ -7,7 +7,7 @@ use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\MappedSuperclass()
*/
abstract class Product extends AbstractDocumentEntity
abstract class Product extends AbstractEntity
{
/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\ProductFamilyInterface", inversedBy="products")
@@ -15,6 +15,11 @@ abstract class Product extends AbstractDocumentEntity
*/
protected $productFamily;

/**
* @ORM\Column(type="string", length=255)
*/
protected $title;

/**
* @ORM\Column(type="float", nullable=true)
*/
@@ -129,4 +134,16 @@ abstract class Product extends AbstractDocumentEntity

return $this;
}

public function getTitle(): ?string
{
return $this->title;
}

public function setTitle(string $title): self
{
$this->title = $title;

return $this;
}
}

+ 39
- 0
ShopBundle/Model/ProductFamily.php Целия файл

@@ -5,6 +5,7 @@ namespace Lc\ShopBundle\Model;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\ShopBundle\Context\ProductInterface;

/**
* @ORM\MappedSuperclass()
@@ -22,6 +23,12 @@ abstract class ProductFamily extends AbstractDocumentEntity
*/
protected $productCategories;

/**
* @ORM\OneToMany(targetEntity="App\Entity\Product", mappedBy="productFamily", orphanRemoval=true)
*/
private $products;


/**
* @ORM\ManyToOne(targetEntity="Lc\ShopBundle\Context\TaxRateInterface")
* @ORM\JoinColumn(nullable=true)
@@ -71,6 +78,7 @@ abstract class ProductFamily extends AbstractDocumentEntity
public function __construct()
{
$this->productCategories = new ArrayCollection();
$this->products = new ArrayCollection();
}

public function getMerchant(): ?Merchant
@@ -85,6 +93,37 @@ abstract class ProductFamily extends AbstractDocumentEntity
return $this;
}

/**
* @return Collection|ProductInterface[]
*/
public function getProducts(): Collection
{
return $this->products;
}

public function addProduct(ProductInterface $product): self
{
if (!$this->products->contains($product)) {
$this->products[] = $product;
$product->setProductFamily($this);
}

return $this;
}

public function removeProduct(ProductInterface $product): self
{
if ($this->products->contains($product)) {
$this->products->removeElement($product);
// set the owning side to null (unless already changed)
if ($product->getProductFamily() === $this) {
$product->setProductFamily(null);
}
}

return $this;
}

/**
* @return Collection|ProductCategory[]
*/

Loading…
Отказ
Запис