src/Controller/MdmController.php line 34

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under two different licenses:
  6.  * - GNU General Public License version 3 (GPLv3)
  7.  * - Pimcore Enterprise License (PEL)
  8.  * Full copyright and license information is available in
  9.  * LICENSE.md which is distributed with this source code.
  10.  *
  11.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12.  *  @license    http://www.pimcore.org/license     GPLv3 and PEL
  13.  */
  14. namespace App\Controller;
  15. use App\Services\Import\ImportExternalServiceEconology;
  16. use App\Services\ObjectToArrayService;
  17. use Couchbase\Document;
  18. use Pimcore\Controller\FrontendController;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Pimcore\Model\DataObject;
  23. /**
  24.  * Class AccountController
  25.  *
  26.  * Controller that handles all account functionality, including register, login and connect to SSO profiles
  27.  */
  28. class MdmController extends FrontendController
  29. {
  30.     static $PER_PAGE 15;
  31.     static $MDM_URL "https://pimcore.distriweb.net";
  32.     /**
  33.      * Récupérer les produits
  34.      * @Route("/mdm/products")
  35.      */
  36.     public function listProducts(Request $request)
  37.     {
  38.         $listingProducts = new DataObject\Product\Listing();
  39.         $listingProducts->setUnpublished(true);
  40.         //        $listingProducts->load();
  41.         $products = [];
  42.         $mdmUrl self::$MDM_URL;
  43.         $now = new \DateTime();
  44.         $now->sub(new \DateInterval("PT15M"));
  45.         //$now->sub(new \DateInterval("P1D"));
  46.         $perPage $request->get('size') ? $request->get('size') : self::$PER_PAGE;
  47.         // --------------------------------------------------------------------------------Système de pages ----------------------------------------------------------------------
  48.         $pageNumber $request->get('page') ? $request->get('page') : 1;
  49.         //$isDbg = $request->get('lp') == 1;
  50.         
  51.         // offset
  52.         $offset 0;
  53.         if ($pageNumber == 2$offset = ($perPage);
  54.         if ($pageNumber 2$offset = ($perPage) * ($pageNumber 1);
  55.         if($request->get('lp') == 1) {
  56.             $pageNumber 301;
  57.             $perPage 100;
  58.             $offset = ($perPage) * ($pageNumber 1);
  59.         }
  60.         // récupérer les produits correspondants
  61.         $listingProducts->setCondition('buyingPrice != 0 OR skuEconology IS NOT NULL');
  62.         //$listingProducts->setOrderKey('o_creationDate');
  63.         //$listingProducts->setOrder('DESC');
  64.         if (!$request->get('full'))
  65.             $listingProducts->setCondition('o_modificationDate > ?', [$now->getTimestamp()]);
  66.         $listingProducts->setOffset($offset);
  67.         $listingProducts->setLimit($perPage);
  68.         // lastPage
  69.         $lastPage = (count($listingProducts) / $perPage);
  70.         if (is_float($lastPage)) {
  71.             $lastPage intval($lastPage) + 1;
  72.         }
  73.         // Récupérer les informations dont on a besoin pour Skyper et Routeur
  74.         foreach ($listingProducts as $key => $listingProduct) {
  75.             //echo $listingProduct->getSku(); die();
  76.             $isDbg = !!$listingProduct->getSkuEconology();
  77.             if (!$listingProduct->hasChildren() || !$listingProduct->getSku() || $listingProduct->getChildren()[0]->getKey() != "Providers") {
  78.                 if ($isDbg) {
  79.                     //echo ' A ';
  80.                     //echo $listingProduct->getSku();
  81.                     //echo ' ';
  82.                     $_providerInfo_Econology =  \Pimcore\Model\DataObject\ProviderInfo::getById(1761389);
  83.                     $skuEco $listingProduct->getSkuEconology();
  84.                     // REF49003
  85.                     //echo '<br/>';
  86.                     //echo '<br/>';
  87.                     //print_r($skuEco);
  88.                     $_class \Pimcore\Model\DataObject\ExternalDataEconology::class;
  89.                     $product_eco ImportExternalServiceEconology::getProductInBdd($_class$skuEco);
  90.                     // echo '<br/>';
  91.                     // echo get_class($product_eco);
  92.                     // //print_r($product_eco);
  93.                     // echo '<br/>';
  94.                     // echo '<br/>';
  95.                     $_classStock \Pimcore\Model\DataObject\ExternalDataEconologyStock::class;
  96.                     $productStock ImportExternalServiceEconology::getProductStockInBdd($_classStock$skuEco'Default');
  97.                     // echo get_class($productStock);
  98.                     // echo '<br/>';
  99.                     // echo '<br/>';
  100.                     // echo $productStock->getQuantityAvailable();
  101.                     // //print_r($productStock);
  102.                     // Ajout ProductProvider
  103.                     $stockProviderEco = new \Pimcore\Model\DataObject\ProductProvider();
  104.                     // echo '<br/>';
  105.                     // echo '<br/>';
  106.                     // echo get_class($stockProviderEco);
  107.                     $pathProviders $listingProduct->getFullPath() . '/Providers';
  108.                     // echo '<br/>';
  109.                     // print_r($pathProviders);
  110.                     $parent DataObject\Service::createFolderByPath($pathProviders);
  111.                     // echo '<br/>';
  112.                     //echo get_class($parent);
  113.                     
  114.                     //$product_eco = new \Pimcore\Model\DataObject\ExternalDataEconology();
  115.                     // Ajout des champs utiles
  116.                     $stockProviderEco->setKey(strtolower("econology" "-" $product_eco->getKey()));
  117.                     $stockProviderEco->setName($product_eco->getTitle());
  118.                     // Lié à Eco
  119.                     $stockProviderEco->setProviderName("Econology");
  120.                     $stockProviderEco->setStatus(true);
  121.                     $stockProviderEco->setProviderSku($product_eco->getKey());
  122.                     $stockProviderEco->setProduct($listingProduct);
  123.                     $stockProviderEco->setProvider($_providerInfo_Econology);
  124.                     // Gestion des prix
  125.                     $stockProviderEco->setPrice($product_eco->getPrice_ttc());
  126.                     //echo '<pre>'.print_r($stockProviderEco,true).'</pre>';
  127.                     $stockProviderEco->setParent($parent);
  128.                     $stockProviderEco->setPublished(true);
  129.                     $stockProviderEco->save();
  130.                     //$productStock = new \Pimcore\Model\DataObject\ExternalDataEconologyStock();
  131.                     // AJOUT STOCK UNIT
  132.                     $unite \Pimcore\Model\DataObject\QuantityValue\Unit::getByAbbreviation("Un");
  133.                     $stockEntrepotEco = new \Pimcore\Model\DataObject\ProductWharehouse();
  134.                     $stockEntrepotEco->setKey(strtolower($productStock->getWarehouseInfos()->getCode() . "-" $product_eco->getKey()));
  135.                     $stockEntrepotEco->setProvider($stockProviderEco);
  136.                     $stockEntrepotEco->setProduct($listingProduct);
  137.                     $stockEntrepotEco->setInfos($productStock->getWarehouseInfos());
  138.                     // Variables utiles
  139.                     $stockEntrepotEco->setActiveForDispo(true);
  140.                     $stockEntrepotEco->setPhysicalStock(new \Pimcore\Model\DataObject\Data\QuantityValue($productStock->getQuantityInStock(), $unite));
  141.                     $stockEntrepotEco->setAvailableStock(new \Pimcore\Model\DataObject\Data\QuantityValue($productStock->getQuantityAvailable(), $unite));
  142.                     $stockEntrepotEco->setParent($stockProviderEco);
  143.                     $stockEntrepotEco->setPublished(true);
  144.                     $stockEntrepotEco->save();
  145.                     // echo '<pre>'.print_r($stockEntrepotEco->getFullPath(),true).'</pre>';
  146.                     // echo '<pre>'.print_r($stockEntrepotEco,true).'</pre>';
  147.                     // die();
  148.                 }
  149.                 continue;
  150.             }
  151.             if (!isset($listingProduct->getChildren()[0])) {
  152.                 // if ($isDbg) echo ' B ';
  153.                 continue;
  154.             }
  155.             $product['id'] = $listingProduct->getId();
  156.             $product['sku'] = $listingProduct->getSku();
  157.             $product['isActive'] = $listingProduct->isPublished();
  158.             // Fix - Init des clés
  159.             if(true) {
  160.                 $product['description'] = $listingProduct->getDescription();
  161.                 $product['shortDescription'] = $listingProduct->getDescription();
  162.                 $product['metaDescription'] = null;
  163.                 $product['metakey'] = null;
  164.             }
  165.             // url image
  166.             $hotspotImage $listingProduct->getBaseImage();
  167.             $thumbnailUrl $hotspotImage sprintf('%s%s'$mdmUrl$hotspotImage->getThumbnail()->getPath()) : null;
  168.             $product['thumbnail'] = $thumbnailUrl;
  169.             // ok  référence fabriquant
  170.             $product['manufacturerReference'] = $listingProduct->getMpn();
  171.             // ok  metadataImage
  172.             $metadataImage $listingProduct->getBaseImage() && $listingProduct->getBaseImage()->getHasMetaData()
  173.                 ? $listingProduct->getBaseImage()->getMetadata()[0]
  174.                 : null;
  175.             
  176.             $product['metadataImage'] = $metadataImage;
  177.             $product['name'] = $listingProduct->getName();
  178.             // prix de vente viens de salle
  179.             $product['price'] = null;
  180.             if (isset($listingProduct->getChildren()[1], $listingProduct->getChildren()[1]->getChildren()[0])) {
  181.                 $product['price'] = $listingProduct->getChildren()[1]->getChildren()[0]->getPrice() ?
  182.                     $listingProduct->getChildren()[1]->getChildren()[0]->getPrice() :
  183.                     $listingProduct->getChildren()[1]->getChildren()[0]->getSpecialPrice();
  184.                 // ok  slugUrl
  185.                 $slugUrl null;
  186.                 $product['description'] = null;
  187.                 $product['shortDescription'] = null;
  188.                 $product['metaDescription'] = null;
  189.                 $product['metakey'] = null;
  190.                 \Pimcore\Model\DataObject::setHideUnpublished(false);
  191.                 foreach ($listingProduct->getChildren()[1]->getChildren()[0]->getChildren() as $child) {
  192.                     switch ($child->getChannelName()) {
  193.                         case 'DistriwebTeamelek':
  194.                             $product['price'] = $child->getPrice() ?
  195.                                 $child->getPrice() :
  196.                                 $child->getSpecialPrice();
  197.                             $slugUrl $child->getUrl()[0]
  198.                                 ? $child->getUrl()[0]->getSlug()
  199.                                 : null;
  200.                             $product['description'] = isset($child->getDescription()[3])
  201.                                 ? $listingProduct->getChildren()[1]->getChildren()[0]->getDescription() != $child->getDescription() ? $child->getDescription() : null
  202.                                 null;
  203.                             $product['shortDescription'] = isset($child->getShortDescription()[3])
  204.                                 ? $child->getShortDescription()
  205.                                 : null;
  206.                             $product['metaDescription'] = $child->getMetaDescription();
  207.                             $product['metakey'] = $child->getMetakey();
  208.                             // Dépublier la chaine
  209.                             $product['isActive'] = $child->getPublished();
  210.                             break;
  211.                     }
  212.                 }
  213.                 $product['slugUrl'] = $slugUrl;
  214.             }
  215.             $product['priceSpecial'] = null;
  216.             $product['priceMagasin'] = null;
  217.             $product['priceSpecialMagasin'] = null;
  218.             $product['providerProducts'] = [];
  219.             if (isset($listingProduct->getChildren()[0]) && is_array($listingProduct->getChildren()[0]->getChildren()))
  220.                 foreach ($listingProduct->getChildren()[0]->getChildren() as $key1 => $productProvider) {
  221.                     $product['providerProducts'] += [$key1 => [
  222.                         "id" => $productProvider->getId(),
  223.                         "sku" => $listingProduct->getSku(),
  224.                         "productMagento" => null,
  225.                         "code" => $productProvider->getProviderSku(),
  226.                         "name" => $productProvider->getProviderName(),
  227.                         "price" => $productProvider->getPrice(),
  228.                         'provider' => [
  229.                             'id' => $productProvider->getProvider()->getId(),
  230.                             'name' => $productProvider->getName(),
  231.                             'favoriteProvider' => $productProvider->getFavoriteProvider()
  232.                         ]
  233.                     ]];
  234.                 }
  235.             $product['magentoId'] = null;
  236.             $product['gtin'] = $listingProduct->getEan13();
  237.             // les quantité min/max
  238.             $product['minQty'] = $listingProduct->getMinQty();
  239.             $product['incrementQty'] = $listingProduct->getIncrementQty();
  240.             
  241.             // parti de catégorie
  242.             $productSalesChannel = new DataObject\ProductSalesChannel\Listing();
  243.             $productSalesChannel->setCondition('channelName = ? AND o_published ', ["DistriwebTeamelek"true]);
  244.             $productSalesChannel->setCondition('product__id = ?', [$listingProduct->getId()]);
  245.             $categories null;
  246.             $categoriesSalesChannel = [];
  247.             foreach ($productSalesChannel as $productSaleChannel) {
  248.                 $categoriesSalesChannel $productSaleChannel->getCategories();
  249.             }
  250.             if ($categoriesSalesChannel) {
  251.                 foreach ($categoriesSalesChannel as  $categorySalesChannel) {
  252.                     //                    $categorie = [
  253.                     //                        'id' => $categorySalesChannel->getId(),
  254.                     //                        'name' => $categorySalesChannel->getName(),
  255.                     //                        'isActive' => $categorySalesChannel->getIsActive(),
  256.                     //                        'slug' => $categorySalesChannel->getSlug(),
  257.                     //                        'description' => $categorySalesChannel->getDescription(),
  258.                     //                        'title' => $categorySalesChannel->getTitle(),
  259.                     //                        'metakey' => $categorySalesChannel->getMetakey(),
  260.                     //                        'metaDescription' => $categorySalesChannel->getMetaDescription(),
  261.                     //                    ];
  262.                     $categories[] = ObjectToArrayService::objectToArray($categorySalesChannel);
  263.                 }
  264.             }
  265.             $product['category'] = $categories;
  266.             // Brand et characteristics
  267.             $brandSorti null;
  268.             $characteristicsSorti = [];
  269.             $characteristics $listingProduct->getCharacteristics();
  270.             $brand $listingProduct->getBrand();
  271.             if ($brand) {
  272.                 $brandSorti ObjectToArrayService::objectToArray($brand);
  273.             }
  274.             if ($characteristics) {
  275.                 foreach ($characteristics as $characteristic) {
  276.                     $key array_search($characteristic->getObjectId(), array_column($characteristicsSorti'id'));
  277.                     if ($key === false) {
  278.                         $characteristicsSorti[] = ["id" => $characteristic->getObjectId(), "name" => $characteristic->getElement()->getName(), "value" => $characteristic->getData()["val"]];
  279.                     } else {
  280.                         $characteristicsSorti[$key]['value'] = $characteristicsSorti[$key]['value'] . ', ' $characteristic->getData()["val"];
  281.                     }
  282.                 }
  283.             }
  284.             $product['caracteristiques'] = $characteristicsSorti;
  285.             $product['brand'] = $brandSorti;
  286.             $product['images'] = ['id' => null];
  287.             $product['weight'] = $listingProduct->getGrossWeight() ? $listingProduct->getGrossWeight() : 0;
  288.             $product['volume'] = 0;
  289.             // nouveau modification par rapport de stock;
  290.             //            $product['stock'] = $listingProduct->getTotalAvailableStock();
  291.             // $stock DERD
  292.             $product['stockDerd'] = null;
  293.             if (isset($listingProduct->getChildren()[0]) && isset($listingProduct->getChildren()[0]->getChildren()[0])) {
  294.                 $product['stockDerd'] = (int)$listingProduct->getChildren()[0]->getChildren()[0]->getAvailableStock();
  295.             }
  296.             $product['stock'] = (int)$listingProduct->getTotalAvailableStock();
  297.             $product['stockMp'] = (int)$listingProduct->getTotalAvailableStockMp();
  298.             $product['stockSecurity'] = 0;  // stockSecurity
  299.             $product['stockDefaultMin'] = 0;  // stockDefaultMin
  300.             $product['stockDefaultSufficient'] = 0;  // stockDefaultSufficient
  301.             $product['stockDefaultMax'] = 0;  // stockDefaultMax
  302.             $product['manageStock'] = true;  // manageStock
  303.             $product['replenishmentQuantity'] = 0;   // replenishmentQuantity
  304.             $product['locationArea'] = "";  // manageStock
  305.             $product['nbCarton'] = 0;  // nbCarton
  306.             $product['nbProductsCarton'] = 0;  // nbCarton
  307.             // Fix
  308.             $product['is_visible'] = true;
  309.             try {
  310.                 if($listingProduct->getSkuEconology()) {
  311.                     // Pour qu'il soit indexé dans Sylius
  312.                     $product['minQty'] = 0;
  313.                     $product['incrementQty'] = 0;
  314.                     // Test si produit uniquement Econology
  315.                     if(count($listingProduct->getChildren()[0]->getChildren()) == 1) {
  316.                         // Pour que le produit uniquement Econology ne soit pas visible (sauf lien direct)
  317.                         $product['is_visible'] = false;
  318.                         // Pour que le prix remonte (car pas de Sales dans PIMCore)
  319.                         if(!($product['price'] > 0)) {
  320.                             $product['price'] = 1.0 $listingProduct->getChildren()[0]->getChildren()[0]->getPrice();
  321.                         }
  322.                     }
  323.                 }
  324.             } catch (\Throwable $th) { }
  325.             $products[] = $product;
  326.         }
  327.         return new JsonResponse([
  328.             'status' => 'ok',
  329.             'page' => [
  330.                 "current-page" => (int) $pageNumber,
  331.                 "per-page" => (int) $perPage,
  332.                 "total" => count($listingProducts),
  333.                 "last-page" => $lastPage : (int) $lastPage,
  334.             ],
  335.             'result' => $products,
  336.         ]);
  337.     }
  338.     /**
  339.      * Récupérer les transporteurs par marketplaces
  340.      *
  341.      * @Route("/mdm/carrier-marketplaces", name="carrier_marketplaces")
  342.      */
  343.     public function listCarrierMarketplaces(Request $request)
  344.     {
  345.         $listingCarrierMartplaces = new DataObject\CarrierMarketplace\Listing();
  346.         return new JsonResponse(ObjectToArrayService::objectsToArray($listingCarrierMartplaces));
  347.     }
  348.     /**
  349.      * Récupérer les produits
  350.      * @Route("/mdm/products1")
  351.      */
  352.     public function listProducts1(Request $request)
  353.     {
  354.         $listingProducts = new DataObject\Product\Listing();
  355.         $listingProducts->setUnpublished(true);
  356.         //        $listingProducts->load();
  357.         $products = [];
  358.         $mdmUrl self::$MDM_URL;
  359.         $now = new \DateTime();
  360.         $now->sub(new \DateInterval("PT15M"));
  361.         $perPage $request->get('size') ? $request->get('size') : self::$PER_PAGE;
  362.         // --------------------------------------------------------------------------------Système de pages ----------------------------------------------------------------------
  363.         $pageNumber $request->get('page') ? $request->get('page') : 1;
  364.         // offset
  365.         $offset 0;
  366.         if ($pageNumber == 2$offset = ($perPage);
  367.         if ($pageNumber 2$offset = ($perPage) * ($pageNumber 1);
  368.         // récupérer les produits correspondants
  369.         $listingProducts->setCondition('buyingPrice != 0');
  370.         if (!$request->get('full'))
  371.             $listingProducts->setCondition('o_modificationDate > ?', [$now->getTimestamp()]);
  372.         $listingProducts->setOffset($offset);
  373.         $listingProducts->setLimit($perPage);
  374.         // lastPage
  375.         $lastPage = (count($listingProducts) / $perPage);
  376.         if (is_float($lastPage)) {
  377.             $lastPage intval($lastPage) + 1;
  378.         }
  379.         // Récupérer les informations dont on a besoin pour Skyper et Routeur
  380.         foreach ($listingProducts as $key => $listingProduct) {
  381.             if (!$listingProduct->hasChildren() || !$listingProduct->getSku() || $listingProduct->getChildren()[0]->getKey() != "Providers") continue;
  382.             $product['id'] = $listingProduct->getId();
  383.             $product['sku'] = $listingProduct->getSku();
  384.             $product['isActive'] = $listingProduct->isPublished();
  385.             // url image
  386.             $hotspotImage $listingProduct->getBaseImage();
  387.             $thumbnailUrl $hotspotImage sprintf('%s%s'$mdmUrl$hotspotImage->getThumbnail()->getPath()) : null;
  388.             $product['thumbnail'] = $thumbnailUrl;
  389.             // ok  référence fabriquant
  390.             $product['manufacturerReference'] = $listingProduct->getMpn();
  391.             // ok  metadataImage
  392.             $metadataImage $listingProduct->getBaseImage()
  393.                 ? $listingProduct->getBaseImage()->getMetadata()[0]
  394.                 : null;
  395.             $product['metadataImage'] = $metadataImage;
  396.             $product['name'] = $listingProduct->getName();
  397.             // prix de vente viens de salle
  398.             $product['price'] = null;
  399.             if (isset($listingProduct->getChildren()[1], $listingProduct->getChildren()[1]->getChildren()[0])) {
  400.                 $product['price'] = $listingProduct->getChildren()[1]->getChildren()[0]->getPrice() ?
  401.                     $listingProduct->getChildren()[1]->getChildren()[0]->getPrice() :
  402.                     $listingProduct->getChildren()[1]->getChildren()[0]->getSpecialPrice();
  403.                 // ok  slugUrl
  404.                 $slugUrl null;
  405.                 $product['description'] = null;
  406.                 $product['shortDescription'] = null;
  407.                 $product['metaDescription'] = null;
  408.                 $product['metakey'] = null;
  409.                 \Pimcore\Model\DataObject::setHideUnpublished(false);
  410.                 foreach ($listingProduct->getChildren()[1]->getChildren()[0]->getChildren() as $child) {
  411.                     switch ($child->getChannelName()) {
  412.                         case 'DistriwebTeamelek':
  413.                             $product['price'] = $child->getPrice() ?
  414.                                 $child->getPrice() :
  415.                                 $child->getSpecialPrice();
  416.                             $slugUrl $child->getUrl()[0]
  417.                                 ? $child->getUrl()[0]->getSlug()
  418.                                 : null;
  419.                             $product['description'] = isset($child->getDescription()[3])
  420.                                 ? $listingProduct->getChildren()[1]->getChildren()[0]->getDescription() != $child->getDescription() ? $child->getDescription() : null
  421.                                 null;
  422.                             $product['shortDescription'] = isset($child->getShortDescription()[3])
  423.                                 ? $child->getShortDescription()
  424.                                 : null;
  425.                             $product['metaDescription'] = $child->getMetaDescription();
  426.                             $product['metakey'] = $child->getMetakey();
  427.                             // Dépublier la chaine
  428.                             $product['isActive'] = $child->getPublished();
  429.                             break;
  430.                     }
  431.                 }
  432.                 $product['slugUrl'] = $slugUrl;
  433.             }
  434.             $product['priceSpecial'] = null;
  435.             $product['priceMagasin'] = null;
  436.             $product['priceSpecialMagasin'] = null;
  437.             $product['providerProducts'] = [];
  438.             if (is_array($listingProduct->getChildren()[0]->getChildren()))
  439.                 foreach ($listingProduct->getChildren()[0]->getChildren() as $key1 => $productProvider) {
  440.                     $product['providerProducts'] += [$key1 => [
  441.                         "id" => $productProvider->getId(),
  442.                         "sku" => $listingProduct->getSku(),
  443.                         "productMagento" => null,
  444.                         "code" => $productProvider->getProviderSku(),
  445.                         "name" => $productProvider->getProviderName(),
  446.                         "price" => $productProvider->getPrice(),
  447.                         'provider' => [
  448.                             'id' => $productProvider->getProvider()->getId(),
  449.                             'name' => $productProvider->getName(),
  450.                             'favoriteProvider' => $productProvider->getFavoriteProvider()
  451.                         ]
  452.                     ]];
  453.                 }
  454.             $product['magentoId'] = null;
  455.             $product['gtin'] = $listingProduct->getEan13();
  456.             // les quantité min/max
  457.             $product['minQty'] = $listingProduct->getMinQty();
  458.             $product['incrementQty'] = $listingProduct->getIncrementQty();
  459.             // parti de catégorie
  460.             $productSalesChannel = new DataObject\ProductSalesChannel\Listing();
  461.             $productSalesChannel->setCondition('channelName = ? AND o_published ', ["DistriwebTeamelek"true]);
  462.             $productSalesChannel->setCondition('product__id = ?', [$listingProduct->getId()]);
  463.             $categories null;
  464.             $categoriesSalesChannel = [];
  465.             foreach ($productSalesChannel as $productSaleChannel) {
  466.                 $categoriesSalesChannel $productSaleChannel->getCategories();
  467.             }
  468.             if ($categoriesSalesChannel) {
  469.                 foreach ($categoriesSalesChannel as  $categorySalesChannel) {
  470.                     //                    $categorie = [
  471.                     //                        'id' => $categorySalesChannel->getId(),
  472.                     //                        'name' => $categorySalesChannel->getName(),
  473.                     //                        'isActive' => $categorySalesChannel->getIsActive(),
  474.                     //                        'slug' => $categorySalesChannel->getSlug(),
  475.                     //                        'description' => $categorySalesChannel->getDescription(),
  476.                     //                        'title' => $categorySalesChannel->getTitle(),
  477.                     //                        'metakey' => $categorySalesChannel->getMetakey(),
  478.                     //                        'metaDescription' => $categorySalesChannel->getMetaDescription(),
  479.                     //                    ];
  480.                     $categories[] = ObjectToArrayService::objectToArray($categorySalesChannel);
  481.                 }
  482.             }
  483.             $product['category'] = $categories;
  484.             // Brand et characteristics
  485.             $brandSorti null;
  486.             $characteristicsSorti null;
  487.             $characteristics $listingProduct->getCharacteristics();
  488.             $brand $listingProduct->getBrand();
  489.             if ($brand) {
  490.                 $brandSorti ObjectToArrayService::objectToArray($brand);
  491.             }
  492.             if ($characteristics) {
  493.                 foreach ($characteristics as $characteristic) {
  494.                     $characteristicsSorti[] = ["id" => $characteristic->getObjectId(), "name" => $characteristic->getElement()->getName(), "value" => $characteristic->getData()["val"]];
  495.                 }
  496.             }
  497.             $product['caracteristiques'] = $characteristicsSorti;
  498.             $product['brand'] = $brandSorti;
  499.             $product['images'] = ['id' => null];
  500.             $product['weight'] = $listingProduct->getGrossWeight() ? $listingProduct->getGrossWeight() : 0;
  501.             $product['volume'] = 0;
  502.             // nouveau modification par rapport de stock;
  503.             //            $product['stock'] = $listingProduct->getTotalAvailableStock();
  504.             // $stock DERD
  505.             $product['stockDerd'] = null;
  506.             if (isset($listingProduct->getChildren()[0]) && isset($listingProduct->getChildren()[0]->getChildren()[0])) {
  507.                 $product['stockDerd'] = (int)$listingProduct->getChildren()[0]->getChildren()[0]->getAvailableStock();
  508.             }
  509.             $product['stock'] = (int)$listingProduct->getTotalAvailableStock();
  510.             $product['stockSecurity'] = 0;  // stockSecurity
  511.             $product['stockDefaultMin'] = 0;  // stockDefaultMin
  512.             $product['stockDefaultSufficient'] = 0;  // stockDefaultSufficient
  513.             $product['stockDefaultMax'] = 0;  // stockDefaultMax
  514.             $product['manageStock'] = true;  // manageStock
  515.             $product['replenishmentQuantity'] = 0;   // replenishmentQuantity
  516.             $product['locationArea'] = "";  // manageStock
  517.             $product['nbCarton'] = 0;  // nbCarton
  518.             $product['nbProductsCarton'] = 0;  // nbCarton
  519.             $products[] = $product;
  520.         }
  521.         return new JsonResponse([
  522.             'status' => 'ok',
  523.             'page' => [
  524.                 "current-page" => (int) $pageNumber,
  525.                 "per-page" => (int) $perPage,
  526.                 "total" => count($listingProducts),
  527.                 "last-page" => $lastPage : (int) $lastPage,
  528.             ],
  529.             'result' => $products,
  530.         ]);
  531.     }
  532.     /**
  533.      * Récupérer les catégories
  534.      * @Route("/mdm/categories")
  535.      */
  536.     public function listCategories(Request $request)
  537.     {
  538.         $listingCategories = new DataObject\Category\Listing();
  539.         $categories = [];
  540.         $mdmUrl self::$MDM_URL;
  541.         $now = new \DateTime();
  542.         $now->sub(new \DateInterval("PT15M"));
  543.         $perPage $request->get('size') ? $request->get('size') : self::$PER_PAGE;
  544.         $pageNumber $request->get('page') ? $request->get('page') : 1;
  545.         $offset 0;
  546.         if ($pageNumber == 2$offset = ($perPage);
  547.         if ($pageNumber 2$offset = ($perPage) * ($pageNumber 1);
  548.         if (!$request->get('full')) {
  549.             $listingCategories->setCondition('o_modificationDate > ?', [$now->getTimestamp()]);
  550.         }
  551.         $listingCategories->setOffset($offset);
  552.         $listingCategories->setLimit($perPage);
  553.         $lastPage = (count($listingCategories) / $perPage);
  554.         if (is_float($lastPage)) {
  555.             $lastPage intval($lastPage) + 1;
  556.         }
  557.         foreach ($listingCategories as $key => $listingCategory) {
  558.             $category['id'] = $listingCategory->getId();
  559.             $category['name'] = $listingCategory->getName();
  560.             $category['isActive'] = $listingCategory->getIsActive();
  561.             $category['slug'] = $listingCategory->getSlug();
  562.             $category['description'] = $listingCategory->getDescription();
  563.             $category['parentCategory'] = $listingCategory->getParent() ? $listingCategory->getParent()->getId() : null;
  564.             // url image
  565.             $hotspotImage $listingCategory->getImage();
  566.             $thumbnailUrl $hotspotImage sprintf('%s%s'$mdmUrl$hotspotImage->getThumbnail()->getPath()) : null;
  567.             $category['image'] = $thumbnailUrl;
  568.             $categories[] = $category;
  569.         }
  570.         return new JsonResponse([
  571.             'status' => 'ok',
  572.             'page' => [
  573.                 "current-page" => (int) $pageNumber,
  574.                 "per-page" => (int) $perPage,
  575.                 "total" => count($listingCategories),
  576.                 "last-page" => $lastPage : (int) $lastPage,
  577.             ],
  578.             'result' => $categories,
  579.         ]);
  580.     }
  581. }