<?php
namespace App\Controller;
use App\Entity\ERPCommercialData;
use App\Entity\ERPCommercialDataLang;
use App\Entity\ERPLogisticData;
use App\Entity\File;
use App\Entity\Image;
use App\Entity\ImageLang;
use App\Entity\Product;
use App\Entity\ProductAttribute;
use App\Entity\ProductLang;
use App\Entity\PSA;
use App\Form\ProductLangType;
use App\Form\ProductType;
use App\Repository\AttributeRepository;
use App\Repository\AttributeValueRepository;
use App\Repository\ERPCommercialDataLangRepository;
use App\Repository\ERPCommercialDataRepository;
use App\Repository\ERPLogisticDataRepository;
use App\Repository\FeatureRepository;
use App\Repository\FeatureValueRepository;
use App\Repository\FileRepository;
use App\Repository\ImageLangRepository;
use App\Repository\ImageRepository;
use App\Repository\LangRepository;
use App\Repository\ProductAttributeRepository;
use App\Repository\ProductLangRepository;
use App\Repository\ProductRepository;
use App\Repository\PSARepository;
use App\Repository\SiteRepository;
use App\Services\WebserviceUtils;
use Attribute;
use CURLFile;
use DateTime;
use Doctrine\ORM\EntityManager;
use Doctrine\Persistence\ManagerRegistry;
use PrestaShopWebservice;
use PrestaShopWebserviceException;
use Psr\Log\LoggerInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
use Symfony\Component\Security\Core\Security;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\File\Exception\FileException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\String\Slugger\SluggerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
#[Route('/product', name: 'app_product')]
#[IsGranted('ROLE_CONTENT_MANAGER')]
class ProductController extends AbstractController
{
public $twigData;
public $breadcrumb = [];
public $translator;
public $security;
public $em;
public function __construct(Security $security, TranslatorInterface $translator, ManagerRegistry $doctrine)
{
$this->twigData = [];
$this->translator = $translator;
$this->security = $security;
$this->twigData = [
'user' => $security->getUser(),
];
$this->em = $doctrine->getManager();
}
#[Route('/', name: '_index')]
public function index(LangRepository $langRepository, ProductRepository $productRepository, ProductLangRepository $productLangRepository, SiteRepository $siteRepository): Response
{
$this->breadcrumb[0]['name'] = $this->translator->trans('page.catalog.Catalog');
$this->breadcrumb[0]['link'] = $this->generateUrl('app_catalog_index');
$this->breadcrumb[0]['last'] = false;
$this->breadcrumb[1]['name'] = $this->translator->trans('page.product.Products');
$this->breadcrumb[1]['last'] = true;
$this->twigData['breadcrumb'] = $this->breadcrumb;
$langs = $langRepository->findAll();
$products = $productRepository->findBy([], ['id' => 'ASC']);
foreach ($products as $keyProduct => $product) {
$productLangs = $product->getProductLangs();
foreach ($productLangs as $keyProductLang => $productLang) {
$productLang->setProgression($productLang->calculateProgression());
$productLangRepository->add($productLang);
}
}
$this->em->flush();
$langsPercent = [];
foreach ($langs as $keyLang => $lang) {
$langsPercent[$keyLang]['lang'] = $lang;
}
$this->twigData['langs'] = $langs;
$this->twigData['products'] = $products;
$this->twigData['sites'] = $siteRepository->findAll();
$user = $this->security->getUser();
$userInterfaceLang = $user->getInterfaceLang();
$this->twigData['userInterfaceLang'] = $userInterfaceLang;
return $this->render('product/index.html.twig', $this->twigData);
}
#[Route('/new', name: '_new')]
public function new(LangRepository $langRepository, Request $request, ProductRepository $productRepository, ProductLangRepository $productLangRepository): Response
{
$this->breadcrumb[0]['name'] = $this->translator->trans('page.catalog.Catalog');
$this->breadcrumb[0]['link'] = $this->generateUrl('app_catalog_index');
$this->breadcrumb[0]['last'] = false;
$this->breadcrumb[1]['name'] = $this->translator->trans('page.product.Products');
$this->breadcrumb[1]['link'] = $this->generateUrl('app_product_index');
$this->breadcrumb[1]['last'] = false;
$this->breadcrumb[2]['name'] = $this->translator->trans('page.product.new');
$this->breadcrumb[2]['last'] = true;
$this->twigData['breadcrumb'] = $this->breadcrumb;
$step = $request->query->get('step');
$this->twigData['step'] = $step;
$product = new Product();
$formProduct = $this->createForm(ProductType::class, $product);
$formProduct->handleRequest($request);
$this->twigData['formProduct'] = $formProduct->createView();
$langs = $langRepository->findAll();
$formsProductLang = [];
foreach ($langs as $keyLangs => $lang) {
$productLang = new ProductLang();
$productLang->setLang($lang);
$formProductLang = $this->createForm(ProductLangType::class, $productLang);
$formProductLang->handleRequest($request);
$formsProductLang[$lang->getId()]['form'] = $formProductLang;
$formsProductLang[$lang->getId()]['view'] = $formProductLang->createView();
$formsProductLang[$lang->getId()]['entity'] = $productLang;
}
if ($formProduct->isSubmitted() && $formProduct->isValid()) {
// Retrive datas from lang form
$productLangs = $request->request->getIterator();
$productLangs = $productLangs['product_lang'];
$names = $productLangs['name'];
$descriptions = $productLangs['description'];
$regulations = $productLangs['regulations'];
$shortDescriptions = $productLangs['short_description'];
$subTitles = $productLangs['sub_title'];
$advices = $productLangs['advices'];
$metaTitles = $productLangs['meta_title'];
$metaDescriptions = $productLangs['meta_description'];
// Assign datas to productLang
foreach ($formsProductLang as $lang_id => $formProductLang) {
$name = $names[$lang_id];
$description = $descriptions[$lang_id];
$regulation = $regulations[$lang_id];
$advice = $advices[$lang_id];
$subTitle = $subTitles[$lang_id];
$shortDescription = $shortDescriptions[$lang_id];
$metaTitle = $metaTitles[$lang_id];
$metaDescription = $metaDescriptions[$lang_id];
$formProductLang['entity']->setProduct($product);
$formProductLang['entity']->setName($name);
$formProductLang['entity']->setDescription($description);
$formProductLang['entity']->setRegulations($regulation);
$formProductLang['entity']->setAdvices($advice);
$formProductLang['entity']->setSubTitle($subTitle);
$formProductLang['entity']->setShortDescription($shortDescription);
$formProductLang['entity']->setMetaTitle($metaTitle);
$formProductLang['entity']->setMetaDescription($metaDescription);
$formProductLang['entity']->setProgression($formProductLang['entity']->calculateProgression());
$productLangRepository->add($formProductLang['entity']);
}
$productRepository->add($product, true);
return $this->redirectToRoute('app_product_edit', ['id' => $product->getId()]);
}
$this->twigData['formsProductLang'] = $formsProductLang;
$this->twigData['langs'] = $langs;
return $this->render('product/new.html.twig', $this->twigData);
}
#[Route('/all/edit', name: '_all_edit')]
public function allEdit(FileRepository $fileRepository, LangRepository $langRepository, Request $request, ProductRepository $productRepository, ProductLangRepository $productLangRepository, AttributeRepository $attributeRepository, ProductAttributeRepository $productAttributeRepository, FeatureRepository $featureRepository, FeatureValueRepository $featureValueRepository): Response
{
$products = $productRepository->findAll();
$langs = $langRepository->findAll();
foreach ($products as $product) {
foreach ($langs as $keyLangs => $lang) {
$productLang = $productLangRepository->findOneBy(['lang' => $lang, 'product' => $product]);
if ($productLang != null) {
$productLang->setProgression($productLang->calculateProgression());
$productLangRepository->add($productLang);
// if ($productLang->getRegulations() != null && json_decode($productLang->getRegulations()) == null) {
// $newRegulation = json_decode(json_encode($productLang->getRegulations()));
// $startHtml = strpos($newRegulation, '"html","data":{"html":');
// }
if ($productLang->getDescription() != null && json_decode($productLang->getDescription()) == null) {
$newDescription = [
"time" => 1675328680884,
"blocks" => [
[
"id" => "9dCJlykOTY",
"type" => "html",
"data" => [
"html" => $productLang->getDescription()
]
]
],
"version" => "2.26.4"
];
// $newDescription = '{"time":1675328680884,"blocks":[{"id":"9dCJlykOTY","type":"html","data":{"html":"'.$descriptionEncode. '"}}],"version":"2.26.4"}';
$newDescription = json_encode($newDescription);
$productLang->setDescription($newDescription);
}
if ($productLang->getShortDescription() != null && json_decode($productLang->getShortDescription()) == null) {
$newDescription = [
"time" => 1675328680884,
"blocks" => [
[
"id" => "9dCJlykOTY",
"type" => "html",
"data" => [
"html" => $productLang->getShortDescription()
]
]
],
"version" => "2.26.4"
];
// $newDescription = '{"time":1675328680884,"blocks":[{"id":"9dCJlykOTY","type":"html","data":{"html":"'.$descriptionEncode. '"}}],"version":"2.26.4"}';
$newDescription = json_encode($newDescription);
$productLang->setShortDescription($newDescription);
}
if ($productLang->getAdvices() != null && json_decode($productLang->getAdvices()) == null) {
$newAdvices = [
"time" => 1675328680884,
"blocks" => [
[
"id" => "9dCJlykOTY",
"type" => "html",
"data" => [
"html" => $productLang->getAdvices()
]
]
],
"version" => "2.26.4"
];
// $newAdvices = '{"time":1675328680884,"blocks":[{"id":"9dCJlykOTY","type":"html","data":{"html":"'.$descriptionEncode. '"}}],"version":"2.26.4"}';
$newAdvices = json_encode($newAdvices);
$productLang->setAdvices($newAdvices);
}
if ($productLang->getRegulations() != null && json_decode($productLang->getRegulations()) == null) {
$newRegulation = [
"time" => 1675328680884,
"blocks" => [
[
"id" => "9dCJlykOTY",
"type" => "html",
"data" => [
"html" => $productLang->getRegulations()
]
]
],
"version" => "2.26.4"
];
// $newRegulation = '{"time":1675328680884,"blocks":[{"id":"9dCJlykOTY","type":"html","data":{"html":"'.$descriptionEncode. '"}}],"version":"2.26.4"}';
$newRegulation = json_encode($newRegulation);
$productLang->setRegulations($newRegulation);
}
$productLangRepository->add($productLang);
}
$this->em->flush();
}
}
return $this->redirectToRoute('app_product_index');
}
#[Route('/{id}/edit', name: '_edit')]
public function edit(Product $product, SiteRepository $siteRepository, ERPLogisticDataRepository $ERPLogisticDataRepository, ERPCommercialDataRepository $ERPCommercialDataRepository, ERPCommercialDataLangRepository $ERPCommercialDataLangRepository, FileRepository $fileRepository, LangRepository $langRepository, Request $request, ProductRepository $productRepository, ProductLangRepository $productLangRepository, AttributeRepository $attributeRepository, ProductAttributeRepository $productAttributeRepository, FeatureRepository $featureRepository, FeatureValueRepository $featureValueRepository): Response
{
$this->breadcrumb[0]['name'] = $this->translator->trans('page.catalog.Catalog');
$this->breadcrumb[0]['link'] = $this->generateUrl('app_catalog_index');
$this->breadcrumb[0]['last'] = false;
$this->breadcrumb[1]['name'] = $this->translator->trans('page.product.Products');
$this->breadcrumb[1]['link'] = $this->generateUrl('app_product_index');
$this->breadcrumb[1]['last'] = false;
$this->breadcrumb[2]['name'] = $this->translator->trans('page.product.edit');
$this->breadcrumb[2]['last'] = true;
$this->twigData['breadcrumb'] = $this->breadcrumb;
$step = $request->query->get('step');
$this->twigData['step'] = $step;
$formProduct = $this->createForm(ProductType::class, $product);
$formProduct->handleRequest($request);
$user = $this->security->getUser();
$userInterfaceLang = $user->getInterfaceLang();
$attributes = $attributeRepository->findAll();
$attributesDatas = [];
$attributesValuesDatas = [];
foreach ($attributes as $keyAttribute => $attribute) {
$attributesDatas[$attribute->getId()] = [
'id' => $attribute->getId(),
];
$attributeLangs = $attribute->getAttributeLang();
foreach ($attributeLangs as $keyAttributeLang => $attributeLang) {
if ($attributeLang->getLang() == $userInterfaceLang) {
$attributesDatas[$attribute->getId()]['value'] = $attributeLang->getName();
$attributesDatas[$attribute->getId()]['label'] = $attributeLang->getName();
}
}
$attributeValues = $attribute->getAttributeValues();
foreach ($attributeValues as $keyAttributeValue => $attributeValue) {
$attributesValuesDatas[$attribute->getId() . "-" . $attributeValue->getId()]['value'] = $attributeValue->getId();
$attributeValueLang = $attributeValue->getAttributeValueLangs();
foreach ($attributeValueLang as $keyAttributeValueLang => $attributeValueLang) {
if ($attributeValueLang->getLang() == $userInterfaceLang) {
$attributesValuesDatas[$attribute->getId() . "-" . $attributeValue->getId()]['name'] = $attributeValueLang->getValue();
$attributesValuesDatas[$attribute->getId() . "-" . $attributeValue->getId()]['class'] = $attributesDatas[$attribute->getId()]['label'];
}
}
}
}
$this->twigData['formProduct'] = $formProduct->createView();
$this->twigData['product'] = $product;
$this->twigData['attributes'] = $attributes;
$this->twigData['userInterfaceLang'] = $userInterfaceLang;
$this->twigData['files'] = $fileRepository->findAll();
$this->twigData['attributesDatas'] = json_encode($attributesDatas);
$this->twigData['attributesValuesDatas'] = json_encode($attributesValuesDatas);
$this->twigData['sites'] = $siteRepository->findAll();
//ERP
$productErp = [];
$productLogisticErp = $product->getERPLogisticData();
$productCommercialErp = $product->getERPCommercialData();
$productErp['logistic'] = $productLogisticErp;
$productErp['commercial'] = $productCommercialErp;
$this->twigData['productErp'] = $productErp;
$langs = $langRepository->findAll();
$formsProductLang = [];
foreach ($langs as $keyLangs => $lang) {
$productLang = $productLangRepository->findOneBy(['lang' => $lang, 'product' => $product]);
if ($productLang == null) {
$productLang = new ProductLang();
$productLang->setProduct($product);
$productLang->setLang($lang);
$productLang->setProgression(0);
$productLangRepository->add($productLang, true);
} else {
if ($productLang->getRegulations() != null && json_decode($productLang->getRegulations()) == null) {
$newRegulation = json_decode(json_encode($productLang->getRegulations()));
$startHtml = strpos($newRegulation, '"html","data":{"html":');
}
if ($productLang->getDescription() != null && json_decode($productLang->getDescription()) == null) {
$newDescription = [
"time" => 1675328680884,
"blocks" => [
[
"id" => "9dCJlykOTY",
"type" => "html",
"data" => [
"html" => $productLang->getDescription()
]
]
],
"version" => "2.26.4"
];
// $newDescription = '{"time":1675328680884,"blocks":[{"id":"9dCJlykOTY","type":"html","data":{"html":"'.$descriptionEncode. '"}}],"version":"2.26.4"}';
$newDescription = json_encode($newDescription);
$productLang->setDescription($newDescription);
}
if ($productLang->getShortDescription() != null && json_decode($productLang->getShortDescription()) == null) {
$newDescription = [
"time" => 1675328680884,
"blocks" => [
[
"id" => "9dCJlykOTY",
"type" => "html",
"data" => [
"html" => $productLang->getShortDescription()
]
]
],
"version" => "2.26.4"
];
// $newDescription = '{"time":1675328680884,"blocks":[{"id":"9dCJlykOTY","type":"html","data":{"html":"'.$descriptionEncode. '"}}],"version":"2.26.4"}';
$newDescription = json_encode($newDescription);
$productLang->setShortDescription($newDescription);
}
if ($productLang->getAdvices() != null && json_decode($productLang->getAdvices()) == null) {
$newAdvices = [
"time" => 1675328680884,
"blocks" => [
[
"id" => "9dCJlykOTY",
"type" => "html",
"data" => [
"html" => $productLang->getAdvices()
]
]
],
"version" => "2.26.4"
];
// $newAdvices = '{"time":1675328680884,"blocks":[{"id":"9dCJlykOTY","type":"html","data":{"html":"'.$descriptionEncode. '"}}],"version":"2.26.4"}';
$newAdvices = json_encode($newAdvices);
$productLang->setAdvices($newAdvices);
}
if ($productLang->getRegulations() != null && json_decode($productLang->getRegulations()) == null) {
$newRegulation = [
"time" => 1675328680884,
"blocks" => [
[
"id" => "9dCJlykOTY",
"type" => "html",
"data" => [
"html" => $productLang->getRegulations()
]
]
],
"version" => "2.26.4"
];
// $newRegulation = '{"time":1675328680884,"blocks":[{"id":"9dCJlykOTY","type":"html","data":{"html":"'.$descriptionEncode. '"}}],"version":"2.26.4"}';
$newRegulation = json_encode($newRegulation);
$productLang->setRegulations($newRegulation);
}
}
$productLang->setProgression($productLang->calculateProgression());
$formProductLang = $this->createForm(ProductLangType::class, $productLang);
$formsProductLang[$lang->getId()]['form'] = $formProductLang;
$formsProductLang[$lang->getId()]['view'] = $formProductLang->createView();
$formsProductLang[$lang->getId()]['entity'] = $productLang;
$formProductLang->handleRequest($request);
}
$productCommercialErp = $ERPCommercialDataRepository->findOneBy(['product' => $product]);
$productLogisticErp = $ERPLogisticDataRepository->findOneBy(['product' => $product]);
if ($productCommercialErp == null) {
$productCommercialErp = new ERPCommercialData();
$productCommercialErp->setProduct($product);
}
if ($productLogisticErp == null) {
$productLogisticErp = new ERPLogisticData();
$productLogisticErp->setProduct($product);
}
$this->twigData['productCommercialErp'] = $productCommercialErp;
$this->twigData['productLogisticErp'] = $productLogisticErp;
if ($formProduct->isSubmitted() && $formProduct->isValid()) {
// ERP
// -- commercial
// $productCommercialErpDatas = $request->request->getIterator();
// dd($productCommercialErpDatas);
// $productCommercialErpDatas = $productCommercialErpDatas['product_erpCommercial'];
// $productCommercialErp = $ERPCommercialDataRepository->findOneBy(['product' => $product]);
// if ($productCommercialErp == null) {
// $productCommercialErp = new ERPCommercialData();
// $productCommercialErp->setProduct($product);
// }
// $productCommercialErp->setManufacturer($productCommercialErpDatas['manufacturer']);
// $productCommercialErp->setBrand($productCommercialErpDatas['brand']);
// $productCommercialErp->setProductRange($productCommercialErpDatas['productRange']);
// $productCommercialErp->setCommercialReference($productCommercialErpDatas['commercialReference']);
// $productCommercialErp->setProductReference($productCommercialErpDatas['productReference']);
// $productCommercialErp->setinfoReference($productCommercialErpDatas['infoReference']);
// $productCommercialErp->setGTIN13($productCommercialErpDatas['GTIN13']);
// $productCommercialErp->setDateTarif($productCommercialErpDatas['dateTarif']);
// $productCommercialErp->setPriceWithoutTax($productCommercialErpDatas['priceWithoutTax']);
// $productCommercialErp->setDistributorPriceWithoutTax($productCommercialErpDatas['distributorPriceWithoutTax']);
// $productCommercialErp->setCurrency($productCommercialErpDatas['currency']);
// $productCommercialErp->setVat($productCommercialErpDatas['vat']);
// $productCommercialErp->setQuantity($productCommercialErpDatas['quantity']);
// $productCommercialErp->setBaseReferenceUnit($productCommercialErpDatas['baseReferenceUnit']);
// $productCommercialErp->setMinimalOrderQuantity($productCommercialErpDatas['minimalOrderQuantity']);
// $productCommercialErp->setMultiplePerOrder($productCommercialErpDatas['multiplePerOrder']);
// $productCommercialErp->setPackagingQtyMin($productCommercialErpDatas['packagingQtyMin']);
// $productCommercialErp->setManufacturerStoredProduct($productCommercialErpDatas['manufacturerStoredProduct']);
// $productCommercialErp->setDeliveryDelay($productCommercialErpDatas['deliveryDelay']);
// $productCommercialErp->setElectronicDataInterchange($productCommercialErpDatas['electronicDataInterchange']);
// $productCommercialErp->setWarrantyDuration($productCommercialErpDatas['warrantyDuration']);
// $productCommercialErp->setReferenceStatus($productCommercialErpDatas['referenceStatus']);
// $productCommercialErp->setTaric($productCommercialErpDatas['taric']);
// $productCommercialErp->setProductHeight($productCommercialErpDatas['productHeight']);
// $productCommercialErp->setProductHeightUnity($productCommercialErpDatas['productHeightUnity']);
// $productCommercialErp->setProductWidth($productCommercialErpDatas['productWidth']);
// $productCommercialErp->setProductWidthUnity($productCommercialErpDatas['productWidthUnity']);
// $productCommercialErp->setProductDepth($productCommercialErpDatas['productDepth']);
// $productCommercialErp->setProductDepthUnity($productCommercialErpDatas['productDepthUnity']);
// $productCommercialErp->setProductWeight($productCommercialErpDatas['productWeight']);
// $productCommercialErp->setProductWeightUnity($productCommercialErpDatas['productWeightUnity']);
// $productCommercialErp->setProductDiameter($productCommercialErpDatas['productDiameter']);
// $productCommercialErp->setProductDiameterUnity($productCommercialErpDatas['productDiameterUnity']);
// $productCommercialErp->setRecommendedStorageLimitDuration($productCommercialErpDatas['RecommendedStorageLimitDuration']);
// // -- commercial lang
// $productCommercialErpLangDatas = $productCommercialErpDatas['product_erpCommercial_lang'];
// foreach ($langs as $keyLangs => $lang) {
// $lang = $langRepository->find($lang->getId());
// $productCommercialErpLang = $ERPCommercialDataLangRepository->findOneBy(['lang' => $lang, 'product' => $product]);
// if ($productCommercialErpLang == null) {
// $productCommercialErpLang = new ERPCommercialDataLang();
// $productCommercialErpLang->setLang($lang);
// $productCommercialErpLang->setProduct($product);
// $productCommercialErpLang->setERPCommercialData($productCommercialErp);
// }
// $productCommercialErpLang->setWording30($productCommercialErpLangDatas['wording30'][$lang->getId()]);
// $productCommercialErpLang->setWording80($productCommercialErpLangDatas['wording80'][$lang->getId()]);
// $productCommercialErpLang->setWording240($productCommercialErpLangDatas['wording240'][$lang->getId()]);
// $ERPCommercialDataLangRepository->add($productCommercialErpLang);
// }
// $ERPCommercialDataRepository->add($productCommercialErp, true);
// // -- logistic
// $productLogisticErpDatas = $request->request->getIterator();
// $productLogisticErpDatas = $productLogisticErpDatas['product_erp_logistic'];
// $productLogisticErp = $ERPLogisticDataRepository->findOneBy(['product' => $product]);
// if ($productLogisticErp == null) {
// $productLogisticErp = new ERPLogisticData();
// $productLogisticErp->setProduct($product);
// }
// $productLogisticErp->setBrand($productLogisticErpDatas['brand']);
// $productLogisticErp->setCommercialReference($productLogisticErpDatas['commercialReference']);
// $productLogisticErp->setQuantity($productLogisticErpDatas['quantity']);
// $productLogisticErp->setGTIN14($productLogisticErpDatas['GTIN14']);
// $productLogisticErp->setProductHeight($productLogisticErpDatas['productHeight']);
// $productLogisticErp->setProductHeightUnity($productLogisticErpDatas['productHeightUnity']);
// $productLogisticErp->setProductWidth($productLogisticErpDatas['productWidth']);
// $productLogisticErp->setProductWidthUnity($productLogisticErpDatas['productWidthUnity']);
// $productLogisticErp->setProductDepth($productLogisticErpDatas['productDepth']);
// $productLogisticErp->setProductDepthUnity($productLogisticErpDatas['productDepthUnity']);
// $productLogisticErp->setProductWeight($productLogisticErpDatas['productWeight']);
// $productLogisticErp->setProductWeightUnity($productLogisticErpDatas['productWeightUnity']);
// $productLogisticErp->setProductDiameter($productLogisticErpDatas['productDiameter']);
// $productLogisticErp->setProductDiameterUnity($productLogisticErpDatas['productDiameterUnity']);
// $productLogisticErp->setProductVolume($productLogisticErpDatas['productVolume']);
// $productLogisticErp->setProductVolumeUnity($productLogisticErpDatas['productVolumeUnity']);
// $productLogisticErp->setDeposit($productLogisticErpDatas['deposit']);
// $productLogisticErp->setStackingLimitCount($productLogisticErpDatas['stackingLimitCount']);
// $ERPLogisticDataRepository->add($productLogisticErp, true);
$files = $request->request->getIterator();
$currentFiles = $product->getFiles();
foreach ($currentFiles as $keyCurrentFile => $currentFile) {
$product->removeFile($currentFile);
}
if (isset($files['productFile'])) {
$files = $files['productFile'];
foreach ($files as $keyFiles => $file) {
$file = $fileRepository->find($file);
$product->addFile($file);
}
}
$productLangs = $request->request->getIterator();
$productLangs = $productLangs['product_lang'];
$names = $productLangs['name'];
$descriptions = $productLangs['description'];
$regulations = $productLangs['regulations'];
$advices = $productLangs['advices'];
$shortDescriptions = $productLangs['short_description'];
$subTitles = $productLangs['sub_title'];
$metaTitles = $productLangs['meta_title'];
$metaDescriptions = $productLangs['meta_description'];
$currentProductFeatures = $product->getFeatureValues();
foreach ($currentProductFeatures as $keyCurrentProductFeature => $currentProductFeature) {
$product->removeFeatureValue($currentProductFeature);
}
$formProductFeatures = $request->request->all('features');
if (count($formProductFeatures) > 0) {
foreach ($formProductFeatures as $keyProductFeatures => $formProductFeature) {
$productFeatureValue = $featureValueRepository->find($formProductFeature['value']);
if ($productFeatureValue) {
$product->addFeatureValue($productFeatureValue);
}
}
}
foreach ($formsProductLang as $lang_id => $formProductLang) {
$lang = $langRepository->find($lang_id);
$name = $names[$lang_id];
$description = $descriptions[$lang_id];
$regulation = $regulations[$lang_id];
$advice = $advices[$lang_id];
$shortDescription = $shortDescriptions[$lang_id];
$subTitle = $subTitles[$lang_id];
$metaTitle = $metaTitles[$lang_id];
$metaDescription = $metaDescriptions[$lang_id];
$productLang = $productLangRepository->findOneBy(['lang' => $lang, 'product' => $product]);
if ($productLang == false) {
$productLang = new ProductLang();
$productLang->setLang($lang);
$productLang->setProduct($product);
}
$productLang->setName($name);
$productLang->setDescription($description);
$productLang->setRegulations($regulation);
$productLang->setAdvices($advice);
$productLang->setMetaTitle($metaTitle);
$productLang->setMetaDescription($metaDescription);
$productLang->setSubTitle($subTitle);
$productLang->setShortDescription($shortDescription);
$productLang->setProgression($productLang->calculateProgression());
$productLangRepository->add($productLang);
}
$productRepository->add($product, true);
$stay = $request->request->get('stay');
if ($stay == '1') {
$redirectUrl = $this->generateUrl('app_product_edit', ['id' => $product->getId()]);
if ($step != null) {
$redirectUrl .= '?step=' . $step;
}
return $this->redirect($redirectUrl);
}
return $this->redirectToRoute('app_product_index');
}
$this->twigData['formsProductLang'] = $formsProductLang;
$features = $featureRepository->findAll();
$this->twigData['features'] = $features;
$productAttributes = $productAttributeRepository->findBy(['product' => $product]);
$this->twigData['productAttributes'] = $productAttributes;
$this->twigData['langs'] = $langs;
return $this->render('product/edit.html.twig', $this->twigData);
}
#[Route('/{id}/generate-combination', name: '_generateCombination')]
public function generateCombination(Product $product, LangRepository $langRepository, Request $request, ProductAttributeRepository $productAttributeRepository, ProductRepository $productRepository, AttributeValueRepository $attributeValueRepository, AttributeRepository $attributeRepository): Response
{
$requestBody = [];
if ($content = $request->getContent()) {
$requestBody = json_decode($content, true);
}
if (count($requestBody) > 0) {
$attributeValues = $requestBody['attribute'];
// Make groups by attribute values
$attributeGroups = [];
foreach ($attributeValues as $keyAttributeValue => $attributeValueId) {
$attributeValue = $attributeValueRepository->find($attributeValueId);
$attributeGroups[$attributeValue->getAttribute()->getId()][] = $attributeValueId;
}
// Make attribute id string (like 1-3-4). Numbers are attribute ids
$builderStrings = [];
$i = 0;
foreach ($attributeGroups as $keyAttributeGroup => $attributeGroup) {
foreach ($attributeGroup as $key => $attributeValue) {
if ($i > 0) {
foreach ($builderStrings[$i - 1] as $keyString => $string) {
$builderStrings[$i][] = $string . '-' . $attributeValue;
}
} else {
$builderStrings[$i][] = $attributeValue;
}
}
$i += 1;
}
$builderStrings = $builderStrings[$i - 1];
$productAttributes = $productAttributeRepository->findBy(['product' => $product]);
$existingStrings = [];
foreach ($productAttributes as $keyProductAttribute => $productAttribute) {
$existingStrings[$keyProductAttribute] = "";
foreach ($productAttribute->getAttributeValues() as $keyProductAttributeAttributeValue => $productAttributeAttributeValue) {
if (count($productAttribute->getAttributeValues()) - 1 == $keyProductAttributeAttributeValue) {
$existingStrings[$keyProductAttribute] .= $productAttributeAttributeValue->getId();
} else {
$existingStrings[$keyProductAttribute] .= $productAttributeAttributeValue->getId() . "-";
}
}
}
foreach ($builderStrings as $keyAttributesIds => $attributesIds) {
if (!in_array($attributesIds, $existingStrings)) {
$ids = explode('-', $attributesIds);
$productAttribute = new ProductAttribute();
$productAttribute->setProduct($product);
$productAttribute->setDefaultOn(0);
$productAttributeRepository->add($productAttribute, false);
foreach ($ids as $keyId => $id) {
$attributeValue = $attributeValueRepository->find($id);
$productAttribute->addAttributeValue($attributeValue);
}
}
}
$this->em->flush();
$productAttributes = $productAttributeRepository->findBy(['product' => $product]);
$this->twigData['productAttributes'] = $productAttributes;
$this->twigData['product'] = $product;
$user = $this->security->getUser();
$userInterfaceLang = $user->getInterfaceLang();
$this->twigData['userInterfaceLang'] = $userInterfaceLang;
$html = $this->renderForm("product/_combinationList.html.twig", $this->twigData);
return $this->json(['code' => 200, 'html' => $html->getContent()]);
}
return $this->json(['code' => 200]);
}
#[Route('/{id}/delete-combinations', name: '_deleteCombinations')]
public function deleteCombinations(Product $product, LangRepository $langRepository, Request $request, ProductAttributeRepository $productAttributeRepository, ProductRepository $productRepository, AttributeValueRepository $attributeValueRepository, AttributeRepository $attributeRepository): Response
{
$productAttributes = $product->getProductAttributes();
foreach ($productAttributes as $keyProductAttribute => $productAttribute) {
$productAttributeRepository->remove($productAttribute, false);
}
$this->em->flush();
$productAttributes = $productAttributeRepository->findBy(['product' => $product]);
$this->twigData['productAttributes'] = $productAttributes;
$this->twigData['product'] = $product;
$user = $this->security->getUser();
$userInterfaceLang = $user->getInterfaceLang();
$this->twigData['userInterfaceLang'] = $userInterfaceLang;
$html = $this->renderForm("product/_combinationList.html.twig", $this->twigData);
return $this->json(['code' => 200, 'html' => $html->getContent()]);
}
#[Route('/{id}/delete', name: '_delete', methods: ['POST'])]
public function delete(Product $product, LangRepository $langRepository, ImageRepository $imageRepository, ProductAttributeRepository $productAttributeRepository, FileRepository $fileRepository, Request $request, ProductRepository $productRepository, ProductLangRepository $productLangRepository): Response
{
if ($this->isCsrfTokenValid('delete' . $product->getId(), $request->request->get('_token'))) {
$productLangs = $productLangRepository->findBy(['product' => $product]);
foreach ($productLangs as $key => $productLang) {
$productLangRepository->remove($productLang);
}
foreach ($product->getImage() as $keyProductImage => $productImage) {
foreach ($productImage->getImageLangs() as $keyImageLang => $imageLang) {
$productImage->removeImageLang($imageLang);
}
$product->removeImage($productImage);
$pathToFile = $this->getParameter('product_image_directory') . '/' . $productImage->getName();
if (file_exists($pathToFile)) {
unlink($pathToFile);
}
$imageRepository->remove($productImage);
}
foreach ($product->getProductAttributes() as $keyProductAttributes => $productAttributes) {
$product->removeProductAttribute($productAttributes);
$productAttributeRepository->remove($productAttributes);
}
$productRepository->remove($product, true);
}
return $this->redirectToRoute('app_product_index', [], Response::HTTP_SEE_OTHER);
}
#[Route('/delete', name: '_delete_multiple', methods: ['POST'])]
public function deleteMultiple(Request $request, ProductRepository $productRepository, ImageRepository $imageRepository, ProductAttributeRepository $productAttributeRepository, ProductLangRepository $productLangRepository): Response
{
$idsData = $request->request->all();
$ids = $idsData['itemDelete'];
foreach ($ids as $key => $id) {
$product = $productRepository->find($id);
$productLangs = $productLangRepository->findBy(['product' => $product]);
foreach ($productLangs as $key => $productLang) {
$productLangRepository->remove($productLang);
}
foreach ($product->getImage() as $keyProductImage => $productImage) {
foreach ($productImage->getImageLangs() as $keyImageLang => $imageLang) {
$productImage->removeImageLang($imageLang);
}
$product->removeImage($productImage);
$pathToFile = $this->getParameter('product_image_directory') . '/' . $productImage->getName();
if (file_exists($pathToFile)) {
unlink($pathToFile);
}
$imageRepository->remove($productImage);
}
foreach ($product->getProductAttributes() as $keyProductAttributes => $productAttributes) {
$product->removeProductAttribute($productAttributes);
$productAttributeRepository->remove($productAttributes);
}
$productRepository->remove($product, true);
}
//return json
return $this->json(['code' => 200]);
}
#[Route('/{id}/add/image', name: '_add_image', methods: ['POST'])]
public function addImage(Product $product, LangRepository $langRepository, Request $request, SluggerInterface $slugger, ImageRepository $imageRepository, ImageLangRepository $imageLangRepository): Response
{
$file = $request->files->get('file');
if ($file) {
$originalFilename = pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME);
// this is needed to safely include the file name as part of the URL
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename . '-' . uniqid() . '.' . $file->guessExtension();
$productImage = $product->getImage();
$imagePosition = count($productImage) + 1;
$langs = $langRepository->findAll();
// Move the file to the directory where product image are stored
try {
$file->move(
$this->getParameter('product_image_directory'),
$newFilename
);
$image = new Image();
$image->setName($newFilename);
$image->setProduct($product);
$image->setPosition($imagePosition);
if (count($productImage) == 0) {
$image->setCover(true);
} else {
$image->setCover(false);
}
foreach ($langs as $key => $lang) {
$imageLang = new ImageLang();
$imageLang->setLang($lang);
$imageLang->setImage($image);
$imageLang->setDescription('');
$image->addImageLang($imageLang);
$imageLangRepository->add($imageLang, false);
}
$imageRepository->add($image, true);
return $this->json(['code' => 200, 'message' => "Image added"]);
} catch (FileException $e) {
return new Response($e, Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
}
#[Route('/{id}/image/html', name: '_html_image', methods: ['POST'])]
public function getHtmlImage(Product $product): Response
{
$this->twigData['product'] = $product;
$html = $this->renderForm("product/_imageList.html.twig", $this->twigData);
return $this->json(['code' => 200, 'html' => $html->getContent()]);
}
#[Route('/{id}/save/image', name: '_save_image', methods: ['POST'])]
public function saveImage(Product $product, Request $request, LangRepository $langRepository, SluggerInterface $slugger, ImageLangRepository $imageLangRepository, ImageRepository $imageRepository): Response
{
$formData = $request->request->all();
$descriptions = $formData['description'];
$descriptions = json_decode($descriptions, true);
$imageId = $request->request->get("imageId");
$image = $imageRepository->find($imageId);
foreach ($descriptions as $langId => $description) {
$lang = $langRepository->find($langId);
$imageLang = $imageLangRepository->findOneBy(['image' => $image, 'lang' => $lang]);
if ($imageLang) {
$imageLang->setDescription($description);
$imageLangRepository->add($imageLang, false);
} else {
$imageLang = new ImageLang();
$imageLang->setLang($lang);
$imageLang->setImage($image);
$imageLang->setDescription($description);
$image->addImageLang($imageLang);
$imageLangRepository->add($imageLang, false);
}
}
$image->setCover($request->request->get('cover'));
$imageRepository->add($image, true);
$imagesCover = $imageRepository->findBy(['cover' => 1, "product" => $product]);
if (count($imagesCover) > 0) {
if ($image->isCover()) {
foreach ($imagesCover as $key => $imageCover) {
if ($imageCover->getId() != $image->getId()) {
$imageCover->setCover(0);
$imageRepository->add($imageCover, true);
}
}
}
} else {
$firstImages = $imageRepository->findOneBy(["product" => $product]);
$firstImages->setCover(1);
$imageRepository->add($firstImages, true);
}
$this->twigData['product'] = $product;
$html = $this->renderForm("product/_imageList.html.twig", $this->twigData);
return $this->json(['code' => 200, 'html' => $html->getContent()]);
}
#[Route('/{id}/remove/image', name: '_remove_image', methods: ['POST'])]
public function removeImage(Product $product, Request $request, ImageLangRepository $imageLangRepository, SluggerInterface $slugger, ImageRepository $imageRepository, LoggerInterface $logger): Response
{
$imageId = $request->request->get("imageId");
$image = $imageRepository->find($imageId);
$pathToFile = $this->getParameter('product_image_directory') . '/' . $image->getName();
if (file_exists($pathToFile)) {
unlink($pathToFile);
}
//delete all image lang
$imageLangs = $image->getImageLangs();
foreach ($imageLangs as $key => $imageLang) {
$imageLangRepository->remove($imageLang);
$image->removeImageLang($imageLang);
}
$imageRepository->remove($image, true);
$imagesCover = $imageRepository->findBy(['cover' => 1, "product" => $product]);
if (count($imagesCover) == 0) {
$firstImages = $imageRepository->findOneBy(["product" => $product]);
if ($firstImages->getName() != "") {
$firstImages->setCover(1);
$imageRepository->add($firstImages, true);
}
}
$this->twigData['product'] = $product;
$html = $this->renderForm("product/_imageList.html.twig", $this->twigData);
return $this->json(['code' => 200, 'html' => $html->getContent()]);
}
#[Route('/{id}/file/html', name: '_html_file', methods: ['POST'])]
public function getHtmlFile(Product $product): Response
{
$this->twigData['product'] = $product;
$html = $this->renderForm("product/_fileList.html.twig", $this->twigData);
return $this->json(['code' => 200, 'html' => $html->getContent()]);
}
#[Route('/generate-feature', name: '_generateFeature')]
public function generateFeature(Request $request, FeatureRepository $featureRepository): Response
{
$nbSelect = $request->request->get("nbSelect");
$nbSelect += 1;
$user = $this->security->getUser();
$userInterfaceLang = $user->getInterfaceLang();
$this->twigData['userInterfaceLang'] = $userInterfaceLang;
$features = $featureRepository->findAll();
$this->twigData['features'] = $features;
$this->twigData['nbSelect'] = $nbSelect;
$this->twigData['exist'] = false;
$html = $this->renderForm("product/feature/_featureSelects.html.twig", $this->twigData);
return $this->json(['code' => 200, 'html' => $html->getContent()]);
}
#[Route('/sync', name: '_sync')]
public function sync(LangRepository $langRepository, ProductRepository $productRepository, ImageRepository $imageRepository, Request $request, SiteRepository $siteRepository, PSARepository $PSARepository, ProductLangRepository $productLangRepository, ProductAttributeRepository $productAttributeRepository, FileRepository $fileRepository): Response
{
$debug = false;
$queryBody = $request->request->all();
$selectSyncSites = $queryBody['selectSyncSite'];
$productId = $queryBody['productId'];
$sites = [];
foreach ($selectSyncSites as $key => $selectSyncSite) {
$site = $siteRepository->find($selectSyncSite);
$sites[] = $site;
}
$product = $productRepository->find($productId);
$errors = [];
foreach ($sites as $key => $site) {
$featureValues = $product->getFeatureValues();
foreach ($featureValues as $keyFeatureValue => $featureValue) {
$feature = $featureValue->getFeature();
$featureLangs = $feature->getFeatureLang();
$featureLang = null;
foreach ($featureLangs as $keyFeatureLang => $featureLang) {
if ($featureLang->getLang() == $this->security->getUser()->getInterfaceLang()) {
$featureLang = $featureLang;
break;
}
}
$featureValueLangs = $featureValue->getFeatureValueLangs();
foreach ($featureValueLangs as $keyFeatureValueLang => $featureValueLang) {
if ($featureValueLang->getLang() == $this->security->getUser()->getInterfaceLang()) {
$featureValueLang = $featureValueLang;
break;
}
}
$PSAFeature = $PSARepository->findOneBy(['entityName' => "feature", 'entityId' => $feature->getId(), 'siteId' => $site->getId()]);
if ($PSAFeature == null) {
$error = $this->translator->trans('page.product.error.FeatureNotSync', ['%feature%' => $featureLang->getName()]);
if (in_array($error, $errors) == false) {
$errors[] = $error;
}
}
$PSAFeatureValue = $PSARepository->findOneBy(['entityName' => "featureValue", 'entityId' => $featureValue->getId(), 'siteId' => $site->getId()]);
if ($PSAFeatureValue == null) {
$error = $this->translator->trans('page.product.error.FeatureValueNotSync', ['%featureValue%' => $featureValueLang->getValue(), '%feature%' => $featureLang->getName()]);
if (in_array($error, $errors) == false) {
$errors[] = $error;
}
}
}
$productAttributes = $product->getProductAttributes();
foreach ($productAttributes as $keyAttribute => $productAttribute) {
$attributeValues = $productAttribute->getAttributeValues();
foreach ($attributeValues as $keyAttributeValue => $attributeValue) {
$attribute = $attributeValue->getAttribute();
$attributeLangs = $attribute->getAttributeLang();
$attributeLang = null;
foreach ($attributeLangs as $keyAttributeLang => $attributeLang) {
if ($attributeLang->getLang() == $this->security->getUser()->getInterfaceLang()) {
$attributeLang = $attributeLang;
break;
}
}
$attributeValueLangs = $attributeValue->getAttributeValueLangs();
foreach ($attributeValueLangs as $keyAttributeValueLang => $attributeValueLang) {
if ($attributeValueLang->getLang() == $this->security->getUser()->getInterfaceLang()) {
$attributeValueLang = $attributeValueLang;
break;
}
}
$PSAAttribute = $PSARepository->findOneBy(['entityName' => "attribute", 'entityId' => $attribute->getId(), 'siteId' => $site->getId()]);
if ($PSAAttribute == null) {
$error = $this->translator->trans('page.product.error.AttributeNotSync', ['%attribute%' => $attributeLang->getName()]);
if (in_array($error, $errors) == false) {
$errors[] = $error;
}
}
$PSAAttributeValue = $PSARepository->findOneBy(['entityName' => "attributeValue", 'entityId' => $attributeValue->getId(), 'siteId' => $site->getId()]);
if ($PSAAttributeValue == null) {
$error = $this->translator->trans('page.product.error.AttributeValueNotSync', ['%attributeValue%' => $attributeValueLang->getValue(), '%attribute%' => $attributeLang->getName()]);
if (in_array($error, $errors) == false) {
$errors[] = $error;
}
}
}
}
$productFiles = $product->getFiles();
foreach ($productFiles as $keyProductFile => $productFile) {
$PSAFile = $PSARepository->findOneBy(['entityName' => "attachments", 'entityId' => $productFile->getId(), 'siteId' => $site->getId()]);
if ($PSAFile == null) {
$error = $this->translator->trans('page.product.error.AttachmentsNoSync', ['%attachment%' => $productFile->getDisplayName()]);
if (in_array($error, $errors) == false) {
$errors[] = $error;
}
}
}
}
if (!empty($errors)) {
foreach ($errors as $keyError => $error) {
$this->addFlash('error', ['from' => $this->translator->trans('page.product.Sync'), 'message' => $error]);
}
return $this->redirectToRoute('app_product_index');
die;
}
foreach ($sites as $key => $site) {
$url = $site->getUrl();
$apiKey = $site->getApiKey();
$webService = new PrestaShopWebservice($url, $apiKey, $debug);
$webServiceUtils = new WebserviceUtils($webService, $url);
$langs = $webServiceUtils->getSiteLangs();
$psaProduct = $PSARepository->findOneBy(['entityId' => $product->getId(), "entityName" => 'product', "siteId" => $site->getId()]);
// dump($product->getId(), $langs, $psaProduct, $site);
if ($psaProduct != null) {
// product modification
try {
$xmlResponseProduct = $webService->get(['resource' => 'products', 'id' => $psaProduct->getInSiteId()]);
$productXML = $xmlResponseProduct->product[0];
unset($productXML->manufacturer_name);
unset($productXML->quantity);
unset($productXML->associations->product_features);
$product_features_xml = $productXML->associations->addChild('product_features');
foreach ($product->getFeatureValues() as $keyFeatureValue => $featureValue) {
$PSAFeature = $PSARepository->findOneBy(['entityName' => 'feature', 'entityId' => $featureValue->getFeature()->getId(), 'siteId' => $site->getId()]);
$PSAFeatureValue = $PSARepository->findOneBy(['entityName' => 'featureValue', 'entityId' => $featureValue->getId(), 'siteId' => $site->getId()]);
$product_feature_xml = $product_features_xml->addChild("product_feature");
$product_feature_xml->addChild('id', $PSAFeature->getInSiteId());
$product_feature_xml->addChild('id_feature_value', $PSAFeatureValue->getInSiteId());
}
unset($productXML->position_in_category);
foreach ($langs as $keyLang => $lang) {
if ($lang['icu'] == "en") {
$lang['icu'] = "gb";
}
$langPimdam = $langRepository->findOneBy(['ICU' => $lang['icu']]);
$productLang = $productLangRepository->findOneBy(['lang' => $langPimdam, 'product' => $product->getId()]);
$productXML->name->language[$keyLang] = $productLang->getName();
$productXML->description->language[$keyLang] = $product->editorToHTML($productLang->getDescription());
$productXML->description_short->language[$keyLang] = $product->editorToHTML($productLang->getShortDescription());
$productXML->subtitle->language[$keyLang] = $productLang->getSubtitle();
}
// dd($productXML);
$productXML->reference = $product->getReference();
$productXML->price = $productXML->price;
unset($productXML->associations->combinations);
unset($productXML->associations->attachments);
$attachments_xml = $productXML->associations->addChild('attachments');
foreach ($product->getFiles() as $keyProductFile => $productFile) {
//create attachment xml
$attachment_xml = $attachments_xml->addChild('attachment');
$PSAFile = $PSARepository->findOneBy(['entityName' => 'attachments', 'entityId' => $productFile->getId(), 'siteId' => $site->getId()]);
$attachment_xml->addChild('id', $PSAFile->getInSiteId());
}
$optProduct = ['resource' => 'products'];
$optProduct['putXml'] = $xmlResponseProduct->asXML();
$optProduct['id'] = (int) $productXML->id;
// dd($optProduct);
$returnProduct = $webService->edit($optProduct);
// dd($webService->edit($optProduct));
$psaProductFields = $PSARepository->findOneBy(['entityId' => $product->getId(), "entityName" => 'productfields', "siteId" => $site->getId()]);
// dd($psaProductFields);
// dd($psaProduct, $psaProductFields);
// $xmlResponseNewFields = $webService->get(['url' => $url . '/api/productfields?filter[id_product]=[' . (int) $productXML->id . ']']);
// $xmlResponseNewFieldsId = (int)$xmlResponseNewFields->productfields->productfield[0]['id'];
if ($psaProductFields == null) {
$productFieldsXML = $webService->get(['url' => $url . '/api/productfields/']);
foreach ($productFieldsXML->productfields->productfield as $keyProductField => $productField) {
$xmlResponseNewFields = $webService->get(['url' => $url . '/api/productfields/' . $productField['id']]);
if ($xmlResponseNewFields->productfield[0]->id_product == $psaProduct->getInSiteId()) break;
}
} else {
$xmlResponseNewFields = $webService->get(['url' => $url . '/api/productfields/' . $psaProductFields->getInSiteId()]);
}
$newFieldsXml = $xmlResponseNewFields->productfield[0];
$newFieldsId = (int)$newFieldsXml->id;
// dd($newFieldsId);
foreach ($langs as $keyLang => $lang) {
if ($lang['icu'] == "en") {
$lang['icu'] = "gb";
}
$langPimdam = $langRepository->findOneBy(['ICU' => $lang['icu']]);
$productLang = $productLangRepository->findOneBy(['lang' => $langPimdam, 'product' => $product->getId()]);
$newFieldsXml->subtitle->language[$keyLang] = $productLang->getSubtitle();
$newFieldsXml->reglementation->language[$keyLang] = $product->editorToHTML($productLang->getRegulations());
$newFieldsXml->conseils->language[$keyLang] = $product->editorToHTML($productLang->getAdvices());
}
// dd($newFieldsXml);
$optNewFields['resource'] = 'productfields';
$optNewFields['putXml'] = $xmlResponseNewFields->asXML();
$optNewFields['id'] = $newFieldsId;
$returnNewFields = $webService->edit($optNewFields);
$returnNewFieldsId = (int)$returnNewFields->productfield->id;
// dd($returnNewFields);
if (!$psaProductFields) {
$psaProductFields = new PSA();
$psaProductFields->setEntityId($product->getId());
$psaProductFields->setEntityName('productfields');
$psaProductFields->setInSiteId($returnNewFieldsId);
$psaProductFields->setSiteId($site->getId());
$PSARepository->add($psaProductFields, true);
}
} catch (\PrestaShopWebserviceException $th) {
dd($th);
if ($th->getMessage() == "This call to PrestaShop Web Services failed and returned an HTTP status of 404. That means: Not Found.") {
$PSARepository->Remove($psaProduct, true);
return $this->redirectToRoute('app_product_sync', ['id' => $product->getId()], Response::HTTP_SEE_OTHER);
} else {
$this->addFlash(
'error',
['from' => $this->translator->trans('page.product.Products'), 'message' => $this->translator->trans('page.product.error.CantSync')]
);
return $this->redirectToRoute('app_product_index');
}
}
// Product is modified. Now, it's image time
$imageStatus = "";
try {
$xmlImageResponse = $webService->get(['resource' => 'images/products/' . $psaProduct->getInSiteId()]);
$productImageXML = $xmlImageResponse;
$productImage = json_decode(json_encode((array)$productImageXML), true);
} catch (\Throwable $th) {
if ($th->getMessage() == "This call to PrestaShop Web Services failed and returned an HTTP status of 404. That means: Not Found.") {
$imageStatus = "noImage";
}
}
if ($imageStatus == "") {
$imageStatus = "images";
}
if ($imageStatus == "noImage") {
$productImages = $imageRepository->findBy(['product' => $product->getId()]);
foreach ($productImages as $keyProductImage => $productImage) {
$psaProductImage = $PSARepository->findOneBy(['entityName' => 'image', 'entityId' => $productImage->getId(), 'siteId' => $site->getId()]);
if ($psaProductImage != null) {
$PSARepository->Remove($psaProductImage, true);
}
}
foreach ($product->getImage() as $keyImage => $image) {
$image_path = $this->getParameter('product_image_directory') . '/' . $image->getName();
$image_mime = 'image/jpg';
$args['image'] = new CURLFile($image_path, $image_mime);
$args['position'] = $image->getPosition();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_URL, $url . "/api/images/products/" . $psaProduct->getInSiteId());
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returnImage = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($returnImage, 0, $header_size);
$body = substr($returnImage, $header_size);
$returnImage = $body;
$returnImage = simplexml_load_string($returnImage);
$curlinfo = curl_getinfo($ch);
curl_close($ch);
$returnImageId = intval($returnImage->image[0]->id);
$psaImage = new PSA();
$psaImage->setEntityId($image->getId());
$psaImage->setEntityName('image');
$psaImage->setInSiteId($returnImageId);
$psaImage->setSiteId($site->getId());
$PSARepository->add($psaImage, true);
}
}
if ($imageStatus == "images") {
$productImagesId = [];
foreach ($product->getImage() as $keyProductImage => $image) {
$productImagesId[$image->getId()] = false;
}
foreach ($productImage['image']['declination'] as $keySiteImage => $siteImage) {
$siteImageId = 0;
if (count($productImage['image']['declination']) > 1) {
$siteImageId = $siteImage['@attributes'];
} else {
$siteImageId = $siteImage;
}
$psaSiteImage = $PSARepository->findOneBy(['inSiteId' => $siteImageId, "entityName" => 'image', "siteId" => $site->getId()]);
if ($psaSiteImage != null) {
if (isset($productImagesId[$psaSiteImage->getEntityId()])) {
$productImagesId[$psaSiteImage->getEntityId()] = true;
} else {
$webService->delete(array('resource' => 'images/products/' . $psaProduct->getInSiteId(), 'id' => $psaSiteImage->getInSiteId()));
$PSARepository->remove($psaSiteImage, true);
}
}
}
// check all product image and add if not exist
foreach ($productImagesId as $keyProductImageId => $productImageId) {
if ($productImageId == false) {
$image = $imageRepository->findOneBy(['id' => $keyProductImageId]);
$image_path = $this->getParameter('product_image_directory') . '/' . $image->getName();
$image_mime = 'image/jpg';
$args['image'] = new CURLFile($image_path, $image_mime);
$args['position'] = $image->getPosition();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_URL, $url . "/api/images/products/" . $psaProduct->getInSiteId());
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returnImage = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($returnImage, 0, $header_size);
$body = substr($returnImage, $header_size);
$returnImage = $body;
$returnImage = simplexml_load_string($returnImage);
$curlinfo = curl_getinfo($ch);
curl_close($ch);
$returnImageId = intval($returnImage->image[0]->id);
$psaImage = new PSA();
$psaImage->setEntityId($image->getId());
$psaImage->setEntityName('image');
$psaImage->setInSiteId($returnImageId);
$psaImage->setSiteId($site->getId());
$PSARepository->add($psaImage, true);
}
}
}
foreach ($product->getImage() as $keyImage => $image) {
$psaSiteImage = $PSARepository->findOneBy(['entityId' => $image->getId(), "entityName" => 'image', "siteId" => $site->getId()]);
if ($psaSiteImage == null) {
$image_path = $this->getParameter('product_image_directory') . '/' . $image->getName();
$image_mime = 'image/jpg';
$args['image'] = new CURLFile($image_path, $image_mime);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_URL, $url . "/api/images/products/" . $psaProduct->getInSiteId());
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returnImage = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($returnImage, 0, $header_size);
$body = substr($returnImage, $header_size);
$returnImage = $body;
$returnImage = simplexml_load_string($returnImage);
$curlinfo = curl_getinfo($ch);
curl_close($ch);
$returnImageId = intval($returnImage->image[0]->id);
$psaImage = new PSA();
$psaImage->setEntityId($image->getId());
$psaImage->setEntityName('image');
$psaImage->setInSiteId($returnImageId);
$psaImage->setSiteId($site->getId());
$PSARepository->add($psaImage, true);
}
}
// Now, it's time to combinations
$productCombinations = json_decode(json_encode((array)$productXML->associations->combinations), true);
if (isset($productCombinations['combination'])) {
foreach ($productCombinations['combination'] as $keyCombination => $combination) {
$combinationId = 0;
if ($keyCombination == "id") {
$combinationId = $combination;
} else {
$combinationId = $combination['id'];
}
$psaCombination = $PSARepository->findOneBy(['inSiteId' => $combinationId, "entityName" => 'combination', "siteId" => $site->getId()]);
if ($psaCombination != null) {
$pimCombination = $productAttributeRepository->findOneBy(['id' => $psaCombination->getEntityId(), 'product' => $psaProduct->getEntityId()]);
if ($pimCombination == null) {
$webService->delete(array('resource' => 'combinations', 'id' => $psaCombination->getInSiteId()));
$PSARepository->remove($psaCombination, true);
} else {
$xmlResponseCombination = $webService->get(['resource' => 'combinations', 'id' => $combinationId]);
$combinationXML = $xmlResponseCombination->combination[0];
$combinationXML->reference = $pimCombination->getReference();
$combinationXML->ean13 = $pimCombination->getEan13();
unset($combinationXML->associations->images);
$combinationXML->associations->addChild('images');
foreach ($pimCombination->getImages() as $keyProductAttributeImage => $productAttributeImage) {
$psaImage = $PSARepository->findOneBy(['entityId' => $productAttributeImage->getId(), "entityName" => 'image', "siteId" => $site->getId()]);
// $combinationXML->associations->product_option_values->product_option_value->id = $psaAttributeValue->getInSiteId();
$product_option_image = $combinationXML->associations->images->addChild("image");
$product_option_image->addChild('id', $psaImage->getInSiteId());
}
$webService->edit(array('resource' => 'combinations', 'id' => $psaCombination->getInSiteId(), 'putXml' => $xmlResponseCombination->asXML()));
}
}
}
}
$xmlResponseCombination = $webService->get(['url' => $url . '/api/combinations?schema=blank']);
foreach ($product->getProductAttributes() as $keyProductAttributes => $productAttribute) {
$psaCombination = $PSARepository->findOneBy(['entityId' => $productAttribute->getId(), "entityName" => 'combination', "siteId" => $site->getId()]);
if ($psaCombination == null) {
$combinationXML = $xmlResponseCombination->combination[0];
$combinationXML->id_product = $psaProduct->getInSiteId();
$combinationXML->quantity = 0;
$combinationXML->minimal_quantity = 1;
$combinationXML->reference = $productAttribute->getReference();
$combinationXML->ean13 = $productAttribute->getEan13();
$combinationXML->price = 0;
unset($combinationXML->associations->product_option_values->product_option_value);
foreach ($productAttribute->getAttributeValues() as $keyProductAttributeValue => $productAttributeValue) {
$psaAttributeValue = $PSARepository->findOneBy(['entityId' => $productAttributeValue->getId(), "entityName" => 'attributeValue', "siteId" => $site->getId()]);
// $combinationXML->associations->product_option_values->product_option_value->id = $psaAttributeValue->getInSiteId();
$product_option_value = $combinationXML->associations->product_option_values->addChild("product_option_value");
$product_option_value->addChild('id', $psaAttributeValue->getInSiteId());
}
foreach ($productAttribute->getImages() as $keyProductAttributeImage => $productAttributeImage) {
$psaImage = $PSARepository->findOneBy(['entityId' => $productAttributeImage->getId(), "entityName" => 'image', "siteId" => $site->getId()]);
// $combinationXML->associations->product_option_values->product_option_value->id = $psaAttributeValue->getInSiteId();
$product_option_image = $combinationXML->associations->images->addChild("image");
$product_option_image->addChild('id', $psaImage->getInSiteId());
}
$optCombination = ['resource' => 'combinations'];
$optCombination['postXml'] = $xmlResponseCombination->asXML();
$returnCombination = $webService->add($optCombination);
$returnCombinationId = intval($returnCombination->combination[0]->id);
$psaCombination = new PSA();
$psaCombination->setEntityId($productAttribute->getId());
$psaCombination->setEntityName('combination');
$psaCombination->setInSiteId($returnCombinationId);
$psaCombination->setSiteId($site->getId());
$PSARepository->add($psaCombination, true);
}
}
// Now, it's time to file
// unset($productXML->associations->attachments);
// $attachments_xml = $productXML->associations->addChild('attachments');
// foreach ($product->getFiles() as $keyProductFile => $productFile) {
// //create attachment xml
// $attachment_xml = $attachments_xml->addChild('attachment');
// $PSAFile = $PSARepository->findOneBy(['entityName' => 'attachments', 'entityId' => $productFile->getId(), 'siteId' => $site->getId()]);
// $attachment_xml->addChild('id', $PSAFile->getInSiteId());
// }
// $optProduct = ['resource' => 'products'];
// $optProduct['putXml'] = $xmlResponseProduct->asXML();
// $optProduct['id'] = (int) $productXML->id;
// $returnProduct = $webService->edit($optProduct);
} else {
$existInSite = false;
$xmlResponse = $webService->get(['url' => $url . '/api/products?filter[reference]=[' . $product->getReference() . ']']);
if (isset($xmlResponse->products->product[0]['id'])) {
$xmlResponseProductId = (int)$xmlResponse->products->product[0]['id'];
} else {
$xmlResponseProductId = null;
}
if ($xmlResponseProductId != null) {
$xmlResponse = $webService->get(['url' => $url . '/api/products/' . $xmlResponseProductId]);
$existInSite = true;
} else {
$xmlResponse = $webService->get(['url' => $url . '/api/products?schema=blank']);
}
$productXML = $xmlResponse->product[0];
if ($existInSite == false) {
$productXML->id_category_default = 2;
$productXML->price = 0;
$productXML->position_in_category = 1;
$productXML->state = 1;
} else {
//unset manufacturer_name
unset($productXML->manufacturer_name);
unset($productXML->quantity);
//get position and if < 0, set to 1
if ((int)$productXML->position_in_category < 1) {
$productXML->position_in_category = 1;
}
}
foreach ($langs as $keyLang => $lang) {
if ($lang['icu'] == "en") {
$lang['icu'] = "gb";
}
$langPimdam = $langRepository->findOneBy(['ICU' => $lang['icu']]);
$productLang = $productLangRepository->findOneBy(['lang' => $langPimdam, 'product' => $product->getId()]);
$productXML->name->language[$keyLang] = $productLang->getName();
$productXML->description->language[$keyLang] = $product->editorToHTML($productLang->getDescription());
$productXML->description_short->language[$keyLang] = $product->editorToHTML($productLang->getShortDescription());
$productXML->subtitle->language[$keyLang] = $productLang->getSubtitle();
$productXML->meta_title->language[$keyLang] = $productLang->getMetaTitle();
$productXML->meta_description->language[$keyLang] = $productLang->getMetaDescription();
}
$productXML->ean13 = $product->getEan13();
$productXML->reference = $product->getReference();
$productXML->isbn = $product->getIsbn();
$productXML->mpn = $product->getMpn();
$productXML->width = $product->getWidth();
$productXML->height = $product->getHeight();
$productXML->depth = $product->getDepth();
$productXML->weight = $product->getWeight();
unset($productXML->associations->product_features);
$product_features_xml = $productXML->associations->addChild('product_features');
foreach ($product->getFeatureValues() as $keyFeatureValue => $featureValue) {
$PSAFeature = $PSARepository->findOneBy(['entityName' => 'feature', 'entityId' => $featureValue->getFeature()->getId(), 'siteId' => $site->getId()]);
$PSAFeatureValue = $PSARepository->findOneBy(['entityName' => 'featureValue', 'entityId' => $featureValue->getId(), 'siteId' => $site->getId()]);
$product_feature_xml = $product_features_xml->addChild("product_feature");
$product_feature_xml->addChild('id', $PSAFeature->getInSiteId());
$product_feature_xml->addChild('id_feature_value', $PSAFeatureValue->getInSiteId());
}
$opt = ['resource' => 'products'];
if ($existInSite == false) {
$productXML->associations->categories->category = 2;
$opt['postXml'] = $xmlResponse->asXML();
$returnProduct = $webService->add($opt);
} else {
$opt['putXml'] = $xmlResponse->asXML();
$opt['id'] = $xmlResponseProductId;
$returnProduct = $webService->edit($opt);
}
$returnedId = intval($returnProduct->product[0]->id);
$psaProduct = new PSA();
$psaProduct->setEntityId($product->getId());
$psaProduct->setEntityName('product');
$psaProduct->setInSiteId($returnedId);
$psaProduct->setSiteId($site->getId());
$PSARepository->add($psaProduct, true);
foreach ($product->getImage() as $keyImage => $image) {
$image_path = $this->getParameter('product_image_directory') . '/' . $image->getName();
$image_mime = 'image/jpg';
$args['image'] = new CURLFile($image_path, $image_mime);
$args['position'] = $image->getPosition();
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_URL, $url . "/api/images/products/" . $returnedId);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returnImage = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$header = substr($returnImage, 0, $header_size);
$body = substr($returnImage, $header_size);
$returnImage = $body;
$returnImage = simplexml_load_string($returnImage);
$curlinfo = curl_getinfo($ch);
curl_close($ch);
$returnImageId = intval($returnImage->image[0]->id);
$psaImage = new PSA();
$psaImage->setEntityId($image->getId());
$psaImage->setEntityName('image');
$psaImage->setInSiteId($returnImageId);
$psaImage->setSiteId($site->getId());
$PSARepository->add($psaImage, true);
}
$xmlResponse = $webService->get(['url' => $url . '/api/combinations?schema=blank']);
foreach ($product->getProductAttributes() as $keyProductAttributes => $productAttribute) {
$combinationXML = $xmlResponse->combination[0];
$combinationXML->id_product = $psaProduct->getInSiteId();
$combinationXML->quantity = 0;
$combinationXML->minimal_quantity = 1;
$combinationXML->reference = $productAttribute->getReference();
$combinationXML->ean13 = $productAttribute->getEan13();
$combinationXML->price = 0;
unset($combinationXML->associations->product_option_values->product_option_value);
foreach ($productAttribute->getAttributeValues() as $key => $productAttributeValue) {
$psaAttributeValue = $PSARepository->findOneBy(['entityId' => $productAttributeValue->getId(), "entityName" => 'attributeValue', "siteId" => $site->getId()]);
// $combinationXML->associations->product_option_values->product_option_value->id = $psaAttributeValue->getInSiteId();
$product_option_value = $combinationXML->associations->product_option_values->addChild("product_option_value");
$product_option_value->addChild('id', $psaAttributeValue->getInSiteId());
}
$opt = ['resource' => 'combinations'];
$opt['postXml'] = $xmlResponse->asXML();
try {
$returnCombination = $webService->add($opt);
} catch (PrestaShopWebserviceException $th) {
dd($th);
}
$returnCombinationId = intval($returnCombination->combination[0]->id);
$psaCombination = new PSA();
$psaCombination->setEntityId($productAttribute->getId());
$psaCombination->setEntityName('combination');
$psaCombination->setInSiteId($returnCombinationId);
$psaCombination->setSiteId($site->getId());
$PSARepository->add($psaCombination, true);
}
foreach ($product->getFiles() as $keyProductFile => $file) {
$psaAttachment = $PSARepository->findOneBy(['entityId' => $file->getId(), "entityName" => 'attachments', "siteId" => $site->getId()]);
$file_path = $this->getParameter('file_directory') . '/' . $file->getName();
$file_mime = mime_content_type($file_path);
$args['file'] = new CURLFile($file_path, $file_mime, $file->getDisplayName());
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_URL, $url . "/api/attachments/file/");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, $apiKey);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$returnFile = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$body = substr($returnFile, $header_size);
$curlinfo = curl_getinfo($ch);
curl_close($ch);
$returnFile = $body;
$returnFile = simplexml_load_string($returnFile);
$returnFileId = intval($returnFile->attachment[0]->id);
$xmlAttachmentsResponse = $webService->get(['url' => $url . '/api/attachments/' . $returnFileId]);
$attachmentsXml = $xmlAttachmentsResponse->attachment[0];
foreach ($langs as $keyLang => $lang) {
if ($lang['icu'] == "en") {
$lang['icu'] = "gb";
}
$attachmentsXml->description->language[$keyLang] = $file->getDescription();
}
$attachmentsXml->associations->products->product->id = $psaProduct->getInSiteId();
$optAttachment = ['resource' => 'attachments'];
$optAttachment['putXml'] = $xmlAttachmentsResponse->asXML();
$optAttachment['id'] = $returnFileId;
try {
$returnAttachment = $webService->edit($optAttachment);
} catch (PrestaShopWebserviceException $th) {
dd($th);
}
$returnAttachmentId = $returnFileId;
$psaAttachment = new PSA();
$psaAttachment->setEntityId($file->getId());
$psaAttachment->setEntityName('attachments');
$psaAttachment->setInSiteId($returnAttachmentId);
$psaAttachment->setSiteId($site->getId());
$PSARepository->add($psaAttachment, true);
}
$xmlResponseNewFields = $webService->get(['url' => $url . '/api/productfields?filter[id_product]=[' . $returnedId . ']']);
$xmlResponseNewFieldsId = (int)$xmlResponseNewFields->productfields->productfield[0]['id'];
$xmlResponseNewFields = $webService->get(['url' => $url . '/api/productfields/' . $xmlResponseNewFieldsId]);
$newFieldsXml = $xmlResponseNewFields->productfield[0];
foreach ($langs as $keyLang => $lang) {
if ($lang['icu'] == "en") {
$lang['icu'] = "gb";
}
$langPimdam = $langRepository->findOneBy(['ICU' => $lang['icu']]);
$productLang = $productLangRepository->findOneBy(['lang' => $langPimdam, 'product' => $product->getId()]);
$newFieldsXml->subtitle->language[$keyLang] = $productLang->getSubtitle();
$newFieldsXml->reglementation->language[$keyLang] = $product->editorToHTML($productLang->getRegulations());
$newFieldsXml->conseils->language[$keyLang] = $product->editorToHTML($productLang->getAdvices());
}
$optNewFields = ['resource' => 'productfields'];
$optNewFields['putXml'] = $xmlResponseNewFields->asXML();
$optNewFields['id'] = $xmlResponseNewFieldsId;
$returnNewFields = $webService->edit($optNewFields);
$returnNewFieldsId = intval($returnNewFields->productfield[0]->id);
$psaProductFields = new PSA();
$psaProductFields->setEntityId($product->getId());
$psaProductFields->setEntityName('productfields');
$psaProductFields->setInSiteId($returnNewFieldsId);
$psaProductFields->setSiteId($site->getId());
$PSARepository->add($psaProductFields, true);
}
}
return $this->redirectToRoute('app_product_index');
}
private function xml2array($xmlObject, $out = array())
{
foreach ((array) $xmlObject as $index => $node) {
$out[$index] = (is_object($node)) ? $this->xml2array($node) : $node;
}
return $out;
}
}