ソースを参照

Merge branch 'develop'

master
Fabien Normand 2年前
コミット
fffd08ed51
7個のファイルの変更146行の追加90行の削除
  1. +64
    -0
      Controller/AbstractAdminController.php
  2. +1
    -0
      Definition/Field/Product/ProductCategoryFieldDefinition.php
  3. +0
    -19
      Model/User/UserModel.php
  4. +68
    -68
      Repository/Product/ProductFamilyStore.php
  5. +2
    -1
      Resolver/MerchantResolver.php
  6. +1
    -1
      Resolver/OpeningResolver.php
  7. +10
    -1
      Solver/Order/OrderShopSolver.php

+ 64
- 0
Controller/AbstractAdminController.php ファイルの表示

@@ -2,9 +2,73 @@

namespace Lc\CaracoleBundle\Controller;

use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
use EasyCorp\Bundle\EasyAdminBundle\Config\Option\EA;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Controller\CrudControllerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\FieldDto;
use EasyCorp\Bundle\EasyAdminBundle\Factory\ControllerFactory;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Controller\AbstractAdminController as SovAbstractAdminController;
use Lc\SovBundle\Definition\ActionDefinition;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Field\Filter\FilterManager;
use Lc\SovBundle\Repository\EntityRepository;
use Symfony\Component\HttpFoundation\JsonResponse;

abstract class AbstractAdminController extends SovAbstractAdminController
{
use AdminControllerTrait;

public function autocompleteFilter(AdminContext $context): JsonResponse
{
$repositoryQuery = $this->get(EntityRepository::class)->createRepositoryQuery(
$this->getRepositoryQuery(),
$context->getSearch(),
$context->getEntity(),
FieldCollection::new([]),
FilterCollection::new()
);

if ($this->isInstanceOf(StatusInterface::class)) {
$repositoryQuery->filterIsOnlineAndOffline();
}
if ($this->isInstanceOf(FilterSectionInterface::class)) {
$repositoryQuery->filterBySection($this->getSectionCurrent());
}

if ($this->isInstanceOf(FilterMerchantInterface::class)) {
$repositoryQuery->filterByMerchant($this->getMerchantCurrent());
}

$autocompleteContext = $context->getRequest()->get(AssociationField::PARAM_AUTOCOMPLETE_CONTEXT);

/** @var CrudControllerInterface $controller */
$controller = $this->get(ControllerFactory::class)->getCrudControllerInstance(
$autocompleteContext[EA::CRUD_CONTROLLER_FQCN],
ActionDefinition::INDEX,
$context->getRequest()
);
/** @var FieldDto $field */
$field = FieldCollection::new(
$controller->configureFields($autocompleteContext['originatingPage'])
)->getByProperty($autocompleteContext['propertyName']);

$filterManager = $this->get(FilterManager::class);
$filteredValue = ['value' => $context->getRequest()->query->get('q')];
$filterManager->applyFilter($repositoryQuery, $field, $filteredValue);
$repositoryQuery->select('.' . $autocompleteContext['propertyName']);
//dump($repositoryQuery->getQueryBuilder()->getQuery()->getDQL());

$responses = array();
foreach ($repositoryQuery->find() as $result) {
$responses[] = array_values($result)[0];
}

return JsonResponse::fromJsonString(json_encode($responses));
}
}

+ 1
- 0
Definition/Field/Product/ProductCategoryFieldDefinition.php ファイルの表示

@@ -49,6 +49,7 @@ class ProductCategoryFieldDefinition extends AbstractFieldDefinition
return [
'main',
'seo',
'opengraph',
'conf'
];
}

+ 0
- 19
Model/User/UserModel.php ファイルの表示

@@ -29,17 +29,11 @@ abstract class UserModel extends SovUserModel
*/
protected $isSaleAlwaysOpen;


/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
*/
protected $favoriteMerchant;

/**
* @ORM\Column(type="datetime", nullable=true)
*/
protected $lastLogin;

/**
* @ORM\OneToMany(targetEntity="Lc\CaracoleBundle\Model\Address\AddressInterface", mappedBy="user", cascade={"persist"})
*/
@@ -124,19 +118,6 @@ abstract class UserModel extends SovUserModel
return $this;
}

public function getLastLogin()
{
return $this->lastLogin;
}

public function setLastLogin(\DateTime $time = null)
{
$this->lastLogin = $time;

return $this;
}


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

+ 68
- 68
Repository/Product/ProductFamilyStore.php ファイルの表示

