Explorar el Código

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Guillaume hace 2 años
padre
commit
9cee32f98c
Se han modificado 11 ficheros con 159 adiciones y 127 borrados
  1. +8
    -10
      Controller/Merchant/FavoriteMerchantAdminController.php
  2. +8
    -9
      Controller/Merchant/FavoriteMerchantController.php
  3. +18
    -6
      Controller/Merchant/SwitchMerchantController.php
  4. +2
    -0
      Definition/ActionDefinition.php
  5. +2
    -1
      Repository/Product/ProductFamilyRepositoryQuery.php
  6. +68
    -67
      Repository/Product/ProductFamilyStore.php
  7. +31
    -27
      Repository/Reduction/ReductionCatalogRepositoryQuery.php
  8. +6
    -1
      Resources/translations/admin.fr.yaml
  9. +1
    -1
      Resources/views/adminlte/layout.html.twig
  10. +13
    -0
      Solver/Price/ProductPriceSolver.php
  11. +2
    -5
      Twig/FormTwigExtension.php

+ 8
- 10
Controller/Merchant/FavoriteMerchantAdminController.php Ver fichero

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Controller\Merchant;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request;
@@ -27,22 +28,19 @@ class FavoriteMerchantAdminController extends AbstractController
if ($merchant) {

$user = $security->getUser();
if($user) {
if ($user) {
$user->setFavoriteMerchant($merchant);
$entityManager->update($user);
$entityManager->flush();
}

// @TODO : à fignoler, hein gamin ?
$url = $this->getSettingSolver()->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
) . 'admin';

if ($url) {
return $this->redirect($url);
}
$this->addFlashTranslator('success', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant', ['%merchant%' => $merchant->getTitle()]);
}

} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant');
}

return $this->redirect($request->headers->get('referer'));
}
}

+ 8
- 9
Controller/Merchant/FavoriteMerchantController.php Ver fichero

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Controller\Merchant;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request;
@@ -33,16 +34,14 @@ class FavoriteMerchantController extends AbstractController
$entityManager->flush();
}

// @TODO : à fignoler, hein gamin ?
$url = $this->getSettingSolver()->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
) . 'admin';

if ($url) {
return $this->redirect($url);
}
$this->addFlashTranslator('success', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant', ['%merchant%' => $merchant->getTitle()]);
}

} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_FAVORITE_MERCHANT, 'Merchant');
}

return $this->redirect($request->headers->get('referer'));
}

}

+ 18
- 6
Controller/Merchant/SwitchMerchantController.php Ver fichero

@@ -4,6 +4,7 @@ namespace Lc\CaracoleBundle\Controller\Merchant;

use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
use Lc\CaracoleBundle\Controller\AbstractController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Definition\MerchantSettingDefinition;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Symfony\Component\HttpFoundation\Request;
@@ -16,7 +17,11 @@ class SwitchMerchantController extends AbstractController
*/
public function switchMerchant(Request $request)
{
$form = $this->createForm(SwitchMerchantFormType::class);
$form = $this->createForm(
SwitchMerchantFormType::class,
null,
array('csrf_protection' => false)
);
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
@@ -25,19 +30,26 @@ class SwitchMerchantController extends AbstractController

if ($merchant) {
$url = $this->getSettingValue(
$merchant,
MerchantSettingDefinition::SETTING_URL
$merchant,
MerchantSettingDefinition::SETTING_URL
);

if ($context == 'admin') {
$url .= 'admin';
}

if ($url) {
return $this->redirect($url);
}

}
}

if ($url) {
return $this->redirect($url);
} else {
$this->addFlashTranslator('error', ActionDefinition::SWITCH_MERCHANT, 'Merchant');
return $this->redirect($request->headers->get('referer'));
}


}

}

+ 2
- 0
Definition/ActionDefinition.php Ver fichero

@@ -8,6 +8,8 @@ class ActionDefinition extends SovActionDefinition{
public const DUPLICATE_TO_OTHER_MERCHANT = 'duplicateToOtherMerchant';
public const DUPLICATE_TO_OTHER_SECTION = 'duplicateToOtherSection';
public const EDIT_ADDRESS_USER = 'editAddressUser';
public const SWITCH_MERCHANT = 'switchMerchant';
public const SWITCH_FAVORITE_MERCHANT = 'switchFavoriteMerchant';


}

+ 2
- 1
Repository/Product/ProductFamilyRepositoryQuery.php Ver fichero

@@ -168,7 +168,8 @@ class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery

$this->leftJoin('.productCategories', 'productCategories');
if ($addSelect) {
$this->addSelect('productCategories');
//Commenté sinon doctrine n'hydrate pas correctement les catégories liés au ProductFamily (exemple : un seul sur trois)
//$this->addSelect('productCategories');
}
return $this;
}

