@@ -8,7 +8,7 @@ use Symfony\Component\HttpFoundation\Request; | |||
use Symfony\Component\HttpFoundation\JsonResponse; | |||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | |||
class CitiesController extends AbstractController | |||
class AddressApiController extends AbstractController | |||
{ | |||
protected $utils ; | |||
@@ -17,7 +17,7 @@ class CitiesController extends AbstractController | |||
$this->utils = $utils ; | |||
} | |||
public function index(Request $request) : JsonResponse | |||
public function cities(Request $request) : JsonResponse | |||
{ | |||
$term = $request->get('term') ; | |||
$context = $request->get('context') ; | |||
@@ -58,5 +58,31 @@ class CitiesController extends AbstractController | |||
return new JsonResponse($return) ; | |||
} | |||
public function addresses(Request $request) : JsonResponse | |||
{ | |||
$return = [] ; | |||
$address = $request->get('address') ; | |||
$context = $request->get('context') ; | |||
$results = $this->utils->callAddressApi($address) ; | |||
foreach($results as $result) { | |||
if($result->getStreetNumber() && strlen($result->getStreetNumber()) > 0) { | |||
$streetNameNumber = $result->getStreetNumber().' '.$result->getStreetName() ; | |||
$return[] = [ | |||
'label' => $streetNameNumber, | |||
'value' => $streetNameNumber, | |||
'latitude' => $result->getCoordinates()->getLatitude(), | |||
'longitude' => $result->getCoordinates()->getLongitude() | |||
] ; | |||
} | |||
} | |||
if($context == 'frontend') { | |||
$return = [ | |||
'items' => $return | |||
] ; | |||
} | |||
return new JsonResponse($return) ; | |||
} | |||
} |
@@ -43,6 +43,7 @@ class AdminController extends EasyAdminController | |||
protected $orderUtils; | |||
protected $mailUtils ; | |||
protected $translator; | |||
protected $utilsProcess; | |||
protected $filtersForm = null; | |||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, | |||
@@ -56,6 +57,7 @@ class AdminController extends EasyAdminController | |||
$this->merchantUtils = $utilsManager->getMerchantUtils(); | |||
$this->orderUtils = $utilsManager->getOrderUtils();; | |||
$this->mailUtils = $utilsManager->getMailUtils() ; | |||
$this->utilsProcess = $utilsManager->getUtilsProcess() ; | |||
$this->translator = $translator; | |||
} | |||
@@ -598,14 +600,7 @@ class AdminController extends EasyAdminController | |||
$entity= $this->em->getRepository($easyadmin['entity']['class'])->find($id); | |||
$newEntity = clone $entity ; | |||
if($newEntity instanceof ImageInterface){ | |||
$newEntity->setImage(null); | |||
} | |||
$this->em->persist($newEntity) ; | |||
$this->em->flush() ; | |||
$newEntity = $this->utilsProcess->duplicateEntity($entity); | |||
return $this->redirectToRoute('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]) ; | |||
} | |||
@@ -622,25 +617,26 @@ class AdminController extends EasyAdminController | |||
$entity= $this->em->getRepository($easyadmin['entity']['class'])->find($id); | |||
$hub= $this->em->getRepository(MerchantInterface::class)->findOneByDevAlias($hubAlias); | |||
$newEntity = clone $entity ; | |||
$newEntity = $this->utilsProcess->duplicateEntityToOtherHub($entity,$hub); | |||
if($newEntity instanceof ImageInterface){ | |||
$newEntity->setImage(null); | |||
} | |||
$user->setMerchant($hub); | |||
$this->em->persist($user); | |||
$this->em->flush(); | |||
$redirectUrl = $this->generateUrl('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]).'&hubredirection=true'; | |||
if ($hub) { | |||
$newEntity->setMerchant($hub); | |||
$user->setMerchant($hub); | |||
$this->em->persist($user); | |||
} | |||
$this->em->persist($newEntity) ; | |||
$this->em->flush() ; | |||
return $this->redirectToOtherHub($hub, $redirectUrl) ; | |||
} | |||
$redirectUrl = $hub->getMerchantConfig('url').substr($this->generateUrl('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' =>$newEntity->getId(), 'referer' =>$refererUrl ]),1).'&hubredirection=true'; | |||
public function redirectToOtherHub($hub, $url){ | |||
if(strpos($_SERVER['HTTP_HOST'], 'localhost')!==false){ | |||
return $this->redirect($url); | |||
}else{ | |||
return $this->redirect($hub->getMerchantConfig('url').substr($url,1)); | |||
} | |||
return $this->redirect($redirectUrl) ; | |||
} | |||
} | |||
@@ -100,7 +100,7 @@ class MerchantController extends AdminController | |||
$em->persist($user); | |||
$em->flush(); | |||
return $this->redirect($merchant->getMerchantConfig('url').'admin/dashboard?hubredirection=true') ; | |||
return $this->redirectToOtherHub($merchant, '/admin/dashboard?hubredirection=true') ; | |||
} | |||
} | |||
@@ -10,6 +10,7 @@ use Lc\ShopBundle\Context\ImageInterface; | |||
use Lc\ShopBundle\Context\OrderShopInterface; | |||
use Lc\ShopBundle\Context\ProductCategoryInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
use Lc\ShopBundle\Context\ProductInterface; | |||
use Lc\ShopBundle\Context\ReductionCatalogInterface; | |||
use Lc\ShopBundle\Context\TaxRateInterface; | |||
use Lc\ShopBundle\Form\Backend\Common\AbstractEditPositionType; | |||
@@ -34,6 +35,7 @@ class ProductFamilyController extends AdminController | |||
private $choicesTaxRateParam; | |||
private $choicesSupplierTaxRateParam; | |||
private $parameterBag ; | |||
private $productFamilyUtils ; | |||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, | |||
MailjetTransport $mailjetTransport, UtilsManager $utilsManager, TranslatorInterface $translator, | |||
@@ -41,6 +43,7 @@ class ProductFamilyController extends AdminController | |||
{ | |||
parent::__construct($security, $userManager, $em, $mailjetTransport, $utilsManager, $translator); | |||
$this->parameterBag = $parameterBag ; | |||
$this->productFamilyUtils = $utilsManager->getProductFamilyUtils() ; | |||
} | |||
public function createEntityFormBuilder($entity, $view, $override = true) | |||
@@ -188,10 +191,7 @@ class ProductFamilyController extends AdminController | |||
public function updateProductFamilyEntity($entity, $editForm = false) | |||
{ | |||
if ($editForm) { | |||
$this->processReductionCatalog($entity, $editForm); | |||
$this->processCategories($entity); | |||
$this->processProducts($entity); | |||
$this->processPrice($entity); | |||
$entity = $this->productFamilyUtils->processBeforePersistProductFamily($entity, $editForm); | |||
} | |||
parent::updateEntity($entity); | |||
@@ -201,85 +201,12 @@ class ProductFamilyController extends AdminController | |||
public function persistProductFamilyEntity($entity, $newForm) | |||
{ | |||
$this->processReductionCatalog($entity, $newForm); | |||
$this->processCategories($entity); | |||
$this->processProducts($entity); | |||
$this->processPrice($entity); | |||
$entity = $this->productFamilyUtils->processBeforePersistProductFamily($entity, $newForm); | |||
$this->em->persist($entity); | |||
$this->em->flush(); | |||
} | |||
protected function processReductionCatalog($entity, $editForm) | |||
{ | |||
$reductionCatalog = $editForm->get('reductionCatalog')->getData(); | |||
if ($reductionCatalog instanceof ReductionCatalogInterface) { | |||
if ($reductionCatalog->getValue() && $reductionCatalog->getBehaviorTaxRate() && $reductionCatalog->getUnit()) { | |||
$reductionCatalog->setMerchant($entity->getMerchant()); | |||
$reductionCatalog->setStatus($editForm->get('activeReductionCatalog')->getData()); | |||
$reductionCatalog->setProductFamily($entity); | |||
$this->em->persist($reductionCatalog); | |||
} | |||
} | |||
} | |||
protected function processPrice($entity) | |||
{ | |||
if ($entity->getBehaviorPrice() == 'by-piece') { | |||
$entity->setPriceByRefUnit(null); | |||
$entity->setBuyingPriceByRefUnit(null); | |||
} else if ($entity->getBehaviorPrice() == 'by-reference-unit') { | |||
$entity->setPrice(null); | |||
$entity->setBuyingPrice(null); | |||
} | |||
} | |||
protected function processProducts($entity, $clone = false) | |||
{ | |||
//si il existe un et un seul produit pour ce product family n'ajoute rien supprime rien | |||
if (count($entity->getProducts()) == 0) { | |||
$product = new Product(); | |||
$product->setProductFamily($entity); | |||
$this->em->persist($product); | |||
$entity->addProduct($product); | |||
} else { | |||
foreach ($entity->getProducts() as $i => $product) { | |||
if ($clone) { | |||
$newProduct = clone $product; | |||
$newProduct->setProductFamily($entity); | |||
$this->em->persist($newProduct); | |||
$entity->addProduct($newProduct); | |||
} else { | |||
$product->setProductFamily($entity); | |||
$this->em->persist($product); | |||
$entity->addProduct($product); | |||
} | |||
} | |||
} | |||
} | |||
protected function processCategories(ProductFamilyInterface $entity) | |||
{ | |||
$productCategoryRepository = $this->getDoctrine()->getRepository(ProductCategoryInterface::class); | |||
$productCategories = $entity->getProductCategories(); | |||
$entity->initProductCategories(); | |||
foreach ($productCategories as $key => $bool) { | |||
if (is_bool($bool) && $bool) { | |||
if (strpos($key, 'category_children_') !== false) { | |||
$idCategory = (int)str_replace('category_children_', '', $key); | |||
} else { | |||
$idCategory = (int)str_replace('category_', '', $key); | |||
} | |||
$category = $productCategoryRepository->find($idCategory); | |||
$entity->addProductCategory($category); | |||
} | |||
} | |||
} | |||
protected function editAction() | |||
{ | |||
@@ -310,11 +237,16 @@ class ProductFamilyController extends AdminController | |||
$deleteForm = $this->createDeleteForm($this->entity['name'], $id); | |||
$sortableProductsField = array(); | |||
foreach ($editForm->get('products')->getData() as $k => $product) { | |||
$sortableProductsField[$product->getPosition()] = $k; | |||
if($product->getOriginProduct() == false) { | |||
$sortableProductsField[$product->getPosition()] = $k; | |||
}else{ | |||
$sortableProductsField[-1] = $k; | |||
} | |||
} | |||
} | |||
ksort($sortableProductsField); | |||
$editForm->handleRequest($this->request); | |||
@@ -405,40 +337,12 @@ class ProductFamilyController extends AdminController | |||
'entity' => $entity, | |||
'categories' => $categories, | |||
'sortableProductsField' => array(), | |||
'totalProductOrdered' => array() | |||
'totalProductOrdered' => array('total'=>0) | |||
]; | |||
return $this->executeDynamicMethod('render<EntityName>Template', ['new', $this->entity['templates']['new'], $parameters]); | |||
} | |||
public function duplicateAction() | |||
{ | |||
$id = $this->request->query->get('id'); | |||
$refererUrl = $this->request->query->get('referer', ''); | |||
$easyadmin = $this->request->attributes->get('easyadmin'); | |||
$entity = $this->em->getRepository($easyadmin['entity']['class'])->find($id); | |||
$newProductFamily = clone $entity; | |||
if ($easyadmin['entity']['name'] == "ProductFamily") { | |||
$this->processProducts($newProductFamily, true); | |||
} | |||
if($newProductFamily instanceof ImageInterface) { | |||
$basePath = $this->parameterBag->get('kernel.project_dir').'/public/uploads/images/' ; | |||
$imageProductFamily = 'produits/'.md5(time()).'.jpg' ; | |||
copy($basePath.$entity->getImage(), $basePath.$imageProductFamily) ; | |||
$newProductFamily->setImage($imageProductFamily); | |||
} | |||
$this->em->persist($newProductFamily); | |||
$this->em->flush(); | |||
return $this->redirectToRoute('easyadmin', ['entity' => $easyadmin['entity']['name'], 'action' => 'edit', 'id' => $newProductFamily->getId(), 'referer' => $refererUrl]); | |||
} | |||
//hack utilisé pour filter sur les catégories lors du tri des produits par sous cat | |||
//A améliorer à l'occas |
@@ -29,6 +29,7 @@ class ProductType extends AbstractType | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
//dump($builder); | |||
$builder->add('title', TextType::class, array( | |||
"required" => false |
@@ -38,7 +38,6 @@ abstract class AbstractEntity | |||
*/ | |||
protected $updatedBy; | |||
public function getCreatedAt(): ?\DateTimeInterface | |||
{ | |||
return $this->createdAt; |
@@ -47,6 +47,10 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod | |||
*/ | |||
protected $title; | |||
/** | |||
* @ORM\Column(type="boolean", nullable=true) | |||
*/ | |||
protected $originProduct; | |||
public function __construct() | |||
{ | |||
@@ -56,13 +60,13 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod | |||
public function __toString() | |||
{ | |||
$title = $this->getProductFamily()->getTitle() ; | |||
$title = $this->getProductFamily()->getTitle(); | |||
if($this->getTitle() && strlen($this->getTitle())) { | |||
$title .= ' - '. $this->getTitle() ; | |||
if ($this->getTitle() && strlen($this->getTitle())) { | |||
$title .= ' - ' . $this->getTitle(); | |||
} | |||
return $title ; | |||
return $title; | |||
} | |||
public function getBuyingPriceInherited() | |||
@@ -133,8 +137,7 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod | |||
{ | |||
if ($this->getQuantity()) { | |||
return $this->getQuantity(); | |||
} | |||
else { | |||
} else { | |||
return $this->getProductFamily()->getQuantity(); | |||
} | |||
} | |||
@@ -199,4 +202,16 @@ abstract class Product extends AbstractEntity implements SortableInterface, Prod | |||
return $this; | |||
} | |||
public function getOriginProduct(): ?bool | |||
{ | |||
return $this->originProduct; | |||
} | |||
public function setOriginProduct(?bool $originProduct): self | |||
{ | |||
$this->originProduct = $originProduct; | |||
return $this; | |||
} | |||
} |
@@ -243,7 +243,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
case self::BEHAVIOR_COUNT_STOCK_BY_PRODUCT : | |||
foreach($this->getProducts() as $product) { | |||
foreach($this->getProductsOnline() as $product) { | |||
$availableQuantity += $product->getAvailableQuantityInherited() ; | |||
} | |||
break ; | |||
@@ -327,7 +327,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
$productsOnlineArray = new ArrayCollection() ; | |||
foreach($products as $product) { | |||
if($product->getStatus() == 1) { | |||
if($product->getStatus() == 1 && $product->getOriginProduct() !=true) { | |||
$productsOnlineArray[] = $product ; | |||
} | |||
} | |||
@@ -753,7 +753,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
{ | |||
if ($this->getActiveProducts()) { | |||
$arrayCountProducts = []; | |||
$products = $this->getProducts(); | |||
$products = $this->getProductsOnline(); | |||
foreach ($products as $product) { | |||
$titleProduct = $product->getTitleInherited(); | |||
@@ -777,7 +777,7 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
public function getProductsGroupByTitle() | |||
{ | |||
$arrayProductsGroupByTitle = []; | |||
$products = $this->getProducts(); | |||
$products = $this->getProductsOnline(); | |||
foreach ($products as $product) { | |||
if($product->getStatus() == 1) { | |||
@@ -791,4 +791,36 @@ abstract class ProductFamily extends AbstractDocumentEntity implements ProductPr | |||
return $arrayProductsGroupByTitle; | |||
} | |||
public function getOriginProduct() | |||
{ | |||
$products = $this->getProducts() ; | |||
foreach($products as $product) { | |||
if($product->getOriginProduct()) { | |||
return $product ; | |||
} | |||
} | |||
} | |||
public function getOriginProductOnline() | |||
{ | |||
$originProduct = $this->getOriginProduct() ; | |||
if($originProduct->getStatus()==1){ | |||
return $originProduct; | |||
}else{ | |||
return false; | |||
} | |||
} | |||
public function hasOneProductOnline() | |||
{ | |||
if( ($this->getActiveProducts() && count($this->getProductsOnline()) > 0) | |||
|| (!$this->getActiveProducts() && $this->getOriginProduct())){ | |||
return true ; | |||
} | |||
return false ; | |||
} | |||
} |
@@ -167,6 +167,7 @@ $(window).on('load', function () { | |||
title: null, | |||
position: 0, | |||
status:1, | |||
originProduct: false, | |||
fieldToUpdate: ['title', 'unit', 'quantity', 'price'], | |||
price: null, | |||
priceWithTax: null, | |||
@@ -267,7 +268,8 @@ $(window).on('load', function () { | |||
}, | |||
deleteProductForm: function () { | |||
if (confirm('Êtes-vous sur de cette action ?')) { | |||
Vue.delete(this.$parent.formProducts, this.keyForm); | |||
this.status = -1; | |||
//Vue.delete(this.$parent.formProducts, this.keyForm); | |||
this.$nextTick(function () { | |||
this.$parent.updateSortableProducts(true); | |||
}); |
@@ -14,7 +14,12 @@ | |||
<div class="col-12"> | |||
{{ form_row(form.deliveryTaxRate) }} | |||
</div> | |||
<div class="col-12"> | |||
{{ form_row(form.merchantConfigs['bike-delivery']) }} | |||
</div> | |||
<div class="col-12"> | |||
{{ form_row(form.merchantConfigs['bike-delivery-url-map']) }} | |||
</div> | |||
{{ macros.card_end() }} | |||
</div> | |||
</div> |
@@ -60,7 +60,7 @@ | |||
{% macro product_row(product, totalProductOrdered) %} | |||
<tr class="lc-draggable"> | |||
<tr class="lc-draggable" v-show="originProduct != true && status >= 0 "> | |||
<td> | |||
{% if product.vars.value is not null %} | |||
#{{ product.vars.value.id }} |
@@ -53,7 +53,7 @@ | |||
</th> | |||
<th colspan="3" class="price"> | |||
{# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#} | |||
{# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#} | |||
PV HT | |||
</th> | |||
<th colspan="3" class="price main-info"> | |||
@@ -137,7 +137,7 @@ | |||
</th> | |||
<th colspan="3" class="price"> | |||
{# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#} | |||
{# v-show="getBehaviorPrice() =='{{ constant('Lc\\ShopBundle\\Model\\ProductFamily::BEHAVIOR_PRICE_BY_PIECE') }}'">#} | |||
${productFamily.price} | |||
</th> | |||
<th colspan="3" class="price main-info"> | |||
@@ -195,7 +195,9 @@ | |||
{% for keyForm,i in sortableProductsField %} | |||
{% set product = form.products[i] %} | |||
{#{% if product.vars.value.status >= 0 and (product.vars.value.originProduct is null or product.vars.value.originProduct == false) %}#} | |||
window.productForm[{{ keyForm }}] = { | |||
{% if product.vars.value.originProduct is defined %}originProduct: parseInt({{ product.vars.value.originProduct }}),{% endif %} | |||
{% if product.vars.value.status is defined %}status: parseInt({{ product.vars.value.status }}),{% endif %} | |||
{% if product.vars.value.position %}position: "{{ product.vars.value.position }}",{% endif %} | |||
{% if product.vars.value.title %}title: "{{ product.vars.value.title }}",{% endif %} | |||
@@ -211,6 +213,7 @@ | |||
{#{% if product.vars.value.expirationDate %}expirationDate: "{{ product.vars.value.expirationDate|date('d/m/Y') }}"{% endif %}#} | |||
}; | |||
window.formProductTemplate[{{ keyForm }}] = '{{ product_family_macros.product_row(product, totalProductOrdered[product.vars.value.id])|replace({"\n":' ', "\r":' ', "'" : "\\'"})|raw }}'; | |||
{#{% endif %}#} | |||
{% endfor %} | |||
</script> |
@@ -338,6 +338,22 @@ class OrderUtils | |||
return false ; | |||
} | |||
public function getOrderProductsByProductFamilyInCart($productFamily) | |||
{ | |||
$arrayOrderProducts = [] ; | |||
$orderShop = $this->getCartCurrent() ; | |||
if($orderShop) { | |||
foreach($orderShop->getOrderProducts() as $orderProduct) { | |||
if($orderProduct->getProduct()->getProductFamily() == $productFamily) { | |||
$arrayOrderProducts[] = $orderProduct ; | |||
} | |||
} | |||
} | |||
return $arrayOrderProducts ; | |||
} | |||
public function groupOrderProductsByProductFamily($orderProducts) | |||
{ | |||
$orderProductsByProductFamily = []; |
@@ -0,0 +1,69 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Services ; | |||
class PointLocationUtils { | |||
var $pointOnVertex = true; // Check if the point sits exactly on one of the vertices? | |||
function pointLocation() { | |||
} | |||
function pointInPolygon($point, $polygon, $pointOnVertex = true) { | |||
$this->pointOnVertex = $pointOnVertex; | |||
// Transform string coordinates into arrays with x and y values | |||
$point = $this->pointStringToCoordinates($point); | |||
$vertices = array(); | |||
foreach ($polygon as $vertex) { | |||
$vertices[] = $this->pointStringToCoordinates($vertex); | |||
} | |||
// Check if the point sits exactly on a vertex | |||
if ($this->pointOnVertex == true and $this->pointOnVertex($point, $vertices) == true) { | |||
return "vertex"; | |||
} | |||
// Check if the point is inside the polygon or on the boundary | |||
$intersections = 0; | |||
$vertices_count = count($vertices); | |||
for ($i=1; $i < $vertices_count; $i++) { | |||
$vertex1 = $vertices[$i-1]; | |||
$vertex2 = $vertices[$i]; | |||
if ($vertex1['y'] == $vertex2['y'] and $vertex1['y'] == $point['y'] and $point['x'] > min($vertex1['x'], $vertex2['x']) and $point['x'] < max($vertex1['x'], $vertex2['x'])) { // Check if point is on an horizontal polygon boundary | |||
return "boundary"; | |||
} | |||
if ($point['y'] > min($vertex1['y'], $vertex2['y']) and $point['y'] <= max($vertex1['y'], $vertex2['y']) and $point['x'] <= max($vertex1['x'], $vertex2['x']) and $vertex1['y'] != $vertex2['y']) { | |||
$xinters = ($point['y'] - $vertex1['y']) * ($vertex2['x'] - $vertex1['x']) / ($vertex2['y'] - $vertex1['y']) + $vertex1['x']; | |||
if ($xinters == $point['x']) { // Check if point is on the polygon boundary (other than horizontal) | |||
return "boundary"; | |||
} | |||
if ($vertex1['x'] == $vertex2['x'] || $point['x'] <= $xinters) { | |||
$intersections++; | |||
} | |||
} | |||
} | |||
// If the number of edges we passed through is odd, then it's in the polygon. | |||
if ($intersections % 2 != 0) { | |||
return "inside"; | |||
} else { | |||
return "outside"; | |||
} | |||
} | |||
function pointOnVertex($point, $vertices) { | |||
foreach($vertices as $vertex) { | |||
if ($point == $vertex) { | |||
return true; | |||
} | |||
} | |||
} | |||
function pointStringToCoordinates($pointString) { | |||
$coordinates = explode(" ", $pointString); | |||
return array("x" => $coordinates[0], "y" => $coordinates[1]); | |||
} | |||
} |
@@ -1,368 +0,0 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Services; | |||
use Doctrine\Common\Collections\Collection; | |||
use Lc\ShopBundle\Context\OrderProductInterface; | |||
use Lc\ShopBundle\Context\OrderShopInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
use Lc\ShopBundle\Context\ProductInterface; | |||
use Lc\ShopBundle\Context\ProductPropertyInterface; | |||
use Lc\ShopBundle\Context\ReductionCatalogInterface; | |||
class PriceUtilsOld | |||
{ | |||
public function getPrice($entity) | |||
{ | |||
if ($entity instanceof ProductPropertyInterface) { | |||
if ($entity->getBehaviorPriceInherited() == 'by-piece') { | |||
return $entity->getPriceInherited(); | |||
} elseif ($entity->getBehaviorPriceInherited() == 'by-reference-unit') { | |||
if ($entity->getQuantityInherited() > 0) { | |||
return $entity->getPriceByRefUnitInherited() * ($entity->getQuantityInherited() / $entity->getUnitInherited()->getCoefficient()); | |||
} | |||
} | |||
} | |||
if ($entity instanceof OrderProductInterface) { | |||
return $entity->getPrice(); | |||
} | |||
return null; | |||
} | |||
public function getPriceWithTax($entity) | |||
{ | |||
return $this->applyTax( | |||
$this->getPrice($entity), | |||
$entity->getTaxRateInherited()->getValue() | |||
); | |||
} | |||
public function getPriceWithTaxAndReduction($entity) | |||
{ | |||
return $this->getPriceWithTaxAndReductionCatalog( | |||
$entity, | |||
$this->getPrice($entity), | |||
$this->getPriceWithTax($entity) | |||
); | |||
} | |||
public function getPriceByRefUnit($entity) | |||
{ | |||
if ($entity instanceof ProductPropertyInterface) { | |||
if ($entity->getBehaviorPriceInherited() == 'by-piece') { | |||
return ($this->getPrice($entity) * $entity->getUnitInherited()->getCoefficient()) / $entity->getQuantityInherited(); | |||
} elseif ($entity->getBehaviorPriceInherited() == 'by-reference-unit') { | |||
return $entity->getPriceByRefUnitInherited(); | |||
} | |||
} | |||
if ($entity instanceof OrderProductInterface) { | |||
return ($this->getPrice($entity) * $entity->getUnitInherited()->getCoefficient()) / $entity->getQuantityProduct(); | |||
} | |||
return null; | |||
} | |||
public function getPriceByRefUnitWithTax($entity) | |||
{ | |||
return $this->applyTax( | |||
$this->getPriceByRefUnit($entity), | |||
$entity->getTaxRateInherited()->getValue() | |||
); | |||
} | |||
public function getPriceByRefUnitWithTaxAndReduction($entity) | |||
{ | |||
return $this->getPriceWithTaxAndReductionCatalog( | |||
$entity, | |||
$this->getPriceByRefUnit($entity), | |||
$this->getPriceByRefUnitWithTax($entity) | |||
); | |||
} | |||
public function getTotal($entity) | |||
{ | |||
if ($entity instanceof OrderProductInterface) { | |||
return $entity->getQuantityOrder() * $this->getPrice($entity); | |||
} | |||
if ($entity instanceof OrderShopInterface) { | |||
$total = 0; | |||
foreach ($entity->getOrderProducts() as $orderProduct) { | |||
$total += $this->getTotal($orderProduct); | |||
} | |||
return $total; | |||
} | |||
return null; | |||
} | |||
public function getTotalWithTax($entity) | |||
{ | |||
if ($entity instanceof OrderProductInterface) { | |||
return $this->applyTax( | |||
$this->getTotal($entity), | |||
$entity->getTaxRateInherited()->getValue() | |||
); | |||
} | |||
if ($entity instanceof OrderShopInterface) { | |||
$total = 0; | |||
foreach ($entity->getOrderProducts() as $orderProduct) { | |||
$total += $this->getTotalWithTax($orderProduct); | |||
} | |||
return $total; | |||
} | |||
//C'est bizzare ce truc là | |||
//if($entity instanceof OrderShopInterface) { | |||
// return $this->getTotalOrderProducts($entity->getOrderProducts(), true) ; | |||
//} | |||
return null; | |||
} | |||
public function getTotalWithTaxAndReduction($entity) | |||
{ | |||
if ($entity instanceof OrderProductInterface) { | |||
return $this->getPriceWithTaxAndReductionCatalog( | |||
$entity, | |||
$this->getTotal($entity), | |||
$this->getTotalWithTax($entity) | |||
); | |||
} | |||
if ($entity instanceof OrderShopInterface) { | |||
return $this->getTotalOrderProductsWithTaxAndReduction($entity->getOrderProducts(), true, true); | |||
} | |||
} | |||
public function getTotalWithReduction($entity) | |||
{ | |||
if ($entity instanceof OrderProductInterface) { | |||
return $this->getPriceWithReductionCatalog( | |||
$entity, | |||
$this->getTotal($entity), | |||
$this->getTotalWithTax($entity) | |||
); | |||
} | |||
if ($entity instanceof OrderShopInterface) { | |||
return $this->getTotalOrderProductsWithReduction($entity->getOrderProducts(), true, true); | |||
} | |||
} | |||
public function getTotalOrderProductsWithReductionCart(OrderShopInterface $order) | |||
{ | |||
$this->_getTotalOrderProductsWithReductionCartGeneric($order, false); | |||
} | |||
public function getTotalOrderProductsWithTaxAndReductionCart(OrderShopInterface $order) | |||
{ | |||
$this->_getTotalOrderProductsWithReductionCartGeneric($order, true); | |||
} | |||
private function _getTotalOrderProductsWithReductionCartGeneric(OrderShopInterface $order, $withTax = true) | |||
{ | |||
if ($withTax) { | |||
$priceToReturn = $this->getTotalOrderProductsWithTaxAndReductionCatalog($order); | |||
} | |||
else { | |||
$priceToReturn = $this->getTotalOrderProductsWithReductionCatalog($order); | |||
} | |||
foreach ($order->getOrderReductionCarts() as $orderReductionCart) { | |||
if ($orderReductionCart->getUnit() == 'percent') { | |||
$priceToReturn = $this->applyReductionPercent( | |||
$priceToReturn, | |||
$orderReductionCart->getValue | |||
); | |||
} else if ($orderReductionCart->getUnit() == 'amount') { | |||
if ($orderReductionCart->getBehaviorTaxRate() == 'tax-inlcluded') { | |||
$priceToReturn = | |||
$this->applyReductionAmount( | |||
$priceToReturn, | |||
$orderReductionCart->getValue() | |||
); | |||
} | |||
} | |||
} | |||
} | |||
public function getTotalOrderProducts($entity) | |||
{ | |||
return $this->getSumOrderProductsDispatch($entity); | |||
} | |||
public function getTotalOrderProductsWithTax($entity) | |||
{ | |||
return $this->getSumOrderProductsDispatch($entity, true); | |||
} | |||
public function getTotalOrderProductsWithReduction($entity) | |||
{ | |||
return $this->getTotalOrderProductsWithReductionCatalog($entity); | |||
} | |||
public function getTotalOrderProductsWithTaxAndReduction($entity) | |||
{ | |||
return $this->getTotalOrderProductsWithTaxAndReductionCatalog($entity); | |||
} | |||
public function getTotalOrderProductsWithReductionCatalog($entity) | |||
{ | |||
return $this->getSumOrderProductsDispatch($entity, false, true); | |||
} | |||
public function getTotalOrderProductsWithTaxAndReductionCatalog($entity) | |||
{ | |||
return $this->getSumOrderProductsDispatch($entity, true, true); | |||
} | |||
public function getSumOrderProductsDispatch($entity, $withTax = false, $withReductionCatalog = false) | |||
{ | |||
if ($entity instanceof OrderShopInterface) { | |||
return $this->getSumOrderProducts($entity->getOrderProducts(), $withTax, $withReductionCatalog); | |||
} | |||
if ($entity instanceof Collection || is_array($entity)) { | |||
return $this->getSumOrderProducts($entity, $withTax, $withReductionCatalog); | |||
} | |||
} | |||
public function getSumOrderProducts($orderProducts, $withTax = false, $withReductionCatalog = false) | |||
{ | |||
$total = 0; | |||
foreach ($orderProducts as $orderProduct) { | |||
if ($withTax && $withReductionCatalog) { | |||
$total += $this->getTotalWithTaxAndReduction($orderProduct); | |||
} elseif ($withTax) { | |||
$total += $this->getTotalWithTax($orderProduct); | |||
} elseif ($withReductionCatalog) { | |||
$total += $this->getTotalWithReduction($orderProduct); | |||
} else { | |||
$total += $this->getTotal($orderProduct); | |||
} | |||
} | |||
return $total; | |||
} | |||
public function getPriceWithTaxAndReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null) | |||
{ | |||
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, true); | |||
} | |||
public function getPriceWithReductionCatalog($entity, $price, $priceWithTax, $reductionCatalog = null) | |||
{ | |||
return $this->getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog, false); | |||
} | |||
public function getPriceWithReductionCatalogGeneric($entity, $price, $priceWithTax, $reductionCatalog = null, $withTax = true): ?float | |||
{ | |||
if ($reductionCatalog) { | |||
$reductionCatalogValue = $reductionCatalog->getValue(); | |||
$reductionCatalogUnit = $reductionCatalog->getUnit(); | |||
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate(); | |||
} else { | |||
if ($entity instanceof ProductPropertyInterface) { | |||
$reductionCatalog = $entity->getReductionCatalogInherited(); | |||
if ($reductionCatalog) { | |||
$reductionCatalogValue = $reductionCatalog->getValue(); | |||
$reductionCatalogUnit = $reductionCatalog->getUnit(); | |||
$reductionCatalogBehaviorTaxRate = $reductionCatalog->getBehaviorTaxRate(); | |||
} | |||
} | |||
if ($entity instanceof OrderProductInterface) { | |||
$orderProductReductionCatalog = $entity->getOrderProductReductionCatalog(); | |||
if ($orderProductReductionCatalog) { | |||
$reductionCatalogValue = $orderProductReductionCatalog->getValue(); | |||
$reductionCatalogUnit = $orderProductReductionCatalog->getUnit(); | |||
$reductionCatalogBehaviorTaxRate = $orderProductReductionCatalog->getBehaviorTaxRate(); | |||
} | |||
} | |||
} | |||
if (isset($reductionCatalogValue) && isset($reductionCatalogUnit) && isset($reductionCatalogBehaviorTaxRate)) { | |||
if ($reductionCatalogUnit == 'percent') { | |||
$priceWithTax = $this->applyReductionPercent( | |||
$priceWithTax, | |||
$reductionCatalogValue | |||
); | |||
} elseif ($reductionCatalogUnit == 'amount') { | |||
if ($reductionCatalogBehaviorTaxRate == 'tax-excluded') { | |||
$priceWithTax = $this->applyTax( | |||
$this->applyReductionAmount( | |||
$price, | |||
$reductionCatalogValue | |||
), | |||
$entity->getTaxRateInherited()->getValue() | |||
); | |||
} elseif ($reductionCatalogBehaviorTaxRate == 'tax-included') { | |||
$priceWithTax = $this->applyReductionAmount( | |||
$priceWithTax, | |||
$reductionCatalogValue | |||
); | |||
} | |||
} | |||
} | |||
if ($withTax) { | |||
$priceReturn = $priceWithTax; | |||
} else { | |||
$priceReturn = $this->applyPercentNegative($priceWithTax, $entity->getTaxRateInherited()->getValue()); | |||
} | |||
return $this->round($priceReturn); | |||
} | |||
public function getTotalTaxes($entity) | |||
{ | |||
if ($entity instanceof OrderProductInterface) { | |||
return $this->getTotalWithReduction($entity) * ($entity->getTaxRateInherited()->getValue() / 100); | |||
} | |||
if ($entity instanceof OrderShopInterface) { | |||
$totalTaxes = 0; | |||
foreach ($entity->getOrderProducts() as $orderProduct) { | |||
$totalTaxes += $this->getTotalTaxes($orderProduct); | |||
} | |||
return $totalTaxes; | |||
} | |||
return 0; | |||
} | |||
public function applyTax($price, $taxRateValue) | |||
{ | |||
return $this->round($this->applyPercent($price, $taxRateValue)); | |||
} | |||
public function applyReductionPercent($price, $percentage) | |||
{ | |||
return $this->applyPercent($price, -$percentage); | |||
} | |||
public function applyReductionAmount($price, $amount) | |||
{ | |||
return $price - $amount; | |||
} | |||
public function applyPercent($price, $percentage) | |||
{ | |||
return $price * ($percentage / 100 + 1); | |||
} | |||
public function applyPercentNegative($price, $percentage) | |||
{ | |||
return $price / ($percentage / 100 + 1); | |||
} | |||
public function round($price) | |||
{ | |||
return round((($price * 100)) / 100, 2); | |||
} | |||
} | |||
@@ -2,16 +2,24 @@ | |||
namespace Lc\ShopBundle\Services ; | |||
use App\Entity\Product; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Lc\ShopBundle\Context\PriceUtilsInterface; | |||
use Lc\ShopBundle\Context\ProductCategoryInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
use Lc\ShopBundle\Context\ProductInterface; | |||
use Lc\ShopBundle\Context\ReductionCatalogInterface; | |||
use Lc\ShopBundle\Model\ProductFamily; | |||
class ProductFamilyUtils | |||
{ | |||
protected $priceUtils ; | |||
protected $em ; | |||
public function __construct(PriceUtilsInterface $priceUtils) | |||
public function __construct(PriceUtilsInterface $priceUtils, EntityManagerInterface $em) | |||
{ | |||
$this->priceUtils = $priceUtils ; | |||
$this->em = $em; | |||
} | |||
public function getCheapestProduct($productFamily) | |||
@@ -40,10 +48,14 @@ class ProductFamilyUtils | |||
private function getCheapestOrMostExpensiveProduct($productFamily, $comparisonFunction, $returnSelfIfNotActiveProducts) | |||
{ | |||
$products = $productFamily->getProductsOnline()->getValues() ; | |||
if (count($products) > 0) { | |||
usort($products, $comparisonFunction); | |||
return $products[0]; | |||
if($productFamily->getActiveProducts()) { | |||
$products = $productFamily->getProductsOnline()->getValues(); | |||
if (count($products) > 0) { | |||
usort($products, $comparisonFunction); | |||
return $products[0]; | |||
} | |||
}else{ | |||
return $productFamily->getOriginProduct(); | |||
} | |||
if ($returnSelfIfNotActiveProducts) { | |||
return $productFamily; | |||
@@ -53,4 +65,110 @@ class ProductFamilyUtils | |||
} | |||
} | |||
public function processBeforePersistProductFamily($productFamily, $editForm=false, $clone =false){ | |||
if($editForm){ | |||
$this->processReductionCatalog($productFamily, $editForm); | |||
$this->processCategories($productFamily); | |||
} | |||
$this->processProducts($productFamily, $clone); | |||
$this->processPrice($productFamily); | |||
return $productFamily; | |||
} | |||
protected function processReductionCatalog($entity, $editForm) | |||
{ | |||
$reductionCatalog = $editForm->get('reductionCatalog')->getData(); | |||
if ($reductionCatalog instanceof ReductionCatalogInterface) { | |||
if ($reductionCatalog->getValue() && $reductionCatalog->getBehaviorTaxRate() && $reductionCatalog->getUnit()) { | |||
$reductionCatalog->setMerchant($entity->getMerchant()); | |||
$reductionCatalog->setStatus($editForm->get('activeReductionCatalog')->getData()); | |||
$reductionCatalog->setProductFamily($entity); | |||
$this->em->persist($reductionCatalog); | |||
} | |||
} | |||
} | |||
protected function processPrice($entity) | |||
{ | |||
if ($entity->getBehaviorPrice() == 'by-piece') { | |||
$entity->setPriceByRefUnit(null); | |||
$entity->setBuyingPriceByRefUnit(null); | |||
} else if ($entity->getBehaviorPrice() == 'by-reference-unit') { | |||
$entity->setPrice(null); | |||
$entity->setBuyingPrice(null); | |||
} | |||
} | |||
protected function processProducts($entity, $clone = false) | |||
{ | |||
if($clone) { | |||
foreach ($entity->getProducts() as $i => $product) { | |||
$newProduct = clone $product; | |||
$newProduct->setProductFamily($entity); | |||
$this->em->persist($newProduct); | |||
$entity->addProduct($newProduct); | |||
} | |||
}else { | |||
//Récupère le product origin | |||
$originProducts = $this->em->getRepository(ProductInterface::class)->findBy(array( | |||
'productFamily' => $entity->getId(), | |||
'originProduct' => true | |||
)); | |||
if (count($originProducts) > 1) { | |||
throw new \ErrorException('Plusieurs OriginProduct pour un même produit... Contacter fab'); | |||
// Case Nouveau product family | |||
} else if (count($originProducts) == 0) { | |||
$originProduct = new Product(); | |||
$originProduct->setProductFamily($entity); | |||
$originProduct->setOriginProduct(true); | |||
$entity->addProduct($originProduct); | |||
} else { | |||
$originProduct = $originProducts[0]; | |||
} | |||
if ($entity->getActiveProducts()) { | |||
$originProduct->setStatus(-1); | |||
} else { | |||
$originProduct->setStatus(1); | |||
} | |||
//Enregistrement | |||
$entity->addProduct($originProduct); | |||
foreach ($entity->getProducts() as $product) { | |||
$product->setProductFamily($entity); | |||
$this->em->persist($product); | |||
$entity->addProduct($product); | |||
} | |||
} | |||
} | |||
protected function processCategories(ProductFamilyInterface $entity) | |||
{ | |||
$productCategoryRepository = $this->em->getRepository(ProductCategoryInterface::class); | |||
$productCategories = $entity->getProductCategories(); | |||
$entity->initProductCategories(); | |||
foreach ($productCategories as $key => $bool) { | |||
if (is_bool($bool) && $bool) { | |||
if (strpos($key, 'category_children_') !== false) { | |||
$idCategory = (int)str_replace('category_children_', '', $key); | |||
} else { | |||
$idCategory = (int)str_replace('category_', '', $key); | |||
} | |||
$category = $productCategoryRepository->find($idCategory); | |||
$entity->addProductCategory($category); | |||
} | |||
} | |||
} | |||
} |
@@ -5,9 +5,16 @@ namespace Lc\ShopBundle\Services; | |||
use Cocur\Slugify\Slugify; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager; | |||
use Geocoder\Model\Coordinates; | |||
use Geocoder\Provider\Addok\Addok; | |||
use Geocoder\Query\GeocodeQuery; | |||
use Geocoder\Query\ReverseQuery; | |||
use Lc\ShopBundle\Context\ImageInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\PageInterface; | |||
use Lc\ShopBundle\Context\PointSaleInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; | |||
use Lc\ShopBundle\Context\ReminderInterface; | |||
use Lc\ShopBundle\Context\TaxRateInterface; | |||
use Lc\ShopBundle\Context\UnitInterface; | |||
@@ -15,6 +22,7 @@ use Lc\ShopBundle\Context\UserInterface; | |||
use Lc\ShopBundle\Context\UserPointSaleInterface; | |||
use Liip\ImagineBundle\Imagine\Cache\CacheManager; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\HttpClient\HttplugClient; | |||
use Symfony\Component\HttpFoundation\ParameterBag; | |||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | |||
use Symfony\Contracts\Translation\TranslatorInterface; | |||
@@ -255,6 +263,29 @@ class Utils | |||
return $result; | |||
} | |||
public function getGeocoderProvider() | |||
{ | |||
$symfonyClient = new HttplugClient(); | |||
$provider = new Addok($symfonyClient, 'https://api-adresse.data.gouv.fr') ; | |||
return $provider ; | |||
} | |||
public function callAddressApi($query) | |||
{ | |||
$provider = $this->getGeocoderProvider() ;; | |||
$query = GeocodeQuery::create($query)->withData('type', 'housenumber'); | |||
$results = $provider->geocodeQuery($query); | |||
return $results->all() ; | |||
} | |||
public function callReverseAddressApi($latitude, $longitude) | |||
{ | |||
$provider = $this->getGeocoderProvider() ;; | |||
$query = ReverseQuery::create(new Coordinates($latitude, $longitude)); | |||
$results = $provider->reverseQuery($query); | |||
return $results->all() ; | |||
} | |||
public function getZipByCity($city, $code = null) | |||
{ | |||
$zip = null; | |||
@@ -474,4 +505,47 @@ class Utils | |||
return $this->parameterBag->get('app.path.images'); | |||
} | |||
public function duplicateEntity($entity){ | |||
$newEntity = clone $entity ; | |||
if($newEntity instanceof ImageInterface){ | |||
$this->duplicateImage($entity); | |||
$newEntity->setImage(null); | |||
} | |||
if($newEntity instanceof ProductFamilyInterface){ | |||
$this->productFamilyUtils->processBeforePersistProductFamily($newEntity); | |||
} | |||
$this->em->persist($newEntity) ; | |||
$this->em->flush(); | |||
return $newEntity; | |||
} | |||
public function duplicateImage($entity, $folder = false){ | |||
$basePath = $this->parameterBag->get('kernel.project_dir').'/public/uploads/images/' ; | |||
if($entity->getImage() && file_exists($basePath.$entity->getImage())) { | |||
dump(pathinfo($basePath.$entity->getImage())); | |||
} | |||
die(); | |||
$newImage = md5(uniqid()).'.jpg'; | |||
if($folder) $newImage = $folder.'/'.$newImage; | |||
if($entity->getImage() && file_exists($basePath.$entity->getImage())) { | |||
copy($basePath.$entity->getImage(), $basePath . $newImage); | |||
$entity->setImage($newImage); | |||
}else{ | |||
$entity->setImage(null); | |||
} | |||
return $entity; | |||
} | |||
} |
@@ -8,6 +8,7 @@ use Lc\ShopBundle\Context\OrderUtilsInterface; | |||
use Lc\ShopBundle\Context\PriceUtilsInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; | |||
use Lc\ShopBundle\Context\Services\StatisticsUtilsInterface; | |||
use League\Flysystem\Util; | |||
class UtilsManager | |||
{ | |||
@@ -23,6 +24,7 @@ class UtilsManager | |||
protected $mailUtils ; | |||
protected $ticketUtils ; | |||
protected $statisticsUtils; | |||
protected $pointLocationUtils ; | |||
public function __construct( | |||
Utils $utils, | |||
@@ -35,7 +37,9 @@ class UtilsManager | |||
CreditUtils $creditUtils, | |||
DocumentUtils $documentUtils, | |||
MailUtils $mailUtils, | |||
TicketUtils $ticketUtils | |||
TicketUtils $ticketUtils, | |||
PointLocationUtils $pointLocationUtils, | |||
UtilsProcess $utilsProcess | |||
) | |||
{ | |||
$this->utils = $utils ; | |||
@@ -49,6 +53,8 @@ class UtilsManager | |||
$this->documentUtils = $documentUtils ; | |||
$this->mailUtils = $mailUtils ; | |||
$this->ticketUtils = $ticketUtils ; | |||
$this->pointLocationUtils = $pointLocationUtils ; | |||
$this->utilsProcess = $utilsProcess ; | |||
} | |||
public function getUtils(): Utils | |||
@@ -106,4 +112,14 @@ class UtilsManager | |||
return $this->ticketUtils ; | |||
} | |||
public function getPointLocationUtils(): PointLocationUtils | |||
{ | |||
return $this->pointLocationUtils ; | |||
} | |||
public function getUtilsProcess(): UtilsProcess | |||
{ | |||
return $this->utilsProcess ; | |||
} | |||
} |
@@ -0,0 +1,107 @@ | |||
<?php | |||
namespace Lc\ShopBundle\Services; | |||
use Cocur\Slugify\Slugify; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use EasyCorp\Bundle\EasyAdminBundle\Configuration\ConfigManager; | |||
use Geocoder\Model\Coordinates; | |||
use Geocoder\Provider\Addok\Addok; | |||
use Geocoder\Query\GeocodeQuery; | |||
use Geocoder\Query\ReverseQuery; | |||
use Lc\ShopBundle\Context\ImageInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\PageInterface; | |||
use Lc\ShopBundle\Context\PointSaleInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyInterface; | |||
use Lc\ShopBundle\Context\ProductFamilyUtilsInterface; | |||
use Lc\ShopBundle\Context\ReminderInterface; | |||
use Lc\ShopBundle\Context\TaxRateInterface; | |||
use Lc\ShopBundle\Context\UnitInterface; | |||
use Lc\ShopBundle\Context\UserInterface; | |||
use Lc\ShopBundle\Context\UserPointSaleInterface; | |||
use Liip\ImagineBundle\Imagine\Cache\CacheManager; | |||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||
use Symfony\Component\HttpClient\HttplugClient; | |||
use Symfony\Component\HttpFoundation\ParameterBag; | |||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | |||
use Symfony\Contracts\Translation\TranslatorInterface; | |||
class UtilsProcess | |||
{ | |||
protected $em; | |||
protected $parameterBag; | |||
protected $merchantUtils; | |||
protected $productFamilyUtils; | |||
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, ProductFamilyUtilsInterface $productFamilyUtils) | |||
{ | |||
$this->em = $em; | |||
$this->parameterBag = $parameterBag; | |||
$this->productFamilyUtils = $productFamilyUtils; | |||
} | |||
public function duplicateEntity($entity, $flush = true) | |||
{ | |||
$newEntity = clone $entity; | |||
if ($newEntity instanceof ImageInterface) { | |||
$newEntity = $this->duplicateImage($newEntity); | |||
} | |||
if ($newEntity instanceof ProductFamilyInterface) { | |||
$newEntity = $this->productFamilyUtils->processBeforePersistProductFamily($newEntity, false, true); | |||
} | |||
if(method_exists($newEntity, 'getAddress') && is_object($newEntity->getAddress())){ | |||
$address = $newEntity->getAddress(); | |||
$newAddress = $this->duplicateEntity($address); | |||
$newEntity->setAddress($newAddress); | |||
$this->em->persist($newAddress); | |||
} | |||
$this->em->persist($newEntity); | |||
if($flush){ | |||
$this->em->flush(); | |||
} | |||
return $newEntity; | |||
} | |||
public function duplicateEntityToOtherHub($entity, $hub){ | |||
$newEntity = $this->duplicateEntity($entity); | |||
if ($hub) { | |||
$newEntity->setMerchant($hub); | |||
} | |||
$this->em->persist($newEntity) ; | |||
$this->em->flush() ; | |||
return $newEntity; | |||
} | |||
public function duplicateImage($entity, $folder = false) | |||
{ | |||
$basePath = $this->parameterBag->get('kernel.project_dir') . '/public/uploads/images/'; | |||
if ($entity->getImage() && file_exists($basePath . $entity->getImage())) { | |||
$extension = (pathinfo($basePath . $entity->getImage(), PATHINFO_EXTENSION)); | |||
if ($extension == "jpg" || $extension == "png" || $extension == "gif") { | |||
$newImage = md5(uniqid()) . '.' . $extension; | |||
if ($folder) $newImage = $folder . '/' . $newImage; | |||
copy($basePath . $entity->getImage(), $basePath . $newImage); | |||
$entity->setImage($newImage); | |||
} | |||
} else { | |||
$entity->setImage(null); | |||
} | |||
return $entity; | |||
} | |||
} |