@@ -51,48 +51,51 @@ class ProductFamilyStore extends AbstractStore
}

public function getByParentCategory(
ProductCategoryInterface $parentCategory,
$user = null,
$query = null
)
{
ProductCategoryInterface $parentCategory,
$user = null,
$query = null
) {
$productFamiliesArray = [];

foreach ($parentCategory->getChildrens() as $i => $category) {
$productFamiliesCategory = $this->getByCategory($category, $query);
$productFamiliesCategory = $this->getByCategory($category);
foreach ($productFamiliesCategory as $productFamily) {
$productFamiliesArray[$productFamily->getId()] = $productFamily;
}
uasort($productFamiliesArray, array($this, 'compMethodSortProductFamiliesByPosition'));
}

return $this->getWithReductions($productFamiliesArray, $user, true);
}

private function compMethodSortProductFamiliesByPosition($a, $b)
{
return $a->getPosition() > $b->getPosition();
}

// getProductFamiliesByCategory
public function getByCategory(
ProductCategoryInterface $productCategory,
$query = null
)
{
ProductCategoryInterface $productCategory,
$query = null
) {
$query = $this->createDefaultQuery($query);

$query
->filterIsOnline()
->filterByProductCategory($productCategory);
->filterIsOnline()
->filterByProductCategory($productCategory);

return $query->find();
}

//TODO ajouter status en donné de contexte pour éviter ce truc
public function getByCategoryOnlineAndOffline(
ProductCategoryInterface $productCategory,
$query = null
)
{
ProductCategoryInterface $productCategory,
$query = null
) {
$query = $this->createDefaultQuery($query);

$query
->filterByProductCategory($productCategory);
->filterByProductCategory($productCategory);

return $query->find();
}
@@ -103,8 +106,8 @@ class ProductFamilyStore extends AbstractStore
$query = $this->createDefaultQuery($query);

$query
->filterByPropertyNoveltyExpirationDate()
->filterIsOnline();
->filterByPropertyNoveltyExpirationDate()
->filterIsOnline();

$results = $query->find();

@@ -117,8 +120,8 @@ class ProductFamilyStore extends AbstractStore
$query = $this->createDefaultQuery($query);

$query
->filterIsOrganicLabel()
->filterIsOnline();
->filterIsOrganicLabel()
->filterIsOnline();

$results = $query->find();

@@ -136,10 +139,10 @@ class ProductFamilyStore extends AbstractStore
{
if ($user) {
return $this->getWithReductions(
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
$user->getFavoriteProductFamilies(),
$user,
false,
$organizeByParentCategory
);
}

@@ -149,13 +152,12 @@ class ProductFamilyStore extends AbstractStore

// findByTerms
public function getByTerms(
$terms,
$maxResults = false,
$organizeByParentCategory = false,
$user = null,
$query = null
)
{
$terms,
$maxResults = false,
$organizeByParentCategory = false,
$user = null,
$query = null
) {
$query = $this->createDefaultQuery($query);

$query->filterIsOnline();
@@ -173,18 +175,17 @@ class ProductFamilyStore extends AbstractStore
}

public function getBestReductionCatalog(
ProductFamilyInterface $productFamily,
ReductionCatalogInterface $reductionCatalog1,
ReductionCatalogInterface $reductionCatalog2
)
{
ProductFamilyInterface $productFamily,
ReductionCatalogInterface $reductionCatalog1,
ReductionCatalogInterface $reductionCatalog2
) {
$price1 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog1
$productFamily,
$reductionCatalog1
);
$price2 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog2
$productFamily,
$reductionCatalog2
);


@@ -197,32 +198,31 @@ class ProductFamilyStore extends AbstractStore

