src/WebBundle/Service/SliderService.php line 80

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace WebBundle\Service;
  4. use Exception;
  5. use FlexApp\DTO\RequestCatalogDTO;
  6. use FlexApp\Service\Meta\MetaManager;
  7. use Import1CBundle\Helper\v3\ArticleHelper;
  8. use Import1CBundle\Helper\v3\InteriorHelper;
  9. use Import1CBundle\Helper\v3\TranslitNameHelper;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  12. use Symfony\Contracts\Translation\TranslatorInterface;
  13. use WebBundle\Enum\ArticleStateEnum;
  14. use WebBundle\Exception\ArticleNotAvailableNowException;
  15. use WebBundle\Helper\App;
  16. use WebBundle\Helper\ArticleSettingsHelper;
  17. use WebBundle\Helper\ConversionHelper;
  18. use WebBundle\Helper\ItemHelper;
  19. use WebBundle\Helper\LocaleHelper;
  20. use WebBundle\Helper\PathHelper;
  21. use WebBundle\Helper\StrHelper;
  22. use WebBundle\Repository\ArticleRepository;
  23. use WebBundle\Repository\BuyOrderRepository;
  24. use WebBundle\Repository\FilterRepository;
  25. use WebBundle\Repository\IdeaRepository;
  26. use WebBundle\Repository\InteriorRepository;
  27. use WebBundle\Repository\ListCountryRepository;
  28. class SliderService
  29. {
  30.     /** @required */
  31.     public ArticleRepository $articleRepository;
  32.     /** @required */
  33.     public InteriorRepository $interiorRepository;
  34.     /** @required */
  35.     public IdeaRepository $ideaRepository;
  36.     /** @required */
  37.     public BuyOrderRepository $buyOrderRepository;
  38.     /** @required */
  39.     public FilterRepository $filterRepository;
  40.     /** @required */
  41.     public ListCountryRepository $listCountryRepository;
  42.     /** @required */
  43.     public SearchService $searchService;
  44.     /** @required */
  45.     public SampleService $sampleService;
  46.     private TranslatorInterface $translator;
  47.     public function __construct(TranslatorInterface $translator)
  48.     {
  49.         $this->translator $translator;
  50.     }
  51.     /**
  52.      * @param Request $request
  53.      * @param string $token
  54.      * @param string $type
  55.      * @param array $collection
  56.      * @param string|null $elementId
  57.      * @param string|null $load
  58.      * @return array
  59.      * @throws Exception|\Doctrine\DBAL\Driver\Exception|ArticleNotAvailableNowException
  60.      */
  61.     public function getData(
  62.         Request $request,
  63.         string $token,
  64.         string $type,
  65.         array $collection,
  66.         ?string $elementId null,
  67.         ?string $load 'all'
  68.     ): array {
  69.         if ($type == 'a') {
  70.             $elementsCount $this->articleRepository->countArticlesColl(
  71.                 $collection['id'],
  72.                 $request->get('all'false)
  73.             );
  74.             $params = [
  75.                 'collection' => $collection['id'],
  76.                 'offset' => 0,
  77.                 'limit' => 200000,
  78.             ];
  79.             $elements $this->articleRepository->getArticleNativeOpt($paramstrue);
  80.             $elements $this->prepareDiscountAmountForEachArticle($elements);
  81.             $elementIdes array_column($elements'id');
  82.             $elementUrls array_column($elements'url');
  83.             $elements array_combine($elementIdes$elements);
  84.             if (in_array($elementId$elementUrls)) {
  85.                 if (
  86.                     $redirectArticle $this->articleRepository->findOneBy([
  87.                         'url' => $elementId,
  88.                         'collection' => $collection['id'],
  89.                     ])
  90.                 ) {
  91.                     $elementId $redirectArticle->getId();
  92.                 }
  93.             } elseif (array_key_exists($elementId$elements)) {
  94.                 // если ключ элемента цифровой - запросим редирект
  95.                 // https://tile.expert/ru-it/tile/del-conca/hcl-climb/a/288881155
  96.                 return [
  97.                     'redirect' => App::generateUrl(
  98.                         'app_collection_slideshow',
  99.                         [
  100.                             'factoryUrl' => $collection['factory']['url'],
  101.                             'collectionUrl' => $collection['url'],
  102.                             'type' => $type,
  103.                             'elementId' => $elements[$elementId]['url'],
  104.                         ]
  105.                     ),
  106.                 ];
  107.             } else {
  108.                 // артикула нет!
  109.                 throw new NotFoundHttpException('The element is not found');
  110.             }
  111.             $this->checkAvailableArticle($elements[$elementId]);
  112.             $res $this->getIdes($elementIdes$elementId$load);
  113.             $elements $this->articleRepository->getArticleNativeOpt(
  114.                 [
  115.                     'collection' => $collection['id'],
  116.                     'status' => $collection['status'],
  117.                     'interior' => true,
  118.                     'items' => $res['ides'],
  119.                     'isFreezed' => false,
  120.                 ],
  121.             );
  122.             $elements $this->prepareDiscountAmountForEachArticle($elements);
  123.         } else {
  124.             $elementsCount $this->interiorRepository->countInteriorsColl($collection['id']);
  125.             $res $this->interiorRepository->interiorId($elementId$collection['id']);
  126.             if (!$res) {
  127.                 $url $this->interiorRepository->interiorUrlByName($elementId$collection['id']);
  128.                 if ($url) {
  129.                     return [
  130.                         'redirect' => App::generateUrl(
  131.                             'app_collection_slideshow',
  132.                             [
  133.                                 'factoryUrl' => $collection['factory']['url'],
  134.                                 'collectionUrl' => $collection['url'],
  135.                                 'type' => 'i',
  136.                                 'elementId' => $url,
  137.                             ]
  138.                         ),
  139.                     ];
  140.                 }
  141.             }
  142.             $elementId $res;
  143.             $filter $request->get('filter');
  144.             if ($filter) {
  145.                 $searchFilter = [
  146.                     'c_id' => [$collection['id']],
  147.                     'inside' => true,
  148.                 ];
  149.                 $reqCatDTO = new RequestCatalogDTO($request$filternull);
  150.                 $oSearchService $this->searchService;
  151.                 $oSearchService->setFilter($reqCatDTO$searchFilter);
  152.                 $data $oSearchService->getSearchData();
  153.                 $keyString serialize($data);
  154.                 $key 'sphinx' md5($keyString);
  155.                 $searchTrue_cache App::getMemcache()->get($key);
  156.                 if ($searchTrue_cache !== false) {
  157.                     $searchTrue $searchTrue_cache;
  158.                 } else {
  159.                     $searchTrue App::searchSphinx($data0true);
  160.                     App::getMemcache()->set($key$searchTrue);
  161.                 }
  162.                 $elementIdesAll_ $this->interiorRepository->getInteriorsForSlider(
  163.                     $collection['id'],
  164.                     ['onlyId' => true]
  165.                 );
  166.                 if (!empty($searchTrue[0]['interiors'])) {
  167.                     $elementIdesFind array_column($searchTrue[0]['interiors'], 'i_id');
  168.                     if (in_array($elementId$elementIdesFind)) {
  169.                         $elementIdes array_values($elementIdesFind);
  170.                     } else {
  171.                         $elementIdes array_column($elementIdesAll_'id');
  172.                         $elementIdes array_values(array_diff($elementIdes$elementIdesFind));
  173.                     }
  174.                     $elementsCount count($elementIdes);
  175.                 } else {
  176.                     $elementIdes array_column($elementIdesAll_'id');
  177.                 }
  178.                 $res $this->getIdes($elementIdes$elementId$load);
  179.                 $elements $this->interiorRepository->getInteriorsForSlider(
  180.                     $collection['id'],
  181.                     ['ids' => $res['ides']]
  182.                 );
  183.                 foreach ($elements as &$element) {
  184.                     $element InteriorHelper::getInteriorDetails($element$element['collection'], null$filter);
  185.                 }
  186.             } else {
  187.                 $elementIdes $this->interiorRepository->getInteriorsForSlider($collection['id'], ['onlyId' => true]);
  188.                 $res $this->getIdes(array_column($elementIdes'id'), $elementId$load);
  189.                 $elements $this->interiorRepository->getInteriorsForSlider(
  190.                     $collection['id'],
  191.                     ['ids' => $res['ides']]
  192.                 );
  193.                 foreach ($elements as &$element) {
  194.                     $element InteriorHelper::getInteriorDetails($element$element['collection']);
  195.                 }
  196.             }
  197.         }
  198.         $favorites $this->ideaRepository->getInteriorsIdeasByToken($token);
  199.         $nameF $collection['factory']['name'];
  200.         $pos = isset($collection['factory']['name']) ? strpos($collection['factory']['name'], '&prime;') : false;
  201.         if ($pos !== false) {
  202.             $name TranslitNameHelper::replacePrime($collection['factory']['name'], false);
  203.             $nameF $name;
  204.         }
  205.         $titleData = [
  206.             'c_id' => $collection['id'],
  207.             'c_name' => $collection['name'],
  208.             'c_satus' => $collection['status'],
  209.             'f_id' => $collection['factory']['id'],
  210.             'f_name' => $nameF,
  211.             'f_satus2' => $collection['factory']['status'],
  212.             'code' => $collection['factory']['country']['code'],
  213.             'type' => $type,
  214.             'elsCount' => $elementsCount,
  215.         ];
  216.         $buyOrderArticle $this->buyOrderRepository->getInfoBuyOrderArticle($token);
  217.         $samplesArray = [];
  218.         if ($request->get('sample')) {
  219.             $samplesArray $this->sampleService
  220.                 ->getSamplesData(
  221.                     array_column($elements'code'),
  222.                     (string)App::getCurCountryId(),
  223.                     false,
  224.                     LocaleHelper::getCur(),
  225.                     LocaleHelper::getUserMeasure()
  226.                 );
  227.         }
  228.         $newElements = [];
  229.         $ordersItems $this->buyOrderRepository->getInfoBuyOrderArticle($token);
  230.         foreach ($elements as $row) {
  231.             $row $this->unsetInactiveArticleInInteriorOrCollection($row);
  232.             $newElements[$row['id']] = $newElements[$row['id']] ?? $row;
  233.             $newElements[$row['id']]['name'] = html_entity_decode($row['name']);
  234.             $newElements[$row['id']]['alternateName'] = empty($row['alternateName']) ? null html_entity_decode(
  235.                 $row['alternateName']
  236.             );
  237.             $newElements[$row['id']]['numberElement'] = $res['numberElement'][$row ['id']];
  238.             $titleData['id'] = $row['id'];
  239.             $titleData['elNum'] = $res['numberElement'][$row['id']];
  240.             $newElements[$row['id']]['collection']['priceSort'] = LocaleHelper::getPrMin($row['collection']);
  241.             $newElements[$row['id']]['collection']['priceSortCur'] = LocaleHelper::getCurrency();
  242.             $newElements[$row['id']]['collection']['priceSortMea'] = LocaleHelper::getUserMeasure();
  243.             $this->addInfoAboutAvailableInCountryOfFactory($row['collection'], $newElements[$row['id']]);
  244.             $furl $row['collection']['factory']['url'] ?? null;
  245.             $curl $row['collection']['url'] ?? null;
  246.             if ($type == 'i') {
  247.                 if (empty($row['file'])) {
  248.                     $row['file'] = StrHelper::toLower($row['name']) . '.jpg';
  249.                 } else {
  250.                     $row['file'] = StrHelper::toLower($row['file']);
  251.                 }
  252.                 //todo временно
  253.                 if (!empty($newElements[$row['id']]['collection']['process'])) {
  254.                     $row['file'] = preg_replace('#\.jpg#i''.webp'$row['file']);
  255.                     $isWebp $newElements[$row['id']]['collection']['a_version'] = true;
  256.                 } else {
  257.                     $isWebp $newElements[$row['id']]['collection']['a_version'] = false;
  258.                 }
  259.                 foreach ($row['articles'] as $n => $article) {
  260.                     if (empty($article['collection'])) {
  261.                         unset($newElements[$row['id']]['articles'][$n]);
  262.                         continue;
  263.                     }
  264.                     $afurl $article['collection']['factory']['url'] ?? null;
  265.                     $acurl $article['collection']['url'] ?? null;
  266.                     $article['name'] = html_entity_decode($article['name']);
  267.                     $article['alternateName'] = empty($article['alternateName']) ? null html_entity_decode(
  268.                         $article['alternateName']
  269.                     );
  270.                     $article['addUrl'] = App::generateUrl(
  271.                         'app_buy_orders_list',
  272.                         [
  273.                             'articleId' => $article['id'],
  274.                         ]
  275.                     );
  276.                     $article['sampleUrl'] = App::generateUrl('app_order_sample', ['code' => $article['code']]);
  277.                     $article['collectionUrl'] = App::generateUrl(
  278.                         'app_collection',
  279.                         [
  280.                             'factoryUrl' => $afurl,
  281.                             'collectionUrl' => $acurl,
  282.                         ]
  283.                     );
  284.                     $article['factoryUrl'] = App::generateUrl(
  285.                         'app_catalog',
  286.                         [
  287.                             'key' => $afurl,
  288.                         ]
  289.                     );
  290.                     $article['prc'] = LocaleHelper::getPrice($article);
  291.                     $article['mea'] = App::trans(LocaleHelper::getMeasure($article));
  292.                     // рассчитываем размер в inch-ах
  293.                     $article['sizeGbX'] = ConversionHelper::convertInch((float)$article['sizeX'], ConversionHelper::CM);
  294.                     $article['sizeGbY'] = ConversionHelper::convertInch((float)$article['sizeY'], ConversionHelper::CM);
  295.                     $article['sizeGbZ'] = ConversionHelper::convertInch((float)$article['sizeZ'], ConversionHelper::CM);
  296.                     $article['amount'] = LocaleHelper::getAmount($article);
  297.                     $article['orders'] = !empty($ordersItems[$article['id']]) ? $ordersItems[$article['id']] : false;
  298.                     $article['ssLink'] = App::generateUrl(
  299.                         'app_collection_slideshow',
  300.                         [
  301.                             'factoryUrl' => $afurl,
  302.                             'collectionUrl' => $acurl,
  303.                             'type' => 'a',
  304.                             'elementId' => $article['url'],
  305.                         ]
  306.                     );
  307.                     $article['imageSettingIcon'] = ArticleHelper::getPathArticleImageSettings($article);
  308.                     $article['shape'] = [
  309.                         'id' => $article['shape']['id'],
  310.                         'alias' => App::trans($article['shape']['alias']),
  311.                     ];
  312.                     if ($isWebp) {
  313.                         $articleFileNameWebp preg_replace('#\.jpg#i''.webp'$article['details']['file']);
  314.                     } else {
  315.                         $articleFileNameWebp $article['details']['file'];
  316.                     }
  317.                     $article['pathImg'] = PathHelper::pathGenerate(
  318.                         'article',
  319.                         [
  320.                             'factoryUrl' => $afurl,
  321.                             'collectionUrl' => $acurl,
  322.                             'file' => 'b_' $articleFileNameWebp,
  323.                         ]
  324.                     );
  325.                     if (!empty($article['commentSchemeImage'])) {
  326.                         $article['commentSchemeImage'] = PathHelper::pathGenerate(
  327.                             'article',
  328.                             [
  329.                                 'factoryUrl' => $afurl,
  330.                                 'collectionUrl' => $acurl,
  331.                                 'file' => 'b_' $article['details']['commentSchemeImage'],
  332.                             ]
  333.                         );
  334.                     }
  335.                     $alt[] = $article['name'];
  336.                     foreach ($article['textures'] as $k => $texture) {
  337.                         $article['textures'][$k]['alias'] = $alt[] = App::trans($texture['alias']);
  338.                     }
  339.                     if (!empty($article['details']['variantImage']['texture'])) {
  340.                         $article['details']['variantImage']['texture'] = ItemHelper::addMainPic(
  341.                             $article['details']['variantImage']['texture'],
  342.                             $articleFileNameWebp
  343.                         );
  344.                     }
  345.                     if (!empty($article['details']['variantImage']['picture'])) {
  346.                         $article['details']['variantImage']['picture'] = ItemHelper::addMainPic(
  347.                             $article['details']['variantImage']['picture'],
  348.                             $articleFileNameWebp
  349.                         );
  350.                     }
  351.                     $article $this->getDiscountsAmount($article);
  352.                     $coords = [];
  353.                     if (!empty($article['coordItems'])) {
  354.                         foreach ($article['coordItems'] as $coord) {
  355.                             $interiorId $coord['interior']['id'] ?? null;
  356.                             if ($interiorId == $row['id']) {
  357.                                 $coords[] = [
  358.                                     'id' => $coord['id'],
  359.                                     'coordX' => $coord['coordX'],
  360.                                     'coordY' => $coord['coordY'],
  361.                                     'typePointer' => $coord['typePointer'],
  362.                                     'interiorId' => $coord['interior']['id'],
  363.                                     'articleId' => $coord['article']['id'],
  364.                                 ];
  365.                             }
  366.                         }
  367.                     }
  368.                     unset($article['coordItems']);
  369.                     $article['coordItems'] = $coords;
  370.                     $article['url'] = !empty($article['url']) ? $article['url'] : $article['name'];
  371.                     if (!empty($buyOrderArticle[$article['id']])) {
  372.                         $article['orders'] = $buyOrderArticle[$article['id']];
  373.                     } else {
  374.                         $article['orders'] = [];
  375.                     }
  376.                     $pos = isset($article['collection']['factory']['name'])
  377.                         ? strpos($article['collection']['factory']['name'], '&prime;')
  378.                         : false;
  379.                     if ($pos !== false) {
  380.                         $name TranslitNameHelper::replacePrime($article['collection']['factory']['name'], false);
  381.                         $alternateName TranslitNameHelper::replacePrime(
  382.                             $article['collection']['factory']['alternateName'],
  383.                             false
  384.                         );
  385.                         $article['collection']['factory']['name'] = $name;
  386.                         $article['collection']['factory']['alternateName'] = $alternateName;
  387.                     }
  388.                     $newElements[$row['id']]['articles'][$n] = ArticleHelper::getTileArticleAddOptions($article);
  389.                 }
  390.                 if (!empty($newElements[$row['id']]['articles'])) {
  391.                     $newElements[$row['id']]['articles'] = array_values($newElements[$row['id']]['articles']);
  392.                 }
  393.                 $pos = isset($row['collection']['factory']['name'])
  394.                     ? strpos($row['collection']['factory']['name'], '&prime;')
  395.                     : false;
  396.                 if ($pos !== false) {
  397.                     $name TranslitNameHelper::replacePrime($row['collection']['factory']['name'], false);
  398.                     $alternateName TranslitNameHelper::replacePrime(
  399.                         $row['collection']['factory']['alternateName'],
  400.                         false
  401.                     );
  402.                     $newElements[$row['id']]['collection']['factory']['name'] = $name;
  403.                     $newElements[$row['id']]['collection']['factory']['alternateName'] = $alternateName;
  404.                 }
  405.                 $newElements[$row['id']]['inIdeaBook'] = in_array($row['id'], $favorites);
  406.                 $newElements[$row['id']]['url'] = $row['url'];
  407.                 $newElements[$row['id']]['paths'] = [
  408.                     'hd' => !empty($row['fileSizeHDY']) ?
  409.                         PathHelper::pathGenerate(
  410.                             'interior',
  411.                             [
  412.                                 'factoryUrl' => $furl,
  413.                                 'collectionUrl' => $curl,
  414.                                 'file' => 'hd_' $row['file'],
  415.                             ]
  416.                         )
  417.                         : null,
  418.                     'shd_1080' => !empty($row['fileSizeSHDY'])
  419.                         ? PathHelper::pathGenerate(
  420.                             'interior',
  421.                             [
  422.                                 'factoryUrl' => $furl,
  423.                                 'collectionUrl' => $curl,
  424.                                 'file' => 'shd_' $row['file'],
  425.                             ]
  426.                         )
  427.                         : null,
  428.                     's_900' => PathHelper::pathGenerate(
  429.                         'interior',
  430.                         [
  431.                             'factoryUrl' => $furl,
  432.                             'collectionUrl' => $curl,
  433.                             'file' => $row['file'],
  434.                         ]
  435.                     ),
  436.                 ];
  437.                 $newElements[$row['id']]['pathImg'] = PathHelper::pathGenerate(
  438.                     'interior',
  439.                     [
  440.                         'factoryUrl' => $furl,
  441.                         'collectionUrl' => $curl,
  442.                         'file' => $row['file'],
  443.                     ]
  444.                 );
  445.                 $alt[] = $row['name'];
  446.                 foreach ($row['textures'] as $k => $texture) {
  447.                     $newElements[$row['id']]['textures'][$k]['alias'] = $alt[] = App::trans($texture['alias']);
  448.                 }
  449.                 $titleData['i_name'] = $res['numberElement'][$row['id']];
  450.                 $titleData['numberPhoto'] = $res['numberElement'][$row['id']];
  451.                 $titleData['minPrice'] = $this->interiorRepository->getArticleMinPriceByInteriorId($row['id']);
  452.             } else {
  453.                 $titleData['a_name'] = $row['name'];
  454.                 if ($request->get('sample')) {
  455.                     $newElements[$row['id']]['sampleData'] = $samplesArray[$row['code']] ?? [];
  456.                 } else {
  457.                     $newElements[$row['id']]['sampleData'] = null;
  458.                 }
  459.                 // todo удалить при первой возможности - вынести из цикла!
  460.                 $titleData['minPrice'] = $this->articleRepository->getArticleMinPriceById($row['id']);
  461.                 $newElements[$row['id']]['addUrl'] = App::generateUrl(
  462.                     'app_buy_orders_list',
  463.                     [
  464.                         'articleId' => $row['id'],
  465.                     ]
  466.                 );
  467.                 $newElements[$row['id']]['sampleUrl'] = App::generateUrl(
  468.                     'app_order_sample',
  469.                     [
  470.                         'code' => $row['code'],
  471.                     ]
  472.                 );
  473.                 $newElements[$row['id']]['collectionUrl'] = App::generateUrl(
  474.                     'app_collection',
  475.                     [
  476.                         'factoryUrl' => $furl,
  477.                         'collectionUrl' => $curl,
  478.                     ]
  479.                 );
  480.                 $newElements[$row['id']]['factoryUrl'] = App::generateUrl(
  481.                     'app_catalog',
  482.                     [
  483.                         'key' => $furl,
  484.                     ]
  485.                 );
  486.                 $newElements[$row['id']]['prc'] = LocaleHelper::getPrice($row);
  487.                 $newElements[$row['id']]['mea'] = App::trans(LocaleHelper::getMeasure($row));
  488.                 $newElements[$row['id']]['amount'] = LocaleHelper::getAmount($row);
  489.                 $newElements[$row['id']]['orders'] = !empty($ordersItems[$row['id']]) ? $ordersItems[$row['id']] : false;
  490.                 $newElements[$row['id']]['ssLink'] = App::generateUrl(
  491.                     'app_collection_slideshow',
  492.                     [
  493.                         'factoryUrl' => $furl,
  494.                         'collectionUrl' => $curl,
  495.                         'type' => 'a',
  496.                         'elementId' => $row['url'],
  497.                     ]
  498.                 );
  499.                 $newElements[$row['id']]['file'] = $row['details']['file'] ?? null;
  500.                 $newElements[$row['id']]['pathImg'] = PathHelper::pathGenerate(
  501.                     'article',
  502.                     [
  503.                         'factoryUrl' => $furl,
  504.                         'collectionUrl' => $curl,
  505.                         'file' => 'b_' $row['details']['file'] ?? null,
  506.                     ]
  507.                 );
  508.                 if ($row['details']['commentSchemeImage']) {
  509.                     $newElements[$row['id']]['commentSchemeImage'] = PathHelper::pathGenerate(
  510.                         'article',
  511.                         [
  512.                             'factoryUrl' => $furl,
  513.                             'collectionUrl' => $curl,
  514.                             'file' => $row['details']['commentSchemeImage'],
  515.                         ]
  516.                     );
  517.                 }
  518.                 if ($row['shape']) {
  519.                     $newElements[$row['id']]['shape'] = [
  520.                         'id' => $row['shape']['id'],
  521.                         'alias' => App::trans($row['shape']['alias']),
  522.                     ];
  523.                 }
  524.                 $variantImage $row['details']['variantImage'] ?? null;
  525.                 if ($variantImage) {
  526.                     if ($variantImage['texture'] ?? null) {
  527.                         $newElements[$row['id']]['variantImage']['texture'] = ItemHelper::addMainPic(
  528.                             $variantImage['texture'],
  529.                             $row['details']['file']
  530.                         );
  531.                     }
  532.                     if ($variantImage['picture'] ?? null) {
  533.                         $newElements[$row['id']]['variantImage']['picture'] = ItemHelper::addMainPic(
  534.                             $variantImage['picture'],
  535.                             $row['details']['file']
  536.                         );
  537.                     }
  538.                 }
  539.                 $filesEdit $row['details']['fileEdit'] ?? null;
  540.                 if ($filesEdit) {
  541.                     foreach ($filesEdit as $fileEdit) {
  542.                         // генерируем список загружаемых картинок
  543.                         $newElements[$row['id']]['fileEdit'] = PathHelper::pathGenerate(
  544.                             'article',
  545.                             [
  546.                                 'factoryUrl' => $furl,
  547.                                 'collectionUrl' => $curl,
  548.                                 'file' => $fileEdit,
  549.                             ]
  550.                         );
  551.                     }
  552.                 }
  553.                 $newElements[$row['id']]['imageZipLink'] = null;
  554.                 $alt[] = $row['name'];
  555.                 $textures $row['textures'];
  556.                 foreach ($textures as $k => $texture) {
  557.                     $newElements[$row['id']]['textures'][$k]['alias'] = $alt[] = App::trans($texture['alias']);
  558.                 }
  559.                 // Формируем metaTitle для артикулов
  560.                 $titleData['metaTitle'] = $this->buildArticleMetaTitle($row$collection);
  561.                 if (!empty($row['interiors'])) {
  562.                     foreach ($row['interiors'] as $i => $r) {
  563.                         if (
  564.                             $r['status'] == 2
  565.                             || $r['collection']['status'] != 1
  566.                             || $r['collection']['factory']['status'] != 1
  567.                         ) {
  568.                             if (!empty($newElements[$row['id']]['interiors'][$i])) {
  569.                                 unset($newElements[$row['id']]['interiors'][$i]);
  570.                             }
  571.                             continue;
  572.                         }
  573.                         $newElements[$row['id']]['interiors'][$i]['url'] = $r['url'];
  574.                         $newElements[$row['id']]['interiors'][$i]['inIdeaBook'] = in_array($r['id'], $favorites);
  575.                         if (empty($r['file'])) {
  576.                             $r['file'] = $r['name'] . '.jpg';
  577.                         }
  578.                         if (preg_match('#/f/(.*)/a/#is'App::getRequest()->getUri(), $matches)) {
  579.                             $url App::generateUrl('app_collection_slideshow_f', [
  580.                                 'factoryUrl' => $r['collection']['factory']['url'],
  581.                                 'collectionUrl' => $r['collection']['url'],
  582.                                 'filter' => $matches[1],
  583.                                 'type' => 'i',
  584.                                 'elementId' => $r['url'],
  585.                             ]);
  586.                         } else {
  587.                             $url App::generateUrl('app_collection_slideshow', [
  588.                                 'factoryUrl' => $r['collection']['factory']['url'],
  589.                                 'collectionUrl' => $r['collection']['url'],
  590.                                 'type' => 'i',
  591.                                 'elementId' => $r['url'],
  592.                             ]);
  593.                         }
  594.                         $r['file'] = StrHelper::toLower($r['file']);
  595.                         $newElements[$row['id']]['interiors']['setting'] = $r['collection']['settings'];
  596.                         $newElements[$row['id']]['interiors'][$i]['url'] = $url;
  597.                         $newElements[$row['id']]['interiors'][$i]['paths'] = [
  598.                             'hd' => !empty($r['fileSizeHDY']) ?
  599.                                 PathHelper::pathGenerate(
  600.                                     'interior',
  601.                                     [
  602.                                         'factoryUrl' => $r['collection']['factory']['url'],
  603.                                         'collectionUrl' => $r['collection']['url'],
  604.                                         'file' => 'hd_' $r['file'],
  605.                                     ]
  606.                                 )
  607.                                 : null,
  608.                             'shd_1080' => !empty($r['fileSizeSHDY'])
  609.                                 ? PathHelper::pathGenerate(
  610.                                     'interior',
  611.                                     [
  612.                                         'factoryUrl' => $r['collection']['factory']['url'],
  613.                                         'collectionUrl' => $r['collection']['url'],
  614.                                         'file' => 'shd_' $r['file'],
  615.                                     ]
  616.                                 )
  617.                                 : null,
  618.                             's_900' => PathHelper::pathGenerate(
  619.                                 'interior',
  620.                                 [
  621.                                     'factoryUrl' => $r['collection']['factory']['url'],
  622.                                     'collectionUrl' => $r['collection']['url'],
  623.                                     'file' => $r['file'],
  624.                                 ]
  625.                             ),
  626.                         ];
  627.                     }
  628.                 } else {
  629.                     $newElements[$row['id']]['interiors'] = [];
  630.                 }
  631.                 $newElements[$row['id']] = ArticleHelper::getTileArticleAddOptions($newElements[$row['id']]);
  632.             }
  633.             if (!empty($newElements[$row['id']]['interiors'])) {
  634.                 unset($newElements[$row['id']]['interiors']['setting']);
  635.                 // необходимо, чтобы выровнять ключи
  636.                 $newElements[$row['id']]['interiors'] = array_values($newElements[$row['id']]['interiors']);
  637.             }
  638.             $metaManager = new MetaManager($titleData, [
  639.                 '_route' => 'app_collection_slideshow',
  640.                 'type' => $type,
  641.             ]);
  642.             $newElements[$row['id']]['title'] = html_entity_decode($metaManager->getTitle());
  643.             $newElements[$row['id']]['description'] = $metaManager->getDescription();
  644.             $newElements[$row['id']]['downloadArticleImageHelpTooltip'] = App::trans('download_help_tooltip');
  645.         }
  646.         return [
  647.             'elements' => $newElements,
  648.             'elementsCount' => $elementsCount,
  649.             'elementId' => $elementId,
  650.             'numberElement' => $res['numberElement'],
  651.         ];
  652.     }
  653.     /**
  654.      * @param array $elementIdes
  655.      * @param ?int $elementId
  656.      * @param ?string $load
  657.      * @return array
  658.      */
  659.     private function getIdes(array $elementIdes, ?int $elementId null, ?string $load 'all'): array
  660.     {
  661.         if (!in_array($load, ['left''right''all'])) {
  662.             $load 'all';
  663.         }
  664.         if ($elementId == null) {
  665.             $elementId = !empty($elementIdes[0]['id']) ? $elementIdes[0]['id'] : $elementIdes[0] ?? null;
  666.         }
  667.         $numberElement = [];
  668.         $ides = [=> 0];
  669.         foreach ($elementIdes as $k => $row) {
  670.             if ($elementId == $row) {
  671.                 $numberElement[$row] = $k 1;
  672.                 if ($load == 'all') {
  673.                     $ides[] = $row;
  674.                 }
  675.                 if ($load == 'left' || $load == 'all') {
  676.                     if (!empty($elementIdes[$k 2])) {
  677.                         $ides[] = $elementIdes[$k 2];
  678.                         $numberElement[$elementIdes[$k 2]] = $k 1;
  679.                     }
  680.                     if (!empty($elementIdes[$k 1])) {
  681.                         $ides[] = $elementIdes[$k 1];
  682.                         $numberElement[$elementIdes[$k 1]] = $k;
  683.                     }
  684.                 }
  685.                 if ($load == 'right' || $load == 'all') {
  686.                     if (!empty($elementIdes[$k 1])) {
  687.                         $ides[] = $elementIdes[$k 1];
  688.                         $numberElement[$elementIdes[$k 1]] = $k 2;
  689.                     }
  690.                     if (!empty($elementIdes[$k 2])) {
  691.                         $ides[] = $elementIdes[$k 2];
  692.                         $numberElement[$elementIdes[$k 2]] = $k 3;
  693.                     }
  694.                 }
  695.                 break;
  696.             }
  697.         }
  698.         return [
  699.             'ides' => $ides,
  700.             'numberElement' => $numberElement,
  701.         ];
  702.     }
  703.     private function unsetInactiveArticleInInteriorOrCollection(?array $element): ?array
  704.     {
  705.         $test App::isRole('ROLE_TEST');
  706.         foreach ($element['articles'] ?? [] as $key => $article) {
  707.             if ($test) {
  708.                 if ($article['collection']['status'] == 2) {
  709.                     unset($element['articles'][$key]);
  710.                 }
  711.             } else {
  712.                 if ($article['collection']['status'] != 1) {
  713.                     unset($element['articles'][$key]);
  714.                 }
  715.             }
  716.         }
  717.         return $element;
  718.     }
  719.     private function addInfoAboutAvailableInCountryOfFactory(array $collection, array &$newElement): void
  720.     {
  721.         if (!($collection['factory']['country']['code'] ?? null)) {
  722.             return;
  723.         }
  724.         switch (StrHelper::toLower($collection['factory']['country']['code'])) {
  725.             case 'it':
  726.                 $newElement['in_stock'] = $this->translator->trans('in_stock_italy');
  727.                 return;
  728.             case 'es':
  729.                 $newElement['in_stock'] = $this->translator->trans('in_stock_spain');
  730.                 return;
  731.             case 'ge':
  732.                 $newElement['in_stock'] = $this->translator->trans('in_stock_germany');
  733.                 return;
  734.             case 'ma':
  735.                 $newElement['in_stock'] = $this->translator->trans('in_stock_morocco');
  736.                 return;
  737.             case 'pt':
  738.                 $newElement['in_stock'] = $this->translator->trans('in_stock_portugal');
  739.                 return;
  740.         }
  741.     }
  742.     public function getCountryUrl(array $collection): string
  743.     {
  744.         if (empty(App::getCountryList()[StrHelper::toLower($collection['factory']['country']['code'])])) {
  745.             $countryEntity $this->listCountryRepository->getCountry($collection['factory']['country']['code']);
  746.             $countryKey '';
  747.             if ($countryEntity) {
  748.                 $countryKey $countryEntity->getAlias();
  749.             }
  750.         } else {
  751.             $countryKey App::getCountryList()[StrHelper::toLower($collection['factory']['country']['code'])]['alias'];
  752.         }
  753.         if (!$countryKey) {
  754.             return '';
  755.         }
  756.         $countryKey $this->filterRepository->getKeyByLeftMenu($countryKey);
  757.         return App::generateUrl('app_catalog', ['key' => $countryKey]);
  758.     }
  759.     /**
  760.      * @throws ArticleNotAvailableNowException
  761.      */
  762.     private function checkAvailableArticle(array $element): void
  763.     {
  764.         if ($element['delivery']['id'] === ArticleStateEnum::STATE_ITEM_DISCONTINUED) {
  765.             throw new ArticleNotAvailableNowException();
  766.         }
  767.     }
  768.     /**
  769.      * Получение информации о вариантах скидок (сколько-то от палеты и тд)
  770.      * @param $article
  771.      * @return array
  772.      * @throws Exception
  773.      */
  774.     public function getDiscountsAmount($article): array
  775.     {
  776.         // очищаем массив, чтобы избежать дублирования при повторном вызове
  777.         $article['discountsAmount'] = [];
  778.         // добавляем объект цены для js
  779.         $price LocaleHelper::getPrice($article);
  780.         $woVATPrice LocaleHelper::isWithoutVATPrice($price);
  781.         $article['discountsAmount'][] = $this->getDiscountPriceArray($price0.0$woVATPrice ?: $price0);
  782.         return $this->getMoreDiscountsAmount($article);
  783.     }
  784.     private function getMoreDiscountsAmount(array $article): array
  785.     {
  786.         if (empty($article['priceDiscounts'])) {
  787.             return $article;
  788.         }
  789.         foreach ($article['priceDiscounts'] as $k => $discount) {
  790.             if ($discount == null) {
  791.                 continue;
  792.             }
  793.             $priceDiscount LocaleHelper::getPriceDiscount($discount, ['measureId' => $article['measure']['id']]);
  794.             if (
  795.                 $k == 0
  796.                 && $article['multiplePallet'] == 1
  797.                 && $article['packagingCount'] >= $priceDiscount['amount']
  798.             ) {
  799.                 $article['discountsAmount'] = [];
  800.             } else {
  801.                 $article['discountsAmount'][count($article['discountsAmount']) - 1]['endAmount'] = $priceDiscount['amount'];
  802.             }
  803.             $woVATPrice LocaleHelper::isWithoutVATPrice($priceDiscount['price']);
  804.             $article['discountsAmount'][] = $this->getDiscountPriceArray(
  805.                 (float)$priceDiscount['price'],
  806.                 (float)$priceDiscount['amount'],
  807.                 (float)($woVATPrice ?: $priceDiscount['price']),
  808.                 $discount['fold']
  809.             );
  810.         }
  811.         return $article;
  812.     }
  813.     private function getDiscountPriceArray(float $pricefloat $amountfloat $woVATPrice$fold): array
  814.     {
  815.         return [
  816.             'price' => LocaleHelper::floatSignWithOutPostfixZeros($price),
  817.             'startAmount' => LocaleHelper::floatSignWithOutPostfixZeros($amount),
  818.             'woVATPrice' => $woVATPrice,
  819.             'fold' => $fold,
  820.         ];
  821.     }
  822.     public function prepareDiscountAmountForEachArticle(?array $elements): array
  823.     {
  824.         foreach ($elements as &$element) {
  825.             $element $this->getDiscountsAmount($element);
  826.         }
  827.         return $elements;
  828.     }
  829.     /**
  830.      * Формирование metaTitle для артикулов
  831.      * @param array $article
  832.      * @return string
  833.      */
  834.     private function buildArticleMetaTitle(array $row, array $collection): string
  835.     {
  836.         //- стиль
  837.         //- фактура
  838.         //- соответствие цвету
  839.         //- материалы "пробка" и "агломерат"
  840.         //- форма (кроме квадрата, прямоугольника и неправильной)
  841.         //- размеры
  842.         //- страну производства
  843.         $locale App::getCurLocale();
  844.         if ($row['type']['id'] != 113) {
  845.             $meta = [$row['type']['name']];
  846.         } elseif (!empty($row['colors'][0])) {
  847.             $alias $row['colors'][0]['alias'];
  848.             $meta = [
  849.                 $this->filterRepository->getSameSingleByLeft(
  850.                     $locale,
  851.                     $alias
  852.                 )
  853.             ];
  854.         } else {
  855.             $meta = [];
  856.         }
  857.         $styles $row['styles'];
  858.         foreach ($styles as $k => $style) {
  859.             $meta[] = App::trans($style['alias']);
  860.         }
  861.         $facture = [];
  862.         foreach ($row['textures'] as $k => $texture) {
  863.             //to-do добавить название группы
  864.             $newElements[$row['id']]['textures'][$k]['alias'] = $alt[] = $facture[] = App::trans($texture['alias']);
  865.         }
  866.         if (!empty($facture)) {
  867.             $result implode(', '$facture);
  868.             if (!in_array($locale, ['en''nl'])) {
  869.                 $result StrHelper::toLower($this->translator->trans('left_menu_effect', [], null$locale)) .
  870.                     (in_array(
  871.                         $locale,
  872.                         ['de''fi''sv''da''no''pt']
  873.                     ) ? ': ' ' ') . StrHelper::toLower($result);
  874.             } else {
  875.                 $result .= ' ' StrHelper::toLower($this->translator->trans('left_menu_effect', [], null$locale));
  876.             }
  877.             $meta[] = $result;
  878.         }
  879.         if ($row['type']['id'] != 113) {
  880.             $colors $row['colors'];
  881.             foreach ($colors as $k => $color) {
  882.                 $meta[] = App::trans($color['alias']);
  883.             }
  884.         }
  885.         if (in_array($row['material']['id'], [1732])) {
  886.             $meta[] = $row['material']['name'];
  887.         }
  888.         if (!in_array($row['shape']['id'], [149,])) {
  889.             $meta[] = $row['shape']['name'];
  890.         }
  891.         $metaTitle implode(', '$meta);
  892.         $metaTitle StrHelper::ucFirst($metaTitle);
  893.         if (!empty($row['sizeX'])) {
  894.             $metaTitle .= ' ' round($row['sizeX']) . 'x' round($row['sizeY']);
  895.         }
  896.         $metaTitle .= ' (' App::trans($collection['factory']['country']['alias']) . ')';
  897.         return $metaTitle;
  898.     }
  899. }