+ 68
- 67
Repository/Product/ProductFamilyStore.php Ver fichero

@@ -51,10 +51,11 @@ 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) {
@@ -69,14 +70,15 @@ class ProductFamilyStore extends AbstractStore

// 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();
}
@@ -85,7 +87,8 @@ class ProductFamilyStore extends AbstractStore
public function getByCategoryOnlineAndOffline(
ProductCategoryInterface $productCategory,
$query = null
) {
)
{
$query = $this->createDefaultQuery($query);

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

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

$results = $query->find();

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

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

$results = $query->find();

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

@@ -146,12 +149,13 @@ 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();
@@ -169,26 +173,21 @@ class ProductFamilyStore extends AbstractStore
}

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

$price2 = $this->priceSolver->applyReductionCatalog(
$productFamily,
$this->priceSolver->getPrice($productFamily),
$this->priceSolver->getPriceWithTax($productFamily),
1,
$reductionCatalog2
$price2 = $this->priceSolver->getPriceWithTaxByReduction(
$productFamily,
$reductionCatalog2
);


if ($price1 > $price2) {
return $reductionCatalog2;
} else {
@@ -198,29 +197,32 @@ 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 = [
'ids' => [],
'categories' => [],
'productFamiliesIds' => [],
'categories' => [],
'productFamilies' => [],
];

foreach ($productFamilies as $productFamily) {
$conditions['ids'][] = $productFamily->getId();
$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
);
}

@@ -230,20 +232,19 @@ 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;
}
}
@@ -251,11 +252,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);
@@ -273,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;

+ 31
- 27
Repository/Reduction/ReductionCatalogRepositoryQuery.php Ver fichero

@@ -2,6 +2,7 @@

namespace Lc\CaracoleBundle\Repository\Reduction;

use Doctrine\Common\Collections\ArrayCollection;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
@@ -29,8 +30,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinUsers = true;

return $this
->leftJoin('.users', 'pf_users')
->addSelect('pf_users') ;
->leftJoin('.users', 'pf_users')
->addSelect('pf_users');
}
return $this;
}
@@ -41,8 +42,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinGroupUsers = true;

return $this
->leftJoin('.groupUsers', 'groupUsers')
->addSelect('groupUsers') ;
->leftJoin('.groupUsers', 'groupUsers')
->addSelect('groupUsers');
}
return $this;
}
@@ -53,8 +54,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductFamilies = true;

return $this
->leftJoin('.productFamilies', 'productFamilies')
->addSelect('productFamilies') ;
->leftJoin('.productFamilies', 'productFamilies')
->addSelect('productFamilies');
}
return $this;
}
@@ -65,8 +66,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductFamily = true;

return $this
->leftJoin('.productFamily', 'productFamily')
->addSelect('productFamily') ;
->leftJoin('.productFamily', 'productFamily')
->addSelect('productFamily');
}

return $this;
@@ -78,8 +79,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->isJoinProductCategories = true;

return $this
->leftJoin('.productCategories', 'productCategories')
->addSelect('productCategories') ;
->leftJoin('.productCategories', 'productCategories')
->addSelect('productCategories');
}

return $this;
@@ -88,15 +89,15 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
public function filterProductFamily(ProductFamilyInterface $productFamily)
{
return $this
->andWhere('.productFamily = :productFamily')
->setParameter(':productFamily', $productFamily);
->andWhere('.productFamily = :productFamily')
->setParameter(':productFamily', $productFamily);
}

public function filterConditionDate()
{
return $this
->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
->setParameter(':now', new \DateTime());
->andWhere('.permanent = 1 OR ( .dateStart <= :now AND .dateEnd >= :now)')
->setParameter(':now', new \DateTime());
}

public function filterConditionUser(UserInterface $user = null)
@@ -105,11 +106,11 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery

if ($user) {
return $this
->andWhere(':user MEMBER OF .users OR .users is empty')
->setParameter('user', $user);
->andWhere(':user MEMBER OF .users OR .users is empty')
->setParameter('user', $user);
} else {
return $this
->andWhere('.users is empty');
->andWhere('.users is empty');
}
}

@@ -119,21 +120,24 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery

if ($user) {
return $this
->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
->setParameter('groupUser', $user->getGroupUsers());
->andWhere(':groupUser MEMBER OF .groupUsers OR .groupUsers is empty')
->setParameter('groupUser', $user->getGroupUsers());
} else {
return $this
->andWhere('.groupUsers is empty');
->andWhere('.groupUsers is empty');
}
}