// setReductionForProductFamilies
public function getWithReductions(
$productFamilies,
UserInterface $user = null,
$organizeByCategory = false,
$organizeByParentCategory = false,
$onlyOnDiscount = false
)
{
$productFamilies,
UserInterface $user = null,
$organizeByCategory = false,
$organizeByParentCategory = false,
$onlyOnDiscount = false
) {
$conditions = [
'productFamiliesIds' => [],
'categories' => [],
'productFamilies' => [],
'productFamiliesIds' => [],
'categories' => [],
'productFamilies' => [],
];

foreach ($productFamilies as $productFamily) {
$conditions['productFamiliesIds'][] = $productFamily->getId();
$conditions['productFamilies'][] = $productFamily;
$conditions['categories'] = array_merge(
$conditions['categories'],
$productFamily->getProductCategories()->toArray()
$conditions['categories'],
$productFamily->getProductCategories()->toArray()
);
}

if ($productFamilies) {
$reductionCatalogs = $this->reductionCatalogStore->getByProductFamiliesConditions(
$conditions,
$user
$conditions,
$user
);
}

@@ -232,19 +232,20 @@ class ProductFamilyStore extends AbstractStore
$conditionProductFamilies = $conditionProductFamily = $conditionProductCategory = false;

if ($reductionCatalog->getProductFamilies()->contains(
$productFamily
) || $reductionCatalog->getProductFamilies()->isEmpty()) {
$productFamily
) || $reductionCatalog->getProductFamilies()->isEmpty()) {
$conditionProductFamilies = true;
}

if ($reductionCatalog->getProductFamily() == $productFamily || $reductionCatalog->getProductFamily() === null) {
if ($reductionCatalog->getProductFamily() == $productFamily || $reductionCatalog->getProductFamily(
) === null) {
$conditionProductFamily = true;
}

foreach ($productFamily->getProductCategories() as $productCategory) {
if ($reductionCatalog->getProductCategories()->contains(
$productCategory
) || $reductionCatalog->getProductCategories()->isEmpty()) {
$productCategory
) || $reductionCatalog->getProductCategories()->isEmpty()) {
$conditionProductCategory = true;
}
}
@@ -252,11 +253,11 @@ class ProductFamilyStore extends AbstractStore
if ($conditionProductFamilies && $conditionProductFamily && $conditionProductCategory) {
if ($productFamily->getReductionCatalog()) {
$productFamily->setReductionCatalog(
$this->getBestReductionCatalog(
$productFamily,
$reductionCatalog,
$productFamily->getReductionCatalog()
)
$this->getBestReductionCatalog(
$productFamily,
$reductionCatalog,
$productFamily->getReductionCatalog()
)
);
} else {
$productFamily->setReductionCatalog($reductionCatalog);
@@ -266,7 +267,6 @@ class ProductFamilyStore extends AbstractStore

if (($onlyOnDiscount && $productFamily->getReductionCatalog()) || !$onlyOnDiscount) {
if ($organizeByParentCategory) {

$productCategories = $productFamily->getProductCategories();

if ($productCategories && count($productCategories) > 0) {
@@ -274,8 +274,8 @@ class ProductFamilyStore extends AbstractStore
if ($this->productCategorySolver->isDisplay($parentCategory, $user)) {
if (!isset($productFamiliesToReturn[$parentCategory->getId()])) {
$productFamiliesToReturn[$parentCategory->getId()] = [
'category' => $parentCategory,
'products' => []
'category' => $parentCategory,
'products' => []
];
}
$productFamiliesToReturn[$parentCategory->getId()]['products'][] = $productFamily;

+ 2
- 1
Resolver/MerchantResolver.php ファイルの表示

@@ -20,6 +20,7 @@ use Lc\SovBundle\Resolver\UrlResolver;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Component\Security\Core\Security;

@@ -83,7 +84,7 @@ class MerchantResolver
return $this->currentMerchant;
}
else {
throw new \ErrorException('Aucun merchant courant');
throw new NotFoundHttpException('Aucun marchand n\'est défini');
}
}


+ 1
- 1
Resolver/OpeningResolver.php ファイルの表示

@@ -306,7 +306,7 @@ class OpeningResolver

$dateOpeningNextSale = $this->getFormatedDateOpeningNextSale($section);
if ($dateOpeningNextSale && strlen($dateOpeningNextSale) > 0) {
return 'Réouverture aux commandes le <u>'.$dateOpeningNextSale.'</u>' ;
return 'Réouverture aux commandes le <span class="underline">'.$dateOpeningNextSale.'</span>' ;
}

return null;

+ 10
- 1
Solver/Order/OrderShopSolver.php ファイルの表示

@@ -302,7 +302,16 @@ class OrderShopSolver

return $orderShop;
}

public function refreshOrderShops(array $orderShops): array
{
foreach ($orderShops as $orderShop) {
foreach ($orderShop->getOrderProducts() as $orderProduct) {
$this->entityManager->refresh($orderProduct);
}
$this->entityManager->refresh($orderShop);
}
return $orderShops;
}
public function isReductionCreditAddedToOrder(
OrderShopInterface $orderShop,
ReductionCreditInterface $reductionCredit

読み込み中…
キャンセル
保存