src/GlobalBundle/Twig/Extension/NavigationExtension.php line 905

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 GlobalBundle\Twig\Extension;
  15. use AppBundle\Model\Catalog\Catalog;
  16. use AppBundle\Model\Product\Product;
  17. use GlobalBundle\AppHelpers\GeneralHelper;
  18. use GlobalBundle\Website\LinkGenerator\AbstractProductLinkGenerator;
  19. use GlobalBundle\Website\LinkGenerator\CategoryLinkGenerator;
  20. use GlobalBundle\Website\LinkGenerator\ProductLinkGenerator;
  21. use Pimcore\Model\DataObject;
  22. use Pimcore\Model\DataObject\SiteMenu;
  23. use Pimcore\Model\Document;
  24. use Pimcore\Navigation\Container;
  25. use Pimcore\Navigation\Page\Document as NavDocument;
  26. use Pimcore\Twig\Extension\Templating\Navigation;
  27. use Pimcore\Twig\Extension\Templating\Placeholder;
  28. use Pimcore\Translation\Translator;
  29. use Twig\Extension\AbstractExtension;
  30. use Twig\TwigFunction;
  31. use AppBundle\Website\Tool\Text;
  32. use Pimcore\Cache;
  33. use Pimcore\Db;
  34. use Pimcore\Model\DataObject\Attributes;
  35. use GlobalBundle\Services\CatalogServices;
  36. use Pimcore\Model\DataObject\Customer;
  37. use Pimcore\Model\DataObject\RequestAnItem;
  38. use Pimcore\Model\DataObject\Status;
  39. use Pimcore\Model\DataObject\WishListComments;
  40. use Pimcore\Model\DataObject\LeadTime;
  41. use Pimcore\Model\DataObject\ProformaInvoice;
  42. class NavigationExtension extends AbstractExtension
  43. {
  44.     private $piObjectIdsByRfq = [];
  45.     private $poObjectIdsByRfq = [];
  46.     const NAVIGATION_EXTENSION_POINT_PROPERTY = 'navigation_extension_point';
  47.     const CACHE_PRIORITY = 1000;
  48.     /**
  49.      * @var CategoryLinkGenerator
  50.      */
  51.     protected $categoryLinkGenerator;
  52.     /**
  53.      * @var ProductLinkGenerator
  54.      */
  55.     protected $productLinkGenerator;
  56.     /**
  57.      * @var Navigation
  58.      */
  59.     protected $navigationHelper;
  60.     /**
  61.      * @var Placeholder
  62.      */
  63.     protected $placeholderHelper;
  64.     /**
  65.      * @param Navigation $navigationHelper
  66.      */
  67.     public function __construct(Navigation $navigationHelper, Placeholder $placeholderHelper, CategoryLinkGenerator $categoryLinkGenerator, ProductLinkGenerator $productLinkGenerator, Translator $translator)
  68.     {
  69.         $this->navigationHelper = $navigationHelper;
  70.         $this->categoryLinkGenerator = $categoryLinkGenerator;
  71.         $this->productLinkGenerator = $productLinkGenerator;
  72.         $this->placeholderHelper = $placeholderHelper;
  73.         $this->translator = $translator;
  74.     }
  75.     /**
  76.      * @return array|TwigFunction[]
  77.      */
  78.     public function getFunctions()
  79.     {
  80.         return [
  81.             new TwigFunction('app_navigation_data_links', [$this, 'getDataLinks']),
  82.             new TwigFunction('app_navigation_enrich_breadcrumbs', [$this, 'enrichBreadcrumbs']),
  83.             new TwigFunction('app_navigation_menubar', [$this, 'getMenuBar']),
  84.             new TwigFunction('app_navigation_megamenu_url', [$this, 'getMegaMenuLinks']),
  85.             new TwigFunction('app_navigation_product_details', [$this, 'getProductLinks']),
  86.             new TwigFunction('app_general_filter_translate', [$this, 'translateValues']),
  87.             new TwigFunction('app_general_filter_sort', [$this, 'sort']),
  88.             new TwigFunction('app_general_filter_sort_objects', [$this, 'sortObjects']),
  89.             new TwigFunction('app_general_filter_value_string', [$this, 'fromIdToValueStr']),
  90.             new TwigFunction('pimcore_pagination_url', [$this, 'pimcorePaginationUrl']),
  91.             new TwigFunction('app_navigation_category_url', [$this, 'getCategoryUrl']),
  92.             new TwigFunction('app_navigation_sitemap_id', [$this, 'getSitemapId']),
  93.             new TwigFunction('app_navigation_product_in_wishlist', [$this, 'getProductWishlistStatus']),
  94.             new TwigFunction('app_navigation_check_user_subscription_type', [$this, 'checkUserSubscriptionType']),
  95.             new TwigFunction('app_navigation_product_attribute_name', [$this, 'getProductAttributeName']),
  96.             new TwigFunction('app_navigation_menu_status', [$this, 'checkMenuStatus']),
  97.             new TwigFunction('app_navigation_mega_menu_status', [$this, 'checkMegaMenuStatus']),
  98.             new TwigFunction('app_navigation_rfq_status', [$this, 'rfqStatus']),
  99.             new TwigFunction('app_navigation_selected_wishlist', [$this, 'getSelectedWhislistByProduct']),
  100.             new TwigFunction('app_navigation_latest_highlight_menu', [$this, 'getLatestHighlightCatalogForMenu']),
  101.             new TwigFunction('app_product_comment', [$this, 'getProductComment']),
  102.             new TwigFunction('app_wishlist_product_comment', [$this, 'getWishlistProductComment']),
  103.             new TwigFunction('app_navigation_analytics_access', [$this, 'getAnalyticsAccess']),
  104.             new TwigFunction('app_navigation_curated_fpg_menubar', [$this, 'getCuratedFPGMenuBar']),
  105.             new TwigFunction('app_navigation_exclusive_fpg_menubar', [$this, 'getExclusiveFPGMenuBar']),
  106.             new TwigFunction('app_navigation_exclusive_random_products', [$this, 'getExclusiveRandomProducts']),
  107.             new TwigFunction('app_navigation_catalogtype', [$this, 'getCatalogTypeInMenu']),
  108.             new TwigFunction('app_navigation_unit_details', [$this, 'getQuantityUnit']),
  109.             new TwigFunction('app_CDN_url', [$this, 'getCDNurl']),
  110.             new TwigFunction('app_navigation_lead_time', [$this, 'getLeadTimeData']),
  111.             new TwigFunction('app_navigation_color', [$this, 'getColorData']),
  112.             new TwigFunction('app_navigation_field_collection', [$this, 'getRFQData']),
  113.             new TwigFunction('app_current_site', [$this, 'getCurrentSite']),
  114.             new TwigFunction('app_sub_document_category', [$this, 'getSubDocumentCategory']),
  115.             new TwigFunction('app_category_top_parent', [$this, 'getCategoryTopParent']),
  116.             new TwigFunction('app_product_id', [$this, 'getOnlyProductId']),
  117.             new TwigFunction('app_array_object_id', [$this, 'getArrayObjectsToIds']),
  118.             new TwigFunction('pimcore_complex_url', [$this, 'pimcoreComplexUrl']),
  119.             new TwigFunction('get_product_by_id', [$this, 'getSingleProductById']),
  120.             new TwigFunction('get_cmf_array', [$this, 'getCMFArray']),
  121.             new TwigFunction('get_exclusive_to_these_customers_array', [$this, 'getExclusiveCustomersArray']),
  122.             new TwigFunction('get_selected_internal_customer_ids', [$this, 'getInternalCustomersArray']),
  123.             new TwigFunction('get_selected_supplier_customer_id', [$this, 'getSupplierCustomersArray']),
  124.             new TwigFunction('get_boardcart_status', [$this, 'getBoardProductCartStatus']),
  125.             new TwigFunction('get_product_status', [$this, 'getProductStatus']),
  126.             new TwigFunction('get_status_in_field_collection', [$this, 'getCartStatusInFieldCollection']),
  127.             new TwigFunction('has_brief_response_comments', [$this, 'hasBriefResponseComments']),
  128.             new TwigFunction('has_brief_uploads_comments', [$this, 'hasBriefUploadsComments']),
  129.             new TwigFunction('get_selected_buyer_customer_id', [$this, 'getBuyerCustomersArray']),
  130.             new TwigFunction('get_selected_supplier_kam_id', [$this, 'getSupplierKAMCustomersArray']),
  131.             new TwigFunction('get_selected_supplier_internal_users_id', [$this, 'getSupplierInternalCustomersArray']),
  132.             new TwigFunction('get_selected_buyer_kam_id', [$this, 'getBuyerKAMCustomersArray']),
  133.             new TwigFunction('get_selected_buyer_internal_users_id', [$this, 'getBuyerInternalCustomersArray']),
  134.             new TwigFunction('get_rfq_generated_pi_status', [$this, 'getRFQGeneratedPIStatus']),
  135.             new TwigFunction('get_pi_obj_id', [$this, 'getPIObjId']),
  136.             new TwigFunction('get_rfq_generated_po_status', [$this, 'getRFQGeneratedPOStatus']),
  137.             new TwigFunction('get_po_obj_id', [$this, 'getPOObjId']),
  138.         ];
  139.     }
  140.     /**
  141.      * @param Document $document
  142.      * @param Document $startNode
  143.      *
  144.      * @return \Pimcore\Navigation\Container
  145.      */
  146.     public function getDataLinks(Document $document, Document $startNode)
  147.     {
  148.         $navigation = $this->navigationHelper->build([
  149.             'active' => $document,
  150.             'root' => $startNode,
  151.             'pageCallback' => function ($page, $document) {
  152.                 $rootCategory = $document->getProperty(AbstractProductLinkGenerator::ROOT_CATEGORY_PROPERTY_NAME);
  153.                 foreach ($rootCategory->getChildren() as $category) {
  154.                     $categoryPage = new NavDocument([
  155.                         'label' => $category->getLabel(),
  156.                         'id' => 'category-' . $category->getId(),
  157.                         'uri' => $category->getLabel()
  158.                     ]);
  159.                     $page->addPage($categoryPage);
  160.                 }
  161.             }
  162.         ]);
  163.         return $navigation;
  164.     }
  165.     public function getCMFArray($productId){
  166.         
  167.         $productObj = Product::getById($productId, ["force" => true]);
  168.         return $productObj;
  169.     }
  170.     public function getExclusiveCustomersArray($productId){
  171.         
  172.         $productObj = Product::getById($productId, ["force" => true]);
  173.         foreach ($productObj->getExclusiveToTheseCustomersOnly() as $key => $value) {
  174.             $customerIdsArray[] = $value->getId();
  175.         }
  176.         return $customerIdsArray;
  177.     }
  178.     public function getInternalCustomersArray($rfqId){
  179.         
  180.         $rfqObj = RequestAnItem::getById($rfqId, ["force" => true]);
  181.         $sharedWithInternal = $rfqObj->getSharedWithInternal();
  182.         $customerIdsArray = [];
  183.         if (!empty($sharedWithInternal)) {
  184.             foreach ($sharedWithInternal as $key => $value) {
  185.                 $customerIdsArray[] = $value->getId();
  186.             }
  187.         }
  188.         return $customerIdsArray;
  189.     }
  190.     public function getSupplierCustomersArray($rfqId){
  191.         
  192.         $rfqObj = RequestAnItem::getById($rfqId, ["force" => true]);
  193.         $supplierCustomer = $rfqObj->getSharedWithSupplier();
  194.         if ($supplierCustomer !== null) {
  195.             $supplierCustomerId = $supplierCustomer->getId();
  196.         } else {
  197.             $supplierCustomerId = null;
  198.         }                                                                       
  199.         return $supplierCustomerId;
  200.     }
  201.     public function getBuyerCustomersArray($rfqId){
  202.         
  203.         $rfqObj = RequestAnItem::getById($rfqId, ["force" => true]);
  204.         $buyerCustomer = $rfqObj->getBuyer();
  205.         
  206.         /*
  207.         if ($buyerCustomer !== null) {
  208.             $buyerCustomerId = $buyerCustomer->getId();
  209.         } else {
  210.             $buyerCustomerId = null;
  211.         }
  212.         return $buyerCustomerId; \
  213.         */
  214.         $buyerCustomerIds = [];
  215.         $buyerCustomers = $rfqObj->getBuyer();
  216.         if (!empty($buyerCustomers)) {
  217.             foreach ($buyerCustomers as $buyerCustomer) {
  218.                 if ($buyerCustomer !== null) {
  219.                     $buyerCustomerIds[] = $buyerCustomer->getId();
  220.                 }
  221.             }
  222.         }
  223.         return $buyerCustomerIds;
  224.     }
  225.     public function getSupplierKAMCustomersArray($rfqId){
  226.         
  227.         $rfqObj = RequestAnItem::getById($rfqId, ["force" => true]);
  228.         $supplierKAMCustomer = $rfqObj->getSharedWithSupplierKAM();
  229.         $supplierKAMCustomerIds = [];
  230.         if (!empty($supplierKAMCustomer)) {
  231.             foreach ($supplierKAMCustomer as $supplierKAM) {
  232.                 if ($supplierKAM !== null) {
  233.                     $supplierKAMCustomerIds[] = $supplierKAM->getId();
  234.                 }
  235.             }
  236.         }
  237.         return $supplierKAMCustomerIds;
  238.     }
  239.     public function getSupplierInternalCustomersArray($rfqId){
  240.         $rfqObj = RequestAnItem::getById($rfqId, ["force" => true]);
  241.         $supplierInternalCustomers = $rfqObj->getSharedWithInternalSupplier();
  242.         $supplierInternalCustomerIds = [];
  243.         if (!empty($supplierInternalCustomers)) {
  244.             foreach ($supplierInternalCustomers as $supplierInternal) {
  245.                 if ($supplierInternal !== null) {
  246.                     $supplierInternalCustomerIds[] = $supplierInternal->getId();
  247.                 }
  248.             }
  249.         }
  250.         return $supplierInternalCustomerIds;
  251.     }
  252.     public function getBuyerKAMCustomersArray($rfqId){
  253.         $rfqObj = RequestAnItem::getById($rfqId, ["force" => true]);
  254.         $buyerKAMCustomers = $rfqObj->getSharedWithBuyerKAM();
  255.         $buyerKAMCustomerIds = [];
  256.         if (!empty($buyerKAMCustomers)) {
  257.             foreach ($buyerKAMCustomers as $buyerKAM) {
  258.                 if ($buyerKAM !== null) {
  259.                     $buyerKAMCustomerIds[] = $buyerKAM->getId();
  260.                 }
  261.             }
  262.         }
  263.         return $buyerKAMCustomerIds;
  264.     }
  265.     public function getBuyerInternalCustomersArray($rfqId){
  266.         $rfqObj = RequestAnItem::getById($rfqId, ["force" => true]);
  267.         $buyerInternalUsers = $rfqObj->getSharedWithInternalBuyer();
  268.         $buyerInternalUserIds = [];
  269.         if (!empty($buyerInternalUsers)) {
  270.             foreach ($buyerInternalUsers as $buyerInternalUser) {
  271.                 if ($buyerInternalUser !== null) {
  272.                     $buyerInternalUserIds[] = $buyerInternalUser->getId();
  273.                 }
  274.             }
  275.         }
  276.         return $buyerInternalUserIds;
  277.     }
  278.     public function getProductStatus($statusId){
  279.         $productStatus = '';
  280.         if ($statusId !== null && $statusId !== '') {
  281.             try {
  282.                 $statusObj = Status::getById($statusId, ["force" => true]);
  283.                 if ($statusObj) {
  284.                     $statusName = $statusObj->getName();
  285.                     if ($statusName !== null) {
  286.                         $productStatus = $statusName;
  287.                     }
  288.                 }
  289.             } catch (\Exception $e) {
  290.                 // Log the exception or handle it as needed
  291.                 error_log('Error fetching product status: ' . $e->getMessage());
  292.             }
  293.         }
  294.         return $productStatus;
  295.     }
  296.     public function hasBriefResponseComments($id)
  297.     {
  298.         $briefResponseObj = \Pimcore\Model\DataObject\RFNResponses::getById($id);
  299.         if (!$briefResponseObj) {
  300.             return false;
  301.         }
  302.         $commentDetailsCollection = [];
  303.         $commentDetails = $briefResponseObj->getBriefResponseLevelCommentDetails();
  304.         if ($commentDetails) {
  305.             foreach ($commentDetails as $commentItem) {
  306.                 $commentData = [
  307.                     'comment' => $commentItem->getComment(),
  308.                 ];
  309.                 $attachments = $commentItem->getAttachments();
  310.                 if ($attachments) {
  311.                     $commentData['attachments'] = array_map(function ($attachment) {
  312.                         return [
  313.                             'fileName' => $attachment->getFilename(),
  314.                             'fullPath' => $attachment->getFullPath(),
  315.                         ];
  316.                     }, $attachments);
  317.                 }
  318.                 $commentDetailsCollection[] = $commentData;
  319.             }
  320.         }
  321.         return count($commentDetailsCollection) > 0 ? true : false;
  322.     }
  323.     public function hasBriefUploadsComments($id)
  324.     {
  325.         $briefUploadsObj = \Pimcore\Model\DataObject\RFNUploads::getById($id);
  326.         if (!$briefUploadsObj) {
  327.             return false;
  328.         }
  329.         $commentDetailsCollection = [];
  330.         $commentDetails = $briefUploadsObj->getBriefUploadsLevelCommentDetails();
  331.         if ($commentDetails) {
  332.             foreach ($commentDetails as $commentItem) {
  333.                 $commentData = [
  334.                     'comment' => $commentItem->getComment(),
  335.                 ];
  336.                 $attachments = $commentItem->getAttachments();
  337.                 if ($attachments) {
  338.                     $commentData['attachments'] = array_map(function ($attachment) {
  339.                         return [
  340.                             'fileName' => $attachment->getFilename(),
  341.                             'fullPath' => $attachment->getFullPath(),
  342.                         ];
  343.                     }, $attachments);
  344.                 }
  345.                 $commentDetailsCollection[] = $commentData;
  346.             }
  347.         }
  348.         return count($commentDetailsCollection) > 0 ? true : false;
  349.     }
  350.     public function getBoardProductCartStatus($productId,$customer){
  351.         $prodIds = [];
  352.         if($customer){
  353.             $rfqDataList = new DataObject\RequestForQuote\Listing();
  354.             $rfqDataList->addConditionParam("customer__id = ?", $customer->getId(), "AND");
  355.             $rfqDataList->addConditionParam("status = ?", "Validation", "AND");
  356.             $rfqDataList->addConditionParam("customerStatus NOT IN (?, ?, ?)", ["Cancelled", "Accepted", "PO received"], "AND");
  357.             $RFQData = $rfqDataList->load();
  358.             if($RFQData){
  359.                 foreach ($RFQData as $key => $value) {
  360.                     $collectionCart = $value->getRFQCollections();
  361.                     if($collectionCart) {
  362.                         foreach ($collectionCart as $key => $valueCC) {
  363.                             $product = $valueCC->getProducts();
  364.                             if ($product) {
  365.                                 $prodIds[] = $product->getId();
  366.                             }
  367.                         }
  368.                     }
  369.                 }
  370.             }
  371.         }
  372.         if(in_array($productId,$prodIds)){
  373.             return false;
  374.         }else{
  375.             return true;
  376.         }
  377.     }
  378.     public function getCategoryUrl($sitemenu)
  379.     {
  380.         $menu['label'] = $sitemenu->getLabel();
  381.         $menu['id'] = $sitemenu->getId();
  382.         $menu['url'] = "/shop/" . Text::toUrl($sitemenu->getLabel() ?? 'elements') . "~c" . $sitemenu->getId();
  383.         return $menu;
  384.     }
  385.     public function getMegaMenuLinks($megaMenuKey, $megaMenuValue, $mainURL)
  386.     {
  387.         $url = "";
  388.         $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  389.         if (!empty($customer)) {
  390.             $subscriptionType = $customer->getCompany()->getSubscription();
  391.             $curateFilter =  explode(',', GeneralHelper::getWebsiteSetting('CurateFilter'));
  392.             $signatureFilter =  explode(',', GeneralHelper::getWebsiteSetting('SignatureFilter'));
  393.             $essencialRemoveFilter = array_merge($curateFilter, $signatureFilter);
  394.             $filterArray = false;
  395.             if ($subscriptionType == "Essential") {
  396.                 if (!in_array($megaMenuKey, $essencialRemoveFilter)) {
  397.                     $filterArray = true;
  398.                 }
  399.             } elseif ($subscriptionType == "Curate") {
  400.                 if (!in_array($megaMenuKey, $signatureFilter)) {
  401.                     $filterArray = true;
  402.                 }
  403.             } else {
  404.                 $filterArray = true;
  405.             }
  406.             if (!empty($mainURL) && $filterArray == true) {
  407.                 if (false !== strpos($mainURL, '?')) {
  408.                     $params = '&' . MEGA_MENU[$megaMenuKey] . '[]=';
  409.                 } else {
  410.                     $params = '?' . MEGA_MENU[$megaMenuKey] . '[]=';
  411.                 }
  412.                 $url = $mainURL . $params . $megaMenuValue;
  413.                 $filterArray = false;
  414.             }
  415.         }
  416.         return $url;
  417.     }
  418.     public function getSitemapId($siteMenuId, $category)
  419.     {
  420.         if ($siteMenuId) {
  421.             return $siteMenuId;
  422.         } else {
  423.             $siteMenuList = new \Pimcore\Model\DataObject\SiteMenu\Listing();
  424.             $siteMenuList->setCondition("categories like '%," . $category . ",%'");
  425.             $siteMenuObject = $siteMenuList->load();
  426.             if (!empty($siteMenuObject)) {
  427.                 $customerSiteMenuData = $this->getAllSiteMenu();
  428.                 if (!empty($customerSiteMenuData)) {
  429.                     foreach ($siteMenuObject as $key => $value) {
  430.                         if (in_array($value->getId(), $customerSiteMenuData)) {
  431.                             return  $value->getId();
  432.                         }
  433.                     }
  434.                     return  $siteMenuObject[0]->getId();
  435.                 } else {
  436.                     return  $siteMenuObject[0]->getId();
  437.                 }
  438.             }
  439.         }
  440.     }
  441.     public function getMenuBar()
  442.     {
  443.         $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  444.         $menu = [];
  445.         if (!empty($customer) && !empty($customer->getCompany())) {
  446.             $cacheKey = 'frontend_product_group_' . $customer->getCompany()->getId();
  447.             if (!$menu = Cache::load($cacheKey)) {
  448.                 $menu = [];
  449.                 $customerSiteMenuData = $this->getAllSiteMenu();
  450.                 $entries = new DataObject\SiteMenu\Listing();
  451.                 $entries->setCondition("level = ?", [1]);
  452.                 $entries->setOrderKey("order");
  453.                 $entries->setOrder("asc");
  454.                 $level1Data = $entries->load();
  455.                 foreach ($level1Data as $key => $value) {
  456.                     //if($value->getLevel() == 1 || $value->getLevel() == 2){
  457.                     $menu[$key]['label'] = $value->getLabel();
  458.                     $menu[$key]['id'] = $value->getId();
  459.                     $menu[$key]['order'] = $value->getOrder();
  460.                     $mainURL = $this->genrateMainURL($value, $customerSiteMenuData);
  461.                     $menu[$key]['url'] = $mainURL;
  462.                     $megeMenuArray = $this->megaMenu($value, $mainURL);
  463.                     $menu[$key]['megaMenu'] = $megeMenuArray;
  464.                     $menu[$key]['children'] = [];
  465.                     $entries = new DataObject\SiteMenu\Listing();
  466.                     $entries->setCondition("parenLevel__id = ? AND level = ?", [$value->getId(), $value->getLevel() + 1]);
  467.                     $entries->setOrderKey("order");
  468.                     $entries->setOrder("asc");
  469.                     $level2Data = $entries->load();
  470.                     if (!empty($level2Data)) {
  471.                         $menu[$key]['children']  =  $this->getRecurciveCategory($level2Data, $customerSiteMenuData);
  472.                     }
  473.                     //}
  474.                 }
  475.                 Cache::save($menu, $cacheKey, [$cacheKey], null, self::CACHE_PRIORITY, true);
  476.             }
  477.         }
  478.         return $menu;
  479.     }
  480.     public function getAllSiteMenu()
  481.     {
  482.         $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  483.         $siteMenuDataArray = [];
  484.         if ($customer) {
  485.             $sitemenuData = $customer->getCompany()->getSiteMenuCategory();
  486.             foreach ($sitemenuData as $siteKey => $siteValue) {
  487.                 $siteMenuDataArray[] = $siteValue->getId();
  488.                 if($siteValue->getLevel() == 3){
  489.                     $siteMenuDataArray[] = $siteValue->getParenLevel()->getId();
  490.                 
  491.                     $siteMenuDataArray[] = $siteValue->getParenLevel()->getParent()->getId();
  492.                 }elseif ($siteValue->getLevel() == 2) {
  493.                     $siteMenuDataArray[] = $siteValue->getParenLevel()->getId();
  494.                     $entries = new DataObject\SiteMenu\Listing();
  495.                     $entries->setCondition("parenLevel__id = ? AND level = ?", [$siteValue->getId(), 3]);
  496.                     $entries->setOrderKey("order");
  497.                     $entries->setOrder("asc");
  498.                     $level3Data = $entries->load();
  499.                     foreach ($level3Data as $key => $value) {
  500.                         $siteMenuDataArray[] = $value->getId();
  501.                     }
  502.                 } elseif ($siteValue->getLevel() == 1) {
  503.                     $entries = new DataObject\SiteMenu\Listing();
  504.                     $entries->setCondition("parenLevel__id = ? AND level = ?", [$siteValue->getId(), 2]);
  505.                     $entries->setOrderKey("order");
  506.                     $entries->setOrder("asc");
  507.                     $level2Data = $entries->load();
  508.                     foreach ($level2Data as $value) {
  509.                         $siteMenuDataArray[] = $value->getId();
  510.                         $entries = new DataObject\SiteMenu\Listing();
  511.                         $entries->setCondition("parenLevel__id = ? AND level = ?", [$value->getId(), 3]);
  512.                         $entries->setOrderKey("order");
  513.                         $entries->setOrder("asc");
  514.                         $level3Data = $entries->load();
  515.                         foreach ($level3Data as $k => $v) {
  516.                             $siteMenuDataArray[] = $v->getId();
  517.                         }
  518.                     }
  519.                 }
  520.             }
  521.         }
  522.         return array_unique($siteMenuDataArray);
  523.     }
  524.     public function genrateMainURL($value, $customerSiteMenuData)
  525.     {
  526.         $mainURL = "";
  527.         $object = new Product();
  528.         $db = Db::get();
  529.         if (!empty($value->getFrontendFilter()->getItems())) {
  530.             $frontendFilterArray = [];
  531.             $whereUrl = "";
  532.             foreach ($value->getFrontendFilter()->getItems() as $frontendFilterKey => $frontendFilterValue) {
  533.                 $frontendFilterQuery = "SELECT name FROM classificationstore_keys WHERE id IN (" . $frontendFilterKey . ")";
  534.                 $frontendGroupName = $db->fetchColumn($frontendFilterQuery);
  535.                 $fieldOptionsPro = $object->getClass()->getFieldDefinition(MEGA_MENU[$frontendGroupName]);
  536.                 foreach ($fieldOptionsPro->getOptions() ?: [] as $frontendOptionKey => $frontendOptionValue) {
  537.                     if (in_array($frontendOptionValue['value'], $frontendFilterValue[$frontendFilterKey]['default'])) {
  538.                         //$frontendFilterArray[$frontendGroupName][$frontendOptionValue['value']] =  $frontendOptionValue['key'];
  539.                         $whereUrl .= '&' . MEGA_MENU[$frontendGroupName] . '[]=' . $frontendOptionValue['value'];
  540.                     }
  541.                 }
  542.             }
  543.             if (in_array($value->getId(), $customerSiteMenuData)) {
  544.                 $mainURL = "/shop/" . Text::toUrl($value->getLabel() ?? 'elements') . "~c" . $value->getId() . '?' . substr($whereUrl, 1);
  545.             }
  546.         } else {
  547.             if (in_array($value->getId(), $customerSiteMenuData)) {
  548.                 $mainURL = "/shop/" . Text::toUrl($value->getLabel() ?? 'elements') . "~c" . $value->getId();
  549.             }
  550.         }
  551.         return $mainURL;
  552.     }
  553.     public function megaMenu($value, $mainURL)
  554.     {
  555.         $object = new Product();
  556.         $db = Db::get();
  557.         $megeMenuArray = [];
  558.         $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  559.         if (!empty($value->getCurateFilter()->getItems())) {
  560.             foreach ($value->getCurateFilter()->getItems() as $megaMenuKey => $megaMenuValue) {
  561.                 $keySqlQuery = "SELECT name FROM classificationstore_keys WHERE id IN (" . $megaMenuKey . ")";
  562.                 $groupName = $db->fetchColumn($keySqlQuery);
  563.                 $fieldOptions = $object->getClass()->getFieldDefinition(MEGA_MENU[$groupName]);
  564.                 foreach ($fieldOptions->getOptions() ?: [] as $optionKey => $optionValue) {
  565.                     if (in_array($optionValue['value'], $megaMenuValue[$megaMenuKey]['default'])) {
  566.                         $subscriptionType = $customer->getCompany()->getSubscription();
  567.                         $curateFilter =  explode(',', GeneralHelper::getWebsiteSetting('CurateFilter'));
  568.                         $signatureFilter =  explode(',', GeneralHelper::getWebsiteSetting('SignatureFilter'));
  569.                         $essencialRemoveFilter = array_merge($curateFilter, $signatureFilter);
  570.                         $filterArray = false;
  571.                         if ($subscriptionType == "Essential") {
  572.                             if (!in_array(MEGA_MENU[$groupName], $essencialRemoveFilter)) {
  573.                                 $filterArray = true;
  574.                             }
  575.                         } elseif ($subscriptionType == "Curate") {
  576.                             if (!in_array(MEGA_MENU[$groupName], $signatureFilter)) {
  577.                                 $filterArray = true;
  578.                             }
  579.                         } else {
  580.                             $filterArray = true;
  581.                         }
  582.                         $megaMenuURL = "";
  583.                         if (!empty($mainURL) && $filterArray == true) {
  584.                             if (false !== strpos($mainURL, '?')) {
  585.                                 $params = '&' . MEGA_MENU[$groupName] . '[]=';
  586.                             } else {
  587.                                 $params = '?' . MEGA_MENU[$groupName] . '[]=';
  588.                             }
  589.                             $megaMenuURL = $mainURL . $params . $optionValue['value'];
  590.                             $filterArray = false;
  591.                         }
  592.                         $megeMenuArray[$groupName][$optionValue['key']] = $megaMenuURL;
  593.                     }
  594.                 }
  595.             }
  596.         }
  597.         return $megeMenuArray;
  598.     }
  599.     public function getRecurciveCategory($sitemenu, $customerSiteMenuData)
  600.     {
  601.         $menu = [];
  602.         foreach ($sitemenu as $key => $value) {
  603.             $label = $value->getLocalizedfields()->getLocalizedValue("label", "en");
  604.             $menu[$key]['label'] = $label;
  605.             $menu[$key]['id'] = $value->getId();
  606.             $menu[$key]['order'] = $value->getOrder();
  607.             if (in_array($value->getId(), $customerSiteMenuData)) {
  608.                 $mainURL = $this->genrateMainURL($value, $customerSiteMenuData);
  609.                 //$menu[$key]['url'] = "/shop/".Text::toUrl($value->getLabel() ?? 'elements')."~c".$value->getId();
  610.                 $menu[$key]['url'] = $mainURL;
  611.             }
  612.             if ($value->getLevel() == 2) {
  613.                 $menu[$key]['image'] = !empty($value->getImage()) ? $value->getImage() : '';
  614.             }
  615.             $entries = new DataObject\SiteMenu\Listing();
  616.             $entries->setCondition("parenLevel__id = ? AND level = ?", [$value->getId(), 3]);
  617.             $entries->setOrderKey("order");
  618.             $entries->setOrder("asc");
  619.             $level3Data = $entries->load();
  620.             if (!empty($level3Data)) {
  621.                 $menu[$key]['children'] = $this->getRecurciveCategory($level3Data, $customerSiteMenuData);
  622.             }
  623.         }
  624.         return $menu;
  625.     }
  626.     public function getProductLinks($product)
  627.     {
  628.         $url = "";
  629.         if (!empty($product)) {
  630.             $url = $this->productLinkGenerator->generateWithMockup($product, []);
  631.         }
  632.         return $url;
  633.     }
  634.     /**
  635.      * @param Container $navigation
  636.      *
  637.      * @return Container
  638.      *
  639.      * @throws \Exception
  640.      */
  641.     public function enrichBreadcrumbs()
  642.     {
  643.         $breadctumbsArray = [];
  644.         $findArr = array($_SERVER['HTTP_HOST'].'/', 'http://', 'https://');
  645.         $replaceArr = array('','','');
  646.         $prev_url = str_replace($findArr,$replaceArr,$_SERVER['HTTP_REFERER'] ?? '');
  647.         $SCList = new DataObject\SalesCampaign\Listing();
  648.         $SCList->setCondition("shareableLink = '" . $prev_url."'");
  649.         $SCData = $SCList->load();
  650.         $currentUrl = $_SERVER['REQUEST_URI'];
  651.         $url_data   = array_values(array_filter(explode('/',$currentUrl)));  
  652.         $path       = array_values(array_filter(explode('/', parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))));
  653.         $params     = $url_data[1] ?? '';
  654.         $last_url   = $_SERVER['HTTP_REFERER'] ?? '';
  655.         if(($url_data[0] ?? null)=='catalog-product-listing'){
  656.             $catalogId  = $path[1];
  657.             $type_data  = explode('=',$params);
  658.             $type       = $type_data[1];
  659.             $myObject   = DataObject\Catalog::getById($catalogId);
  660.             $name       = $myObject->getName();
  661.             $prevUrlData= array_values(array_filter(explode('=',$last_url)));  
  662.             $lastUrlData= end($prevUrlData);
  663.             if($type=='curate'){
  664.                 if($lastUrlData=='allcurater'){
  665.                     $showLabel = 'All Curate';
  666.                 }else if($lastUrlData=='alldesigner'){
  667.                     $showLabel = 'All Designer';
  668.                 }else{
  669.                     $showLabel = 'All Curate';
  670.                 }
  671.                 $breadctumbsArray = array(
  672.                     "level1" => array("id" => 0, "name" => $showLabel,"url"=>$last_url),
  673.                     "level2" => array("id" =>$catalogId, "name" => $name, "url" =>$currentUrl),
  674.                 );
  675.             }elseif($type == 'signature'){
  676.                 if($lastUrlData=='alllicences'){
  677.                     $showLabel = 'All Licences';
  678.                 }else if($lastUrlData=='alldesigner'){
  679.                     $showLabel = 'All Designer';
  680.                 }else if($lastUrlData=='allsignature'){
  681.                     $showLabel = 'All Exclusive';
  682.                 }
  683.                 $breadctumbsArray = array(
  684.                     "level1" => array("id" => 0, "name" => $showLabel,"url"=>$last_url),
  685.                     "level2" => array("id" =>$catalogId, "name" => $name, "url" =>$currentUrl),
  686.                 );
  687.             } 
  688.         }else{
  689.             $urlEnd = explode("~c",(string)(end($path) ?: ''));
  690.             $siteId = $urlEnd[1] ?? null;
  691.             if (!empty($SCData)) {
  692.                 $sc_id = $SCData[0]->getId();
  693.                 $breadctumbsArray = array(
  694.                         "level1" => array("id" => 0, "name" => 'SalesCampaign'),
  695.                         "level2" => array("id" => $sc_id, "name" => $SCData[0]->getTitle(), "url" => '/'.$SCData[0]->getshareableLink()),
  696.                     );
  697.             } else if (!empty($siteId) && isset($siteId)) {  
  698.                 $data = SiteMenu::getById($siteId);               
  699.                 
  700.                 if (!empty($data) && $data->getLevel() == 3) {
  701.                     $urlLevel1 = "/shop/" . Text::toUrl($data->getParent()->getParent()->getLabel() ?? 'elements') . "~c" . $data->getParent()->getParent()->getId();
  702.                     $urlLevel2 = "/shop/" . Text::toUrl($data->getParent()->getLabel() ?? 'elements') . "~c" . $data->getParent()->getId();
  703.                     $urlLevel3 = "/shop/" . Text::toUrl($data->getLabel() ?? 'elements') . "~c" . $data->getId();
  704.                     $breadctumbsArray = array(
  705.                         "level1" => array("id" => $data->getParent()->getParent()->getId(), "name" => $data->getParent()->getParent()->getLabel(), "url" => $urlLevel1),
  706.                         "level2" => array("id" => $data->getParent()->getId(), "name" => $data->getParent()->getLabel(), "url" => $urlLevel2),
  707.                         "level3" => array("id" => $data->getId(), "name" => $data->getLabel(), "url" => $urlLevel3)
  708.                     );
  709.                 } elseif (!empty($data) && $data->getLevel() == 2) {
  710.                     $urlLevel1 = "/shop/" . Text::toUrl($data->getParent()->getLabel() ?? 'elements') . "~c" . $data->getParent()->getId();
  711.                     $urlLevel2 = "/shop/" . Text::toUrl($data->getLabel() ?? 'elements') . "~c" . $data->getId();
  712.                     $breadctumbsArray = array(
  713.                         "level1" => array("id" => $data->getParent()->getId(), "name" => $data->getParent()->getLabel(), "url" => $urlLevel1),
  714.                         "level2" => array("id" => $data->getId(), "name" => $data->getLabel(), "url" => $urlLevel2),
  715.                     );
  716.                 } else {
  717.                     $urlLevel1 = "/shop/" . Text::toUrl($data->getLabel() ?? 'elements') . "~c" . $data->getId();
  718.                     $breadctumbsArray = array(
  719.                         "level1" => array("id" => $data->getId(), "name" => $data->getLabel(), "url" => $urlLevel1),
  720.                     );
  721.                 }
  722.             }
  723.         }
  724.         // p_r($breadctumbsArray);die;
  725.         return $breadctumbsArray;
  726.     }
  727.     public function translateValues($values)
  728.     {
  729.         foreach ($values as &$modifyingValue) {
  730.             $modifyingValue['translated'] = $this->translator->trans(mb_strtolower('attribute.' . $modifyingValue['value']));
  731.         }
  732.         return $values;
  733.     }
  734.     /**
  735.      * @param array $values
  736.      * @param string|null $fieldname
  737.      *
  738.      * @return array
  739.      */
  740.     public function sort(array $values, string $fieldname = null): array
  741.     {
  742.         @usort($values, function ($left, $right) use ($fieldname) {
  743.             $leftString = $left;
  744.             $rightString = $right;
  745.             if ($fieldname) {
  746.                 $methodName = 'get' . ucfirst($fieldname);
  747.                 if (is_array($leftString)) {
  748.                     $leftString = $leftString[$fieldname];
  749.                 } elseif (method_exists($leftString, $methodName)) {
  750.                     $leftString = $leftString->$methodName();
  751.                 }
  752.                 if (is_array($rightString)) {
  753.                     $rightString = $rightString[$fieldname];
  754.                 } elseif (method_exists($rightString, $methodName)) {
  755.                     $rightString = $rightString->$methodName();
  756.                 }
  757.             }
  758.             return strcmp($leftString, $rightString);
  759.         });
  760.         return $values;
  761.     }
  762.     /**
  763.      * @param array $values
  764.      * @param string $fieldname
  765.      * @param array $objects
  766.      *
  767.      * @return array
  768.      */
  769.     public function sortObjects(array $values, string $fieldname, array $objects): array
  770.     {
  771.         @usort($values, function ($left, $right) use ($fieldname, $objects) {
  772.             $leftString = '';
  773.             $rightString = '';
  774.             $methodName = 'get' . ucfirst($fieldname);
  775.             $object = $objects[$left['value']];
  776.             if ($object && method_exists($object, $methodName)) {
  777.                 $leftString = $object->$methodName();
  778.             }
  779.             $object = $objects[$right['value']];
  780.             if ($object && method_exists($object, $methodName)) {
  781.                 $rightString = $object->$methodName();
  782.             }
  783.             return strcmp($leftString, $rightString);
  784.         });
  785.         return $values;
  786.     }
  787.     /**
  788.      * @param string $className
  789.      * @param number $value
  790.      * @return string $value
  791.      */
  792.     public function fromIdToValueStr($className, $value)
  793.     { 
  794.         if (!empty($className) && !in_array($className, STATIC_FILTER)) {
  795.             if ($className == 'country') { 
  796.                 $countryData = GeneralHelper::searchCountry($value);
  797.                 return $countryData['name'];
  798.             }
  799.             if($className == 'countryFilter'){
  800.                 $className = 'country';
  801.             }
  802.             if ($className == 'lifeStyleTheme') {
  803.                 $className = 'LifeStyleCollection';
  804.             }
  805.             if ($className == 'productionLeadTime') {
  806.                 $className = 'LeadTime';
  807.             }
  808.             if ($className == 'crossCategory') {
  809.                 $className = 'CrossGroup';
  810.             }
  811.             if ($className == 'tradeFair') {
  812.                 $className = 'TradeFair';
  813.             }
  814.             if ($className == 'productStatus') {
  815.                 $className = 'Status';
  816.             }
  817.             if ($className =='exclusiveToInternalCompany') {
  818.                 $className = 'SupplierCompany';
  819.             }
  820.             if ($className =='productCategory') {
  821.                 $className = 'Category';
  822.             }
  823.             
  824.            
  825.             $objectStr =  'Pimcore\\Model\\DataObject\\' . ucfirst($className) . '\\Listing';
  826.             $object = new $objectStr();
  827.             $object->setCondition(' o_id = ? ', [$value]);
  828.             $object->setLimit(1);
  829.             $loadObjectData = $object->load();   
  830.             if (!empty($loadObjectData)) {
  831.                 if($className == 'country'){ 
  832.                     return $loadObjectData[0]->getO_key();
  833.                 }else{
  834.                     return $loadObjectData[0]->getName();
  835.                 }
  836.                 
  837.             } else {
  838.                 return;
  839.             }
  840.         } else {
  841.             return $value;
  842.         }
  843.         return $value;
  844.     }
  845.     /**
  846.      * @param  Request Parameter $requestVariables
  847.      * @param  string $currentUrl
  848.      * @return modifiedweburl $x
  849.      */
  850.     public function pimcorePaginationUrl($requestVariables, $currentUrl = '')
  851.     {
  852.         $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  853.         if (in_array('sort', $_REQUEST)) {
  854.             $actual_linkX =    $actual_link;
  855.             $actual_linkY =    $actual_link;
  856.         } else {
  857.             $actual_linkX = substr($actual_link, 0, strpos($actual_link, "&" . $requestVariables . "="));
  858.             $actual_linkY = substr($actual_link, 0, strpos($actual_link, "?" . $requestVariables . "="));
  859.         }
  860.         if ($actual_linkX) {
  861.             $actual_link = $actual_linkX;
  862.         }
  863.         if ($actual_linkY) {
  864.             $actual_link = $actual_linkY;
  865.         }
  866.         $urlData = explode('?', $actual_link);
  867.         if (count($urlData) >= 2) {
  868.             $lchar = substr($actual_link, -1);
  869.             if ($lchar == '?') {
  870.                 $x = $actual_link . $requestVariables . '=';
  871.             } else {
  872.                 $x = $actual_link . '&' . $requestVariables . '=';
  873.             }
  874.         } else {
  875.             $lchar = substr($actual_link, -1);
  876.             if ($lchar == '?') {
  877.                 $x = $actual_link . $requestVariables . '=';
  878.             } else {
  879.                 $x = $actual_link . '?' . $requestVariables . '=';
  880.             }
  881.         }
  882.         return $x;
  883.     }
  884.     public function getProductWishlistStatus($product)
  885.     {
  886.         if (isset($_SESSION['_pimcore_admin']['customer']) && !empty($_SESSION['_pimcore_admin']['customer'])) {
  887.             $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  888.             $wishlistListing = new DataObject\Wishlist\Listing();
  889.             $wishlistListing->setCondition("customer__id = " . $customer->getId());
  890.             // $wishlistListing->setCondition("products like '%,products|".$product->getId().",%'");
  891.             $wishlistData = $wishlistListing->load();
  892.             // p_r($wishlistListing);die;
  893.             if (count($wishlistData) != 0) {
  894.                 return $wishlistData[0]->getLable();
  895.             }
  896.         }
  897.         return false;
  898.     }
  899.     public function checkUserSubscriptionType()
  900.     {
  901.         if (isset($_SESSION['_pimcore_admin']['customer']) && !empty($_SESSION['_pimcore_admin']['customer'])) {
  902.             $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  903.             return $customer->getCompany()->getSubscription();
  904.         }
  905.     }
  906.     public function getProductAttributeName($attributes)
  907.     {
  908.         $name = [];
  909.         if (!empty($attributes)) {
  910.             foreach ($attributes as $key => $value) {
  911.                 $attributesData =  Attributes::getById($value);
  912.                 if (!empty($attributesData)) {
  913.                     $name[] = $attributesData->getLocalizedfields()->getLocalizedValue("name", "en");
  914.                 }
  915.             }
  916.         }
  917.         return $name;
  918.     }
  919.     public function checkMenuStatus($menu)
  920.     {
  921.         $status = true;
  922.         if (!empty($menu)) {
  923.             foreach ($menu as $k => $v) {
  924.                 if (empty($v)) {
  925.                     $status = false;
  926.                     break;
  927.                 }
  928.             }
  929.         }
  930.         return $status;
  931.     }
  932.     public function checkMegaMenuStatus($megaMenu)
  933.     {
  934.         $status = true;
  935.         foreach ($megaMenu as $value) {
  936.             foreach ($value as $v) {
  937.                 if (empty($v)) {
  938.                     $status = false;
  939.                     break;
  940.                 }
  941.             }
  942.         }
  943.         return $status;
  944.     }
  945.     public function rfqStatus($status)
  946.     {
  947.         return RFQ_STATUS[$status];
  948.     }
  949.     public function getSelectedWhislistByProduct($productId)
  950.     {        
  951.         if(strpos($productId, "?") !== false){            
  952.             $productId = strtok($productId, '?');
  953.         }
  954.         
  955.         $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  956.         if (!empty($customer)) {
  957.             $wishlistListing = new DataObject\Wishlist\Listing();
  958.             $condition = "(customer__id = ? AND products LIKE ?) OR (products LIKE ? AND sharedWith LIKE ?)";
  959.             $wishlistListing->setCondition($condition, [$customer->getId(), '%,' . $productId . ',%', '%,' . $productId . ',%', '%,' . $customer->getId() . ',%']);
  960.             $wishlistData = $wishlistListing->load();
  961.             $arr = [];
  962.             if (!empty($wishlistData)) {
  963.                 foreach ($wishlistData as $value) {
  964.                     $arr[]  =   $value->getO_Id();
  965.                 }
  966.                 // PHP 8: templates print this value raw inside onclick attributes -
  967.                 // return the id list as string (PHP 7.4 silently printed "Array" here)
  968.                 return implode(',', $arr);
  969.             }
  970.         }
  971.         return false;
  972.     }
  973.     public function getLatestHighlightCatalogForMenu($type)
  974.     {
  975.         $catalogServices = new CatalogServices();
  976.         return $catalogServices->getLatestHighlightCatalog($type);
  977.     }
  978.     public function getProductComment($commentProductId){
  979.         if(strpos($commentProductId, "?") !== false){            
  980.             $commentProductId = strtok($commentProductId, '?');
  981.         }
  982.         $commentProductObj = Product::getById($commentProductId, ["force" => true]);
  983.         $isCommentExists = false;
  984.         if ($commentProductObj) {
  985.             try{
  986.                 $isCommentExists = ($commentProductObj->getProductComment()) ? true : false;                                                                                   
  987.             }
  988.             catch(\Exception $e){                
  989.                 $isCommentExists = false;
  990.             }
  991.         }
  992.         return $isCommentExists;
  993.     }
  994.     public function getAnalyticsAccess(){        
  995.         $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  996.         $isAbleToViewAnalytics = false;    
  997.         if (!empty($customer)) {
  998.             $customerId = $customer->getId();
  999.             $customerObj = Customer::getById($customerId);
  1000.             $isAbleToViewAnalytics = ($customerObj->getIsAbleToViewAnalytics()) ? true : false;         
  1001.         }
  1002.         return $isAbleToViewAnalytics;
  1003.     }
  1004.     public function getCuratedFPGMenuBar()
  1005.     {
  1006.         $allCuratedFPGMenuData = [];
  1007.         $curatedFPGMenu = new DataObject\CuratedFPG\Listing();        
  1008.         $allCuratedFPGMenuArray = $curatedFPGMenu->load();
  1009.         $level1Array = [];
  1010.         $level2Array = [];
  1011.         $level3Array = [];
  1012.         foreach ($allCuratedFPGMenuArray as $key => $value) {
  1013.             if($value->getLevel() == 1){
  1014.                 $level1Array[$value->getId()] = $value;
  1015.             }
  1016.             elseif($value->getLevel() == 2){
  1017.                 $level2Array[$value->getId()] = $value;
  1018.             }
  1019.             elseif($value->getLevel() == 3){
  1020.                 $level3Array[$value->getParent()->getParent()->getId()][$value->getParent()->getId()][] = $value;
  1021.             }
  1022.         }
  1023.         return ["level1"=>$level1Array, "level2"=>$level2Array, "level3"=>$level3Array];
  1024.     }
  1025.     public function getExclusiveFPGMenuBar()
  1026.     {
  1027.         $allExclusiveFPGMenuData = [];
  1028.         $exclusiveFPGMenu = new DataObject\ExclusiveFPG\Listing();        
  1029.         $allExclusiveFPGMenuArray = $exclusiveFPGMenu->load();
  1030.         $level1Array = [];
  1031.         $level2Array = [];
  1032.         $level3Array = [];
  1033.         foreach ($allExclusiveFPGMenuArray as $key => $value) {
  1034.             if($value->getLevel() == 1){
  1035.                 $level1Array[$value->getId()] = $value;
  1036.             }
  1037.             elseif($value->getLevel() == 2){
  1038.                 $level2Array[$value->getId()] = $value;
  1039.             }
  1040.             elseif($value->getLevel() == 3){
  1041.                 $level3Array[$value->getParent()->getParent()->getId()][$value->getParent()->getId()][] = $value;
  1042.             }
  1043.         }
  1044.         return ["level1"=>$level1Array, "level2"=>$level2Array, "level3"=>$level3Array];
  1045.     }
  1046.     public function getExclusiveRandomProducts($catalogId){                
  1047.         $catalogObj = Catalog::getById($catalogId, ["force" => true]);        
  1048.         $productIds = [];
  1049.         foreach ($catalogObj->getProduct() as $key => $value) {
  1050.             $productIds[] = $value->getId();
  1051.         }        
  1052.         $catalogProducts = new DataObject\Product\Listing();
  1053.         $catalogProducts->setCondition("o_id IN (?)", [$productIds]);
  1054.         $catalogProducts->setOrderKey("RAND()", false);      
  1055.         $catalogProducts->setLimit(2); 
  1056.         $catalogProductsArray = $catalogProducts->load();        
  1057.         return $catalogProductsArray;
  1058.     }
  1059.     public function getCatalogTypeInMenu($catalogId){
  1060.         $catalogObj = Catalog::getById($catalogId, ["force" => true]); 
  1061.         $catalogType = "";
  1062.         return $catalogObj->getCatalogFor() ?? "";
  1063.     }
  1064.     public function getWishlistProductComment($wishlistId, $productId){
  1065.         $wishlistCommentsListing = new DataObject\WishListComments\Listing();          
  1066.         $wishlistCommentsListing->setCondition("wishlist like '%".$wishlistId."%' AND Product like '%".$productId."%'");        
  1067.         $wishlistCommentsObj = $wishlistCommentsListing->load();     
  1068.         $wishlistComment = "";
  1069.         if(count($wishlistCommentsObj) > 0){
  1070.             $wishlistComment = $wishlistCommentsObj[0]->getWishlistCommentDetails();
  1071.         }   
  1072.         return $wishlistComment;
  1073.     }
  1074.     public function getQuantityUnit($unitId){
  1075.         $unit = \Pimcore\Model\DataObject\QuantityValue\Unit::getById($unitId);
  1076.         return $unit;
  1077.     }
  1078.     public function getCDNurl(){
  1079.         return PIMCORE_CDN_BASEURL;
  1080.     }
  1081.     public function getLeadTimeData(){
  1082.         $leadTimeList = new DataObject\LeadTime\Listing();   
  1083.         $leadTimeList->setUnpublished(true);    
  1084.         $leadTimeArray = $leadTimeList->load();        
  1085.         return $leadTimeArray; 
  1086.     }
  1087.     public function getColorData(){
  1088.         $colorList = new DataObject\Color\Listing();   
  1089.         $colorList->setUnpublished(true);    
  1090.         $colorArray = $colorList->load();        
  1091.         return $colorArray; 
  1092.     }
  1093.     public function getRFQData($RFQId){
  1094.         $data   =   DataObject\Fieldcollection\Definition::getByKey($RFQId);
  1095.         $options =  $data->getFieldDefinitions()['currencyUnit']->getOptions();
  1096.         return $options;
  1097.     }
  1098.     public function getCartStatusInFieldCollection($RFQId){
  1099.         $data   =   DataObject\Fieldcollection\Definition::getByKey($RFQId);
  1100.         $options =  $data->getFieldDefinitions()['status']->getOptions();
  1101.         return $options;
  1102.     }
  1103.     public function getCurrentSite(){ 
  1104.         $nuFindDomain = ['3smisource', 'nu-find'];
  1105.         $threeSGlobalDomain = ['3swebsite', '3sglobal'];
  1106.         if (\Pimcore\Model\Site::isSiteRequest()) {         
  1107.             return $GLOBALS['site'] ?? \Pimcore\Model\Site::getCurrentSite()->getRootDocument()->getKey(); 
  1108.         }
  1109.         else if(GeneralHelper::array_contains($_SERVER['SERVER_NAME'], $threeSGlobalDomain)){
  1110.             return '3SWebsite';
  1111.         }
  1112.         else if(GeneralHelper::array_contains($_SERVER['SERVER_NAME'], $nuFindDomain)){
  1113.             return 'NuFind';            
  1114.         }        
  1115.         else{                       
  1116.             return 'NuFind';            
  1117.         }
  1118.     }
  1119.     public function getSubDocumentCategory($category){        
  1120.         $attr = $category.'SubTypes';          
  1121.         $customer = $_SESSION['_pimcore_admin']['customer'] ?? null;
  1122.         $customerData = $customer->getClass()->getFieldDefinition($attr);
  1123.         $getSubcategory =   $customerData->getChilds()[0]->getOptions();
  1124.         $subcatArray    =   [];
  1125.         foreach($getSubcategory as $subcat){ 
  1126.             $subcatArray[$subcat['value']]    = $subcat['key'];   
  1127.         }        
  1128.         return $subcatArray;
  1129.     }
  1130.     public function getCategoryTopParent($categoryId){        
  1131.         $categoryObj = SiteMenu::getById($categoryId);                
  1132.         if($categoryObj->getLevel() == 1 && $categoryObj->getType() != "folder"){
  1133.             return $categoryObj->getLabel();
  1134.         }
  1135.         else{
  1136.             if($categoryObj->getType() != "folder"){                
  1137.                 return $this->getCategoryTopParent($categoryObj->getParent()->getId());
  1138.             }
  1139.         }
  1140.     }
  1141.     public function getOnlyProductId($productId){
  1142.         if(strpos($productId, "?") !== false){            
  1143.             $productId = strtok($productId, '?');
  1144.         }
  1145.         return $productId;
  1146.     }
  1147.     public function getArrayObjectsToIds($arrayOfObj){
  1148.         $idsArray = [];
  1149.         if(count($arrayOfObj)){
  1150.             foreach($arrayOfObj as $singleObj){
  1151.                 $idsArray[] = $singleObj->getId();
  1152.             }                        
  1153.         }
  1154.         return $idsArray;
  1155.     }
  1156.     public function pimcoreComplexUrl($requestVariables, $currentUrl = '')
  1157.     {
  1158.         $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1159.         // Parse the URL to get the query parameters and the path
  1160.         $urlParts = parse_url($actual_link);
  1161.         $queryParams = [];
  1162.         parse_str($urlParts['query'] ?? '', $queryParams);
  1163.         // Remove the $requestVariables parameter if it exists
  1164.         unset($queryParams[$requestVariables]);
  1165.         // Rebuild the query string without the $requestVariables parameter
  1166.         $queryString = http_build_query($queryParams);
  1167.         // Get the URL without the query string
  1168.         $actual_link = $urlParts['path'];
  1169.         // Append the query string to the URL
  1170.         $actual_link .= empty($queryString) ? '' : '?' . $queryString;
  1171.         // Append the $requestVariables parameter to the URL
  1172.         $x = $actual_link . (strpos($actual_link, '?') === false ? '?' : '&') . $requestVariables . '=';
  1173.         return $x;
  1174.     }
  1175.     public function getSingleProductById($productId, $field){
  1176.         
  1177.         $productObj = Product::getById($productId, ["force" => true]);
  1178.         $value = "";
  1179.         $getter = 'get' . ucfirst($field);                                
  1180.         if (method_exists($productObj, $getter)) {
  1181.             $value = $productObj->$getter();      
  1182.         }
  1183.         return $value;
  1184.     }
  1185.     public function getRFQGeneratedPIStatus($rfqId) {
  1186.         return $this->getCachedPIObjectId($rfqId) !== '';
  1187.     }
  1188.     public function getPIObjId($rfqId) {
  1189.         return $this->getCachedPIObjectId($rfqId);
  1190.     }
  1191.     public function getRFQGeneratedPOStatus($rfqId) {
  1192.         return $this->getCachedPOObjectId($rfqId) !== '';
  1193.     }
  1194.     public function getPOObjId($rfqId) {
  1195.         return $this->getCachedPOObjectId($rfqId);
  1196.     }
  1197.     private function getCachedPIObjectId($rfqId)
  1198.     {
  1199.         $rfqId = (string)$rfqId;
  1200.         if ($rfqId === '') {
  1201.             return '';
  1202.         }
  1203.         if (!array_key_exists($rfqId, $this->piObjectIdsByRfq)) {
  1204.             $list = new \Pimcore\Model\DataObject\ProformaInvoice\Listing();
  1205.             $list->setCondition("linkedRFQNumber = ?", [$rfqId]);
  1206.             $list->setLimit(1);
  1207.             $objects = $list->load();
  1208.             $this->piObjectIdsByRfq[$rfqId] = count($objects) > 0 ? $objects[0]->getId() : '';
  1209.         }
  1210.         return $this->piObjectIdsByRfq[$rfqId];
  1211.     }
  1212.     private function getCachedPOObjectId($rfqId)
  1213.     {
  1214.         $rfqId = (string)$rfqId;
  1215.         if ($rfqId === '') {
  1216.             return '';
  1217.         }
  1218.         if (!array_key_exists($rfqId, $this->poObjectIdsByRfq)) {
  1219.             try {
  1220.                 $list = new \Pimcore\Model\DataObject\PurchaseOrders\Listing();
  1221.                 $list->setCondition("linkedRFQNumber = ?", [$rfqId]);
  1222.                 $list->setLimit(1);
  1223.                 $objects = $list->load();
  1224.                 $this->poObjectIdsByRfq[$rfqId] = count($objects) > 0 ? $objects[0]->getId() : '';
  1225.             } catch (\Throwable $e) {
  1226.                 $this->poObjectIdsByRfq[$rfqId] = '';
  1227.             }
  1228.         }
  1229.         return $this->poObjectIdsByRfq[$rfqId];
  1230.     }
  1231. }