public function filterConditionProductFamilies(array $productFamilies)
public function filterConditionProductFamilies(array $productFamiliesIds, array $productFamilies)
{
$this->joinProductFamilies();
$this->joinProductFamily();

return $this
->andWhere(':productFamilies MEMBER OF .productFamilies OR .productFamilies is empty')
->setParameter('productFamilies', $productFamilies);
->andWhere(':productFamiliesIds MEMBER OF .productFamilies OR .productFamilies is empty')
->andWhere('.productFamily IN (:productFamilies) OR .productFamily is null')
->setParameter('productFamiliesIds', $productFamiliesIds)
->setParameter('productFamilies', $productFamilies);
}

public function filterConditionProductFamily(ProductFamilyInterface $productFamily)
@@ -141,8 +145,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->joinProductFamily();

return $this
->andWhere(':productFamily MEMBER OF .productFamily OR .productFamily is empty')
->setParameter('productFamily', $productFamily);
->andWhere(':productFamily MEMBER OF .productFamily OR .productFamily is empty')
->setParameter('productFamily', $productFamily);
}

public function filterConditionProductCategories(array $productCategories)
@@ -150,8 +154,8 @@ class ReductionCatalogRepositoryQuery extends AbstractRepositoryQuery
$this->joinProductCategories();

return $this
->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
->setParameter('productCategory', $productCategories);
->andWhere(':productCategory MEMBER OF .productCategories OR .productCategories is empty')
->setParameter('productCategory', $productCategories);
}



+ 6
- 1
Resources/translations/admin.fr.yaml Ver fichero

@@ -112,7 +112,12 @@ entity:
Merchant:
label: Marchand
label_plurial: Marchands

flashes:
error:
switchMerchant: Une erreur est survenue lors du changement de marchand, veuillez réessayer.
switchFavoriteMerchant: Une erreur est survenue lors de la sauvegarde de votre marchand favoris.
success:
switchFavoriteMerchant: "%merchant% est maintenant votre marchand favoris."
Section:
label: Section
label_plurial: Sections

+ 1
- 1
Resources/views/adminlte/layout.html.twig Ver fichero

@@ -23,7 +23,7 @@
<ul class="navbar-nav ml-auto right">
<li class="nav-item nav-switch-merchant">
<i class="fa fa-store"></i>
{% set form_switch_merchant = carac_form_switch_merchant('admin') %}
{% set form_switch_merchant = carac_form_switch_merchant('admin', 'carac_merchant_switch', false) %}
{% form_theme form_switch_merchant '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_merchant) }}
{{ form(form_switch_merchant) }}

+ 13
- 0
Solver/Price/ProductPriceSolver.php Ver fichero

@@ -5,6 +5,7 @@ namespace Lc\CaracoleBundle\Solver\Price;
use Lc\CaracoleBundle\Doctrine\Extension\ProductPropertyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\CaracoleBundle\Solver\Product\ProductFamilySolver;
use Lc\CaracoleBundle\Solver\Product\ProductSolver;

@@ -87,6 +88,18 @@ class ProductPriceSolver
);
}

//Bridge pour applyReductionCatalog qui ne peut pas être appeler à cause du call
public function getPriceWithTaxByReduction(ProductPropertyInterface $product, ReductionCatalogInterface $reductionCatalog)
{
return $this->applyReductionCatalog(
$product,
$this->getPrice($product),
$this->getPriceWithTax($product),
1,
$reductionCatalog
);
}

public function getPriceByRefUnitWithTaxAndReduction(ProductPropertyInterface $product)
{
return ($this->getPriceByRefUnitWithTax($product) * $this->getPriceWithTaxAndReduction($product))

+ 2
- 5
Twig/FormTwigExtension.php Ver fichero

@@ -2,12 +2,8 @@

namespace Lc\CaracoleBundle\Twig;

use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantButtonAdminFormType;
use Lc\CaracoleBundle\Form\Merchant\SwitchMerchantFormType;
use Lc\CaracoleBundle\Form\Section\SwitchSectionFormType;
use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\Section\SectionRepository;
use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Extension\AbstractExtension;
@@ -34,7 +30,7 @@ class FormTwigExtension extends AbstractExtension
);
}

public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_merchant_switch')
public function getFormSwitchMerchant($context = 'front', $actionRoute = 'carac_merchant_switch', $csrfProtection = true)
{
$form = $this->formFactory->create(
SwitchMerchantFormType::class,
@@ -42,6 +38,7 @@ class FormTwigExtension extends AbstractExtension
[
'action' => $this->urlGenerator->generate($actionRoute),
'attr' => ['class' => 'switch-merchant'],
'csrf_protection' => $csrfProtection,
'context' => $context
]
);

Cargando…
Cancelar
Guardar