use Lc\CaracoleBundle\Model\File\DocumentInterface; | use Lc\CaracoleBundle\Model\File\DocumentInterface; | ||||
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | use Lc\CaracoleBundle\Model\Order\OrderShopInterface; | ||||
use Lc\CaracoleBundle\Generator\Reference\DocumentReferenceGenerator; | |||||
use Lc\CaracoleBundle\Generator\DocumentReferenceGenerator; | |||||
class DocumentBuilder | class DocumentBuilder | ||||
{ | { |
public function initSettingsGeneric($type, $settings, $entities, $factory) | public function initSettingsGeneric($type, $settings, $entities, $factory) | ||||
{ | { | ||||
foreach ($entities as $entity) { | |||||
foreach ($settings as $category => $settingList) { | |||||
foreach ($settingList as $settingName => $setting) { | |||||
$entitySetting = $entity->getSetting($settingName); | |||||
if (!$entitySetting) { | |||||
// gestion du cas des SectionSetting spécifiques à une section | |||||
$createEntitySetting = true; | |||||
if ($entity instanceof SectionInterface && isset($setting['section']) && $setting['section'] != $entity) { | |||||
$createEntitySetting = false; | |||||
} | |||||
if($entities) { | |||||
foreach ($entities as $entity) { | |||||
foreach ($settings as $category => $settingList) { | |||||
foreach ($settingList as $settingName => $setting) { | |||||
$entitySetting = $entity->getSetting($settingName); | |||||
if (!$entitySetting) { | |||||
// gestion du cas des SectionSetting spécifiques à une section | |||||
$createEntitySetting = true; | |||||
if ($entity instanceof SectionInterface && isset($setting['section']) && $setting['section'] != $entity) { | |||||
$createEntitySetting = false; | |||||
} | |||||
if ($createEntitySetting) { | |||||
$text = null; | |||||
$date = null; | |||||
$file = null; | |||||
if ($createEntitySetting) { | |||||
$text = null; | |||||
$date = null; | |||||
$file = null; | |||||
$fieldValue = isset($setting['default']) ? $setting['default'] : null; | |||||
$fieldValue = isset($setting['default']) ? $setting['default'] : null; | |||||
if ($setting['field'] == 'text') { | |||||
$text = $fieldValue; | |||||
} elseif ($setting['field'] == 'date') { | |||||
$date = $fieldValue; | |||||
} elseif ($setting['field'] == 'file') { | |||||
$file = $fieldValue; | |||||
} | |||||
if ($setting['field'] == 'text') { | |||||
$text = $fieldValue; | |||||
} elseif ($setting['field'] == 'date') { | |||||
$date = $fieldValue; | |||||
} elseif ($setting['field'] == 'file') { | |||||
$file = $fieldValue; | |||||
} | |||||
$entitySetting = $factory->create($entity, $setting['name'], $text, $date, $file); | |||||
$entitySetting = $factory->create($entity, $setting['name'], $text, $date, $file); | |||||
$this->entityManager->persist($entitySetting); | |||||
} | |||||
} else { | |||||
if ($this->settingSolver->getValue($entitySetting) === null | |||||
&& isset($setting['default']) | |||||
&& $setting['default'] !== null) { | |||||
$methodSetValue = 'set' . ucfirst($setting['field']); | |||||
$entitySetting->$methodSetValue($setting['default']); | |||||
$this->entityManager->update($entitySetting); | |||||
$this->entityManager->persist($entitySetting); | |||||
} | |||||
} else { | |||||
if ($this->settingSolver->getValue($entitySetting) === null | |||||
&& isset($setting['default']) | |||||
&& $setting['default'] !== null) { | |||||
$methodSetValue = 'set' . ucfirst($setting['field']); | |||||
$entitySetting->$methodSetValue($setting['default']); | |||||
$this->entityManager->update($entitySetting); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
$this->entityManager->flush(); | |||||
$this->entityManager->flush(); | |||||
} | |||||
} | } | ||||
} | } |
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Lc\CaracoleBundle\Model\Address\AddressInterface; | use Lc\CaracoleBundle\Model\Address\AddressInterface; | ||||
use Lc\CaracoleBundle\Model\Config\TaxRateInterface; | use Lc\CaracoleBundle\Model\Config\TaxRateInterface; | ||||
use Lc\CaracoleBundle\Model\Section\SectionInterface; | |||||
use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | use Lc\SovBundle\Model\Newsletter\NewsletterInterface; | ||||
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface; | ||||
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; | use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface; | ||||
*/ | */ | ||||
protected $settings; | protected $settings; | ||||
/** | |||||
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface", mappedBy="merchant") | |||||
*/ | |||||
protected $sections; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->pointSales = new ArrayCollection(); | $this->pointSales = new ArrayCollection(); | ||||
$this->groupUsers = new ArrayCollection(); | $this->groupUsers = new ArrayCollection(); | ||||
$this->settings = new ArrayCollection(); | |||||
} | } | ||||
public function __toString() | public function __toString() | ||||
/** | /** | ||||
* @return Collection|MerchantSettingInterface[] | * @return Collection|MerchantSettingInterface[] | ||||
*/ | */ | ||||
public function getSettings(): Collection | |||||
public function getSettings(): ?Collection | |||||
{ | { | ||||
return $this->settings; | return $this->settings; | ||||
} | } | ||||
return $this; | return $this; | ||||
} | } | ||||
/** | |||||
* @return Collection|SectionInterface[] | |||||
*/ | |||||
public function getSections(): ?Collection | |||||
{ | |||||
return $this->sections; | |||||
} | |||||
public function addSection(SectionInterface $section): self | |||||
{ | |||||
if (!$this->sections->contains($section)) { | |||||
$this->sections[] = $section; | |||||
$section->setMerchant($this); | |||||
} | |||||
return $this; | |||||
} | |||||
public function removeSection(SectionInterface $section): self | |||||
{ | |||||
if ($this->sections->contains($section)) { | |||||
$this->sections->removeElement($section); | |||||
// set the owning side to null (unless already changed) | |||||
if ($section->getMerchant() === $this) { | |||||
$section->setMerchant(null); | |||||
} | |||||
} | |||||
return $this; | |||||
} | |||||
} | } |
protected $section; | protected $section; | ||||
/** | /** | ||||
* @ORM\ManyToOne((targetEntity="Lc\SovBundle\Model\File\FileInterface", cascade={"persist", "remove"}) | |||||
* @ORM\ManyToOne(targetEntity="Lc\SovBundle\Model\File\FileInterface", cascade={"persist", "remove"}) | |||||
*/ | */ | ||||
protected $image; | protected $image; | ||||
use EntitySettingTrait; | use EntitySettingTrait; | ||||
/** | /** | ||||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface") | |||||
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="sections") | |||||
* @ORM\JoinColumn(nullable=false) | * @ORM\JoinColumn(nullable=false) | ||||
*/ | */ | ||||
protected $merchant; | protected $merchant; |
$this->joinProductFamilies(); | $this->joinProductFamilies(); | ||||
$this->joinProductFamily(); | $this->joinProductFamily(); | ||||
return $this | return $this | ||||
->andWhere(':productFamily MEMBER OF e.productFamilies OR e.productFamilies is empty') | |||||
->setParameter('productFamily', $productFamilies); | |||||
->andWhere(':productFamilies MEMBER OF e.productFamilies OR e.productFamilies is empty') | |||||
->setParameter('productFamilies', $productFamilies); | |||||
} | } | ||||
public function filterConditionProductFamily(ProductFamilyInterface $productFamily) | public function filterConditionProductFamily(ProductFamilyInterface $productFamily) |