custom/plugins/uvalaBadgeManagerVsix/src/Subscriber/ProductListingSub.php line 40

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Uvala\uvalaBadgeManagerVsix\Subscriber;
  3. use Shopware\Core\Content\Product\Events\ProductSearchResultEvent;
  4. use Shopware\Core\Content\Product\ProductEntity;
  5. use Shopware\Core\Content\Product\Events\ProductListingResultEvent;
  6. use Shopware\Storefront\Page\Product\ProductPageLoadedEvent;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Metric\EntityAggregation;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  9. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  11. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
  12. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  13. use Shopware\Core\System\SystemConfig\SystemConfigService;
  14. use Shopware\Core\Framework\Struct\ArrayEntity;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. use Uvala\uvalaBadgeManagerVsix\uvalaBadgeManagerVsix;
  17. class ProductListingSub implements EventSubscriberInterface {
  18.     public $uv_plugin_global_settings;
  19.     private $systemConfigService;
  20.     private $productRepository;
  21.     public function __construct(SystemConfigService $systemConfigServiceEntityRepositoryInterface $productRepository) {
  22.         $this->systemConfigService $systemConfigService;
  23.         $this->productRepository $productRepository;
  24.     }
  25.     public static function getSubscribedEvents() {
  26.         return [
  27.             ProductSearchResultEvent::class => 'onProductSearchResult',
  28.             ProductListingResultEvent::class => 'onProductSearchResult',
  29.             ProductPageLoadedEvent::class => 'onProductPageLoaded'
  30.         ];
  31.     }
  32.     public function onProductSearchResult(ProductListingResultEvent $event) {
  33.         global $uv_plugin_global_settings;
  34.         // load plugin settings for global use
  35.         $uv_saleschannel_id $event->getSalesChannelContext()->getSalesChannel()->getId();
  36.         $this->uv_load_plugin_settings($uv_saleschannel_id);
  37.         $uv_current_currencyid $event->getSalesChannelContext()->getSalesChannel()->get('currencyId');
  38.         $uv_allow_output_badges 0;
  39.         $uv_allowed_products = [];
  40.         $uv_product_options_load 0;
  41.         $uv_product_options_needed_array = [];
  42.         $uv_product_options_array = [];
  43.         $uv_product_properties_load 0;
  44.         $uv_product_properties_needed_array = [];
  45.         $uv_product_properties_array = [];
  46.         $uv_plugin_setting_name 'uvalaBadgeManagerVsix.config.';
  47.         // first run: check badges if anyone activated
  48.         for ($uvbgct 1$uvbgct<=8$uvbgct++) {
  49.             if (isset($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstStatePart'.$uvbgct])) {
  50.                 if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstStatePart'.$uvbgct] == 'activated') {
  51.                     $uv_allow_output_badges 1;
  52.                     if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] != 'only_master') {
  53.                         $uv_product_options_load 1;
  54.                     }
  55.                     if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'prod_prop') {
  56.                         $uv_product_properties_load 1;
  57.                     }
  58.                 }
  59.             }
  60.         }
  61.         // second run: check the products with uvala_bdmg_plugin_disable if allow to run and options are needed
  62.         if ($uv_allow_output_badges == 1) {
  63.             foreach ($event->getResult() as $uvtmp_products) {
  64.                 $uvtmpcheck_product_allowed 0;
  65.                 if (isset($uvtmp_products->get('customFields')['uvala_bdmg_plugin_disable'])) {
  66.                     if ($uvtmp_products->get('customFields')['uvala_bdmg_plugin_disable'] == true) {
  67.                         $uvtmpcheck_product_allowed 0;
  68.                     } else {
  69.                         $uvtmpcheck_product_allowed 1;
  70.                     }
  71.                 } else {
  72.                     $uvtmpcheck_product_allowed 1;
  73.                 }
  74.                 if ($uvtmpcheck_product_allowed == 1) {
  75.                     $uv_allowed_products[] = $uvtmp_products;
  76.                     if ($uv_product_options_load == 1) {
  77.                         if ($uvtmp_products->get('parentId') != '') {
  78.                             $uv_product_options_needed_array[$uvtmp_products->get('parentId')] = $uvtmp_products->get('parentId');
  79.                         }
  80.                     }
  81.                     if ($uv_product_properties_load == 1) {
  82.                         if (!empty($uvtmp_products->get('propertyIds'))) {
  83.                             $uv_product_properties_needed_array[$uvtmp_products->get('id')] = $uvtmp_products->get('id');
  84.                         }
  85.                     }
  86.                 }
  87.             }
  88.         }
  89.         // if allow to run the output?
  90.         if (($uv_allow_output_badges == 1) && (!empty($uv_allowed_products))) {
  91.             // load properties from products if needed
  92.             if (!empty($uv_product_properties_needed_array)) {
  93.                 $search_prop_criteria = new Criteria();
  94.                 $search_prop_criteria->addFilter(new EqualsAnyFilter('id'$uv_product_properties_needed_array),
  95.                     new EqualsFilter('active'true))->addAssociations(['properties''properties.group']);
  96.                 $uvresult_products_only_prop $this->productRepository->search($search_prop_criteria$event->getContext());
  97.                 foreach ($uvresult_products_only_prop as $uvtmp_products_op) {
  98.                     foreach ($uvtmp_products_op->get('properties') as $uvtmp_properties_groups) {
  99.                         if (!isset($uv_product_properties_array[$uvtmp_products_op->get('id')]['properties_groups'][$uvtmp_properties_groups->get('groupId')])) {
  100.                             $uv_product_properties_array[$uvtmp_products_op->get('id')]['properties_groups'][$uvtmp_properties_groups->get('groupId')] =
  101.                                 ['name' => $uvtmp_properties_groups->get('group')->get('translated')['name'], 'excluded' => $this->addExcludedForPropertyGroup($uvtmp_properties_groups->getGroup()->getCustomFields())];
  102.                         }
  103.                         $uv_product_properties_array[$uvtmp_products_op->get('id')]['properties_groups'][$uvtmp_properties_groups->get('groupId')]['properties'][$uvtmp_properties_groups->get('id')] =
  104.                             ['name' => $uvtmp_properties_groups->get('translated')['name'], 'excluded' => $this->addExcludedForPropertyGroup($uvtmp_properties_groups->getGroup()->getCustomFields())];
  105.                     }
  106.                 }
  107.             }
  108.             // load options with properties from products if needed
  109.             if (!empty($uv_product_options_needed_array)) {
  110.                 if ($uv_product_properties_load == 1) {
  111.                     $uvtmp_load_associations = ['options''options.group''properties''properties.group'];
  112.                 } else {
  113.                     $uvtmp_load_associations = ['options''options.group'];
  114.                 }
  115.                 $search_options_criteria = new Criteria();
  116.                 $search_options_criteria->addFilter(new EqualsAnyFilter('parentId'$uv_product_options_needed_array), new EqualsFilter('active'true))->addAssociations($uvtmp_load_associations);
  117.                 $uvresult_products_only_options $this->productRepository->search($search_options_criteria$event->getContext());
  118.                 foreach ($uvresult_products_only_options as $uvtmp_products_oo) {
  119.                     $uvtmp_option_parentid $uvtmp_products_oo->get('parentId');
  120.                     if ($uv_product_properties_load == 1) {
  121.                         foreach ($uvtmp_products_oo->get('properties') as $uvtmp_properties_groups) {
  122.                             if (!$uvtmp_properties_groups->getGroup()->getCustomFields() || (array_key_exists('uvala_bdmg_property_group_excluded', (array)$uvtmp_properties_groups->getGroup()->getCustomFields()) && !$uvtmp_properties_groups->getGroup()->getCustomFields()['uvala_bdmg_property_group_excluded']) ) {
  123.                                 if (!isset($uv_product_options_array[$uvtmp_option_parentid]['properties_groups'][$uvtmp_properties_groups->get('groupId')])) {
  124.                                     $uv_product_properties_array[$uvtmp_products_op->get('id')]['properties_groups'][$uvtmp_properties_groups->get('groupId')] =
  125.                                         ['name' => $uvtmp_properties_groups->get('group')->get('translated')['name'], 'excluded' => $this->addExcludedForPropertyGroup($uvtmp_properties_groups->getGroup()->getCustomFields())];
  126.                                 }
  127.                                  $uv_product_properties_array[$uvtmp_products_op->get('id')]['properties_groups'][$uvtmp_properties_groups->get('groupId')]['properties'][$uvtmp_properties_groups->get('id')] =
  128.                                      ['name' => $uvtmp_properties_groups->get('translated')['name'], 'excluded' => $this->addExcludedForPropertyGroup($uvtmp_properties_groups->getGroup()->getCustomFields())];
  129.                             }
  130.                         }
  131.                     }
  132.                     foreach ($uvtmp_products_oo->get('options') as $uvtmp_option_groups) {
  133.                         if (!isset($uv_product_options_array[$uvtmp_option_parentid]['option_groups'][$uvtmp_option_groups->get('groupId')])) {
  134.                             $uv_product_options_array[$uvtmp_option_parentid]['option_groups'][$uvtmp_option_groups->get('groupId')] = ['name' => $uvtmp_option_groups->get('group')->get('translated')['name']];
  135.                         }
  136.                         $uv_product_options_array[$uvtmp_option_parentid]['option_groups'][$uvtmp_option_groups->get('groupId')]['options'][$uvtmp_option_groups->get('id')] = ['name' => $uvtmp_option_groups->get('translated')['name']];
  137.                     }
  138.                     $uvtmp_option_stock $uvtmp_products_oo->get('availableStock');
  139.                     if (isset($uv_product_options_array[$uvtmp_option_parentid]['stock_calc'])) {
  140.                         $uv_product_options_array[$uvtmp_option_parentid]['stock_calc'] = ($uv_product_options_array[$uvtmp_option_parentid]['stock_calc']+$uvtmp_option_stock);
  141.                         if ($uvtmp_option_stock $uv_product_options_array[$uvtmp_option_parentid]['stock_min']) {
  142.                             $uv_product_options_array[$uvtmp_option_parentid]['stock_min'] = $uvtmp_option_stock;
  143.                         }
  144.                         if ($uvtmp_option_stock $uv_product_options_array[$uvtmp_option_parentid]['stock_max']) {
  145.                             $uv_product_options_array[$uvtmp_option_parentid]['stock_max'] = $uvtmp_option_stock;
  146.                         }
  147.                     } else {
  148.                         $uv_product_options_array[$uvtmp_option_parentid]['stock_calc'] = $uvtmp_option_stock;
  149.                         $uv_product_options_array[$uvtmp_option_parentid]['stock_min'] = $uvtmp_option_stock;
  150.                         $uv_product_options_array[$uvtmp_option_parentid]['stock_max'] = $uvtmp_option_stock;
  151.                     }
  152.                     $uvtmp_discount_val '0';
  153.                     $uvtmp_discount_checking $uvtmp_products_oo->getPrice()->getElements()[$uv_current_currencyid];
  154.                     if ($uvtmp_discount_checking->getListPrice() != '') {
  155.                         if ($uvtmp_discount_checking->getListPrice()->getGross() != '0') {
  156.                             $uvtmp_discount_val round(((($uvtmp_discount_checking->getListPrice()->getGross())-($uvtmp_discount_checking->getGross()))/($uvtmp_discount_checking->getListPrice()->getGross()))*1002);
  157.                         }
  158.                     }
  159.                     if (isset($uv_product_options_array[$uvtmp_option_parentid]['discount_calc'])) {
  160.                         $uv_product_options_array[$uvtmp_option_parentid]['discount_calc'] = ($uv_product_options_array[$uvtmp_option_parentid]['discount_calc']+$uvtmp_discount_val);
  161.                         if ($uvtmp_discount_val $uv_product_options_array[$uvtmp_option_parentid]['discount_min']) {
  162.                             $uv_product_options_array[$uvtmp_option_parentid]['discount_min'] = $uvtmp_discount_val;
  163.                         }
  164.                         if ($uvtmp_discount_val $uv_product_options_array[$uvtmp_option_parentid]['discount_max']) {
  165.                             $uv_product_options_array[$uvtmp_option_parentid]['discount_max'] = $uvtmp_discount_val;
  166.                         }
  167.                     } else {
  168.                         $uv_product_options_array[$uvtmp_option_parentid]['discount_calc'] = $uvtmp_discount_val;
  169.                         $uv_product_options_array[$uvtmp_option_parentid]['discount_min'] = $uvtmp_discount_val;
  170.                         $uv_product_options_array[$uvtmp_option_parentid]['discount_max'] = $uvtmp_discount_val;
  171.                     }
  172.                     $uvtmp_deliverytime_min '0';
  173.                     $uvtmp_deliverytime_max '0';
  174.                     if ($uvtmp_products_oo->get('deliveryTime') != '') {
  175.                         $uvtmp_deliverytime_min $this->uv_recalculate_delivery_time($uvtmp_products_oo->get('deliveryTime')->get('min'), $uvtmp_products_oo->get('deliveryTime')->get('unit'));
  176.                         $uvtmp_deliverytime_max $this->uv_recalculate_delivery_time($uvtmp_products_oo->get('deliveryTime')->get('max'), $uvtmp_products_oo->get('deliveryTime')->get('unit'));
  177.                     }
  178.                     if (isset($uv_product_options_array[$uvtmp_option_parentid]['delivery_min'])) {
  179.                         if ($uvtmp_deliverytime_min $uv_product_options_array[$uvtmp_option_parentid]['delivery_min']) {
  180.                             $uv_product_options_array[$uvtmp_option_parentid]['delivery_min'] = $uvtmp_deliverytime_min;
  181.                         }
  182.                         if ($uvtmp_deliverytime_max $uv_product_options_array[$uvtmp_option_parentid]['delivery_max']) {
  183.                             $uv_product_options_array[$uvtmp_option_parentid]['delivery_max'] = $uvtmp_deliverytime_max;
  184.                         }
  185.                     } else {
  186.                         $uv_product_options_array[$uvtmp_option_parentid]['delivery_min'] = $uvtmp_deliverytime_min;
  187.                         $uv_product_options_array[$uvtmp_option_parentid]['delivery_max'] = $uvtmp_deliverytime_max;
  188.                     }
  189.                     if (isset($uv_product_options_array[$uvtmp_option_parentid]['shippingfree_check'])) {
  190.                         if ($uvtmp_products_oo->get('shippingFree') == '1') {
  191.                             $uv_product_options_array[$uvtmp_option_parentid]['shippingfree_check'] = $uvtmp_products_oo->get('shippingFree');
  192.                         }
  193.                     } else {
  194.                         $uv_product_options_array[$uvtmp_option_parentid]['shippingfree_check'] = $uvtmp_products_oo->get('shippingFree');
  195.                     }
  196.                 }
  197.             }
  198.             // last run: collect data and write output to product
  199.             foreach($uv_allowed_products as $uvtmp_products) {
  200.                 $uv_product_data_array = [];
  201.                 $uvtmp_variants_data '';
  202.                 if ($uv_product_options_load == 1) {
  203.                     if (isset($uv_product_options_array[$uvtmp_products->get('parentId')])) {
  204.                         $uvtmp_variants_data $uv_product_options_array[$uvtmp_products->get('parentId')];
  205.                     }
  206.                 }
  207.                 $uvtmp_properties_data '';
  208.                 if ($uv_product_properties_load == 1) {
  209.                     if (isset($uv_product_properties_array[$uvtmp_products->get('id')])) {
  210.                         $uvtmp_properties_data $uv_product_properties_array[$uvtmp_products->get('id')];
  211.                     }
  212.                 }
  213.                 $uvtmp_discount_value '0';
  214.                 if ($uvtmp_products->get('calculatedPrice')->getListPrice() != '') {
  215.                     $uvtmp_discount_value $uvtmp_products->get('calculatedPrice')->getListPrice()->getPercentage();
  216.                 }
  217.                 $uvtmp_delivery_time_min '0';
  218.                 $uvtmp_delivery_time_max '0';
  219.                 if ($uvtmp_products->get('deliveryTime') != '') {
  220.                     $uvtmp_delivery_time_min $this->uv_recalculate_delivery_time($uvtmp_products->get('deliveryTime')->get('min'), $uvtmp_products->get('deliveryTime')->get('unit'));
  221.                     $uvtmp_delivery_time_max $this->uv_recalculate_delivery_time($uvtmp_products->get('deliveryTime')->get('max'), $uvtmp_products->get('deliveryTime')->get('unit'));
  222.                 }
  223.                 $uv_product_data_array = ['variants' => $uvtmp_variants_data,
  224.                     'properties' => $uvtmp_properties_data,
  225.                     'stock_current' => $uvtmp_products->get('availableStock'),
  226.                     'discount_value' => $uvtmp_discount_value,
  227.                     'delivery_time_min' => $uvtmp_delivery_time_min,
  228.                     'delivery_time_max' => $uvtmp_delivery_time_max,
  229.                     'shippingfree_check' => $uvtmp_products->get('shippingFree'),
  230.                     'topseller_check' => $uvtmp_products->get('markAsTopseller'),
  231.                     'newproduct_check' => $uvtmp_products->get('isNew')
  232.                 ];
  233.                 $uvtmp_products->addExtension('badge_manager', new ArrayEntity(['badges_array' => $this->uv_badge_manager_output($uv_product_data_array)]));
  234.             }
  235.         }
  236.     }
  237.     public function onProductPageLoaded(ProductPageLoadedEvent $event) {
  238.         global $uv_plugin_global_settings;
  239.         // load plugin settings for global use
  240.         $uv_saleschannel_id $event->getSalesChannelContext()->getSalesChannel()->getId();
  241.         $this->uv_load_plugin_settings($uv_saleschannel_id);
  242.         $uv_current_page $event->getPage();
  243.         $uv_current_product $uv_current_page->getProduct();
  244.         $uv_current_currencyid $event->getSalesChannelContext()->getSalesChannel()->get('currencyId');
  245.         $uv_allow_output_badges 0;
  246.         $uv_allow_output_product 0;
  247.         $uv_product_options_load 0;
  248.         $uv_product_options_needed_load '';
  249.         $uv_product_options_array = [];
  250.         $uv_product_properties_load 0;
  251.         $uv_product_properties_array = [];
  252.         $uv_plugin_setting_name 'uvalaBadgeManagerVsix.config.';
  253.         // first run: check badges if anyone activated
  254.         for ($uvbgct 1$uvbgct<=8$uvbgct++) {
  255.             if (isset($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstStatePart'.$uvbgct])) {
  256.                 if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstStatePart'.$uvbgct] == 'activated') {
  257.                     $uv_allow_output_badges 1;
  258.                     if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] != 'only_master') {
  259.                         $uv_product_options_load 1;
  260.                     }
  261.                     if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'prod_prop') {
  262.                         $uv_product_properties_load 1;
  263.                     }
  264.                 }
  265.             }
  266.         }
  267.         // second run: check the product with uvala_bdmg_plugin_disable if allow to run and options are needed
  268.         if ($uv_allow_output_badges == 1) {
  269.             $uvtmpcheck_product_allowed 0;
  270.             if (isset($uv_current_product->get('customFields')['uvala_bdmg_plugin_disable'])) {
  271.                 if ($uv_current_product->get('customFields')['uvala_bdmg_plugin_disable'] == true) {
  272.                     $uvtmpcheck_product_allowed 0;
  273.                 } else {
  274.                     $uvtmpcheck_product_allowed 1;
  275.                 }
  276.             } else {
  277.                 $uvtmpcheck_product_allowed 1;
  278.             }
  279.             if ($uvtmpcheck_product_allowed == 1) {
  280.                 $uv_allow_output_product 1;
  281.                 if ($uv_product_options_load == 1) {
  282.                     if ($uv_current_product->get('parentId') != '') {
  283.                         $uv_product_options_needed_load $uv_current_product->get('parentId');
  284.                     }
  285.                 }
  286.                 if ($uv_product_properties_load == 1) {
  287.                     if (!empty($uv_current_product->get('propertyIds'))) {
  288.                         foreach ($uv_current_product->getSortedProperties()->getElements() as $uvtmp_properties_groups) {
  289.                             $uv_product_properties_array['properties_groups'][$uvtmp_properties_groups->get('id')] = ['name' => $uvtmp_properties_groups->get('translated')['name'], 'excluded' => $this->addExcludedForPropertyGroup($uvtmp_properties_groups->getCustomFields())];
  290.                             foreach ($uvtmp_properties_groups->getOptions()->getElements() as $uvtmp_properties_groups_values) {
  291.                                 $uv_product_properties_array['properties_groups'][$uvtmp_properties_groups->get('id')]['properties'][$uvtmp_properties_groups_values->get('id')] = ['name' => $uvtmp_properties_groups_values->get('translated')['name']];
  292.                             }
  293.                         }
  294.                     }
  295.                 }
  296.             }
  297.         }
  298.         // if allow to run the output?
  299.         if (($uv_allow_output_badges == 1) && ($uv_allow_output_product == 1)) {
  300.             // load options with properties from product if needed
  301.             if (($uv_product_options_needed_load != '') && ($uv_product_options_load == 1)) {
  302.                 if ($uv_product_properties_load == 1) {
  303.                     $uvtmp_load_associations = ['options''options.group''properties''properties.group'];
  304.                 } else {
  305.                     $uvtmp_load_associations = ['options''options.group'];
  306.                 }
  307.                 $search_options_criteria = new Criteria();
  308.                 $search_options_criteria->addFilter(new EqualsFilter('parentId'$uv_product_options_needed_load), new EqualsFilter('active'true))->addAssociations($uvtmp_load_associations);
  309.                 $uvresult_products_only_options $this->productRepository->search($search_options_criteria$event->getContext());
  310.                 foreach ($uvresult_products_only_options->getEntities()->getElements() as $uvtmp_products_oo) {
  311.                     $uvtmp_option_parentid $uvtmp_products_oo->get('parentId');
  312.                     if ($uv_product_properties_load == 1) {
  313.                         foreach ($uvtmp_products_oo->get('properties') as $uvtmp_properties_groups) {
  314.                             if (!isset($uv_product_options_array[$uvtmp_option_parentid]['properties_groups'][$uvtmp_properties_groups->get('groupId')])) {
  315.                                 $uv_product_options_array[$uvtmp_option_parentid]['properties_groups'][$uvtmp_properties_groups->get('groupId')] = ['name' => $uvtmp_properties_groups->get('group')->get('translated')['name'], 'excluded' => $this->addExcludedForPropertyGroup($uvtmp_properties_groups->getGroup()->getCustomFields())];
  316.                             }
  317.                             $uv_product_options_array[$uvtmp_option_parentid]['properties_groups'][$uvtmp_properties_groups->get('groupId')]['properties'][$uvtmp_properties_groups->get('id')] = ['name' => $uvtmp_properties_groups->get('translated')['name'], 'excluded' => $this->addExcludedForPropertyGroup($uvtmp_properties_groups->getGroup()->getCustomFields())];
  318.                         }
  319.                     }
  320.                     foreach ($uvtmp_products_oo->get('options') as $uvtmp_option_groups) {
  321.                         if (!isset($uv_product_options_array[$uvtmp_option_parentid]['option_groups'][$uvtmp_option_groups->get('groupId')])) {
  322.                             $uv_product_options_array[$uvtmp_option_parentid]['option_groups'][$uvtmp_option_groups->get('groupId')] = ['name' => $uvtmp_option_groups->get('group')->get('translated')['name']];
  323.                         }
  324.                         $uv_product_options_array[$uvtmp_option_parentid]['option_groups'][$uvtmp_option_groups->get('groupId')]['options'][$uvtmp_option_groups->get('id')] = ['name' => $uvtmp_option_groups->get('translated')['name']];
  325.                     }
  326.                     $uvtmp_option_stock $uvtmp_products_oo->get('availableStock');
  327.                     if (isset($uv_product_options_array[$uvtmp_option_parentid]['stock_calc'])) {
  328.                         $uv_product_options_array[$uvtmp_option_parentid]['stock_calc'] = ($uv_product_options_array[$uvtmp_option_parentid]['stock_calc']+$uvtmp_option_stock);
  329.                         if ($uvtmp_option_stock $uv_product_options_array[$uvtmp_option_parentid]['stock_min']) {
  330.                             $uv_product_options_array[$uvtmp_option_parentid]['stock_min'] = $uvtmp_option_stock;
  331.                         }
  332.                         if ($uvtmp_option_stock $uv_product_options_array[$uvtmp_option_parentid]['stock_max']) {
  333.                             $uv_product_options_array[$uvtmp_option_parentid]['stock_max'] = $uvtmp_option_stock;
  334.                         }
  335.                     } else {
  336.                         $uv_product_options_array[$uvtmp_option_parentid]['stock_calc'] = $uvtmp_option_stock;
  337.                         $uv_product_options_array[$uvtmp_option_parentid]['stock_min'] = $uvtmp_option_stock;
  338.                         $uv_product_options_array[$uvtmp_option_parentid]['stock_max'] = $uvtmp_option_stock;
  339.                     }
  340.                     $uvtmp_discount_val '0';
  341.                     $uvtmp_discount_checking $uvtmp_products_oo->getPrice()->getElements()[$uv_current_currencyid];
  342.                     if ($uvtmp_discount_checking->getListPrice() != '') {
  343.                         if ($uvtmp_discount_checking->getListPrice()->getGross() != '0') {
  344.                             $uvtmp_discount_val round(((($uvtmp_discount_checking->getListPrice()->getGross())-($uvtmp_discount_checking->getGross()))/($uvtmp_discount_checking->getListPrice()->getGross()))*1002);
  345.                         }
  346.                     }
  347.                     if (isset($uv_product_options_array[$uvtmp_option_parentid]['discount_calc'])) {
  348.                         $uv_product_options_array[$uvtmp_option_parentid]['discount_calc'] = ($uv_product_options_array[$uvtmp_option_parentid]['discount_calc']+$uvtmp_discount_val);
  349.                         if ($uvtmp_discount_val $uv_product_options_array[$uvtmp_option_parentid]['discount_min']) {
  350.                             $uv_product_options_array[$uvtmp_option_parentid]['discount_min'] = $uvtmp_discount_val;
  351.                         }
  352.                         if ($uvtmp_discount_val $uv_product_options_array[$uvtmp_option_parentid]['discount_max']) {
  353.                             $uv_product_options_array[$uvtmp_option_parentid]['discount_max'] = $uvtmp_discount_val;
  354.                         }
  355.                     } else {
  356.                         $uv_product_options_array[$uvtmp_option_parentid]['discount_calc'] = $uvtmp_discount_val;
  357.                         $uv_product_options_array[$uvtmp_option_parentid]['discount_min'] = $uvtmp_discount_val;
  358.                         $uv_product_options_array[$uvtmp_option_parentid]['discount_max'] = $uvtmp_discount_val;
  359.                     }
  360.                     $uvtmp_deliverytime_min '0';
  361.                     $uvtmp_deliverytime_max '0';
  362.                     if ($uvtmp_products_oo->get('deliveryTime') != '') {
  363.                         $uvtmp_deliverytime_min $this->uv_recalculate_delivery_time($uvtmp_products_oo->get('deliveryTime')->get('min'), $uvtmp_products_oo->get('deliveryTime')->get('unit'));
  364.                         $uvtmp_deliverytime_max $this->uv_recalculate_delivery_time($uvtmp_products_oo->get('deliveryTime')->get('max'), $uvtmp_products_oo->get('deliveryTime')->get('unit'));
  365.                     }
  366.                     if (isset($uv_product_options_array[$uvtmp_option_parentid]['delivery_min'])) {
  367.                         if ($uvtmp_deliverytime_min $uv_product_options_array[$uvtmp_option_parentid]['delivery_min']) {
  368.                             $uv_product_options_array[$uvtmp_option_parentid]['delivery_min'] = $uvtmp_deliverytime_min;
  369.                         }
  370.                         if ($uvtmp_deliverytime_max $uv_product_options_array[$uvtmp_option_parentid]['delivery_max']) {
  371.                             $uv_product_options_array[$uvtmp_option_parentid]['delivery_max'] = $uvtmp_deliverytime_max;
  372.                         }
  373.                     } else {
  374.                         $uv_product_options_array[$uvtmp_option_parentid]['delivery_min'] = $uvtmp_deliverytime_min;
  375.                         $uv_product_options_array[$uvtmp_option_parentid]['delivery_max'] = $uvtmp_deliverytime_max;
  376.                     }
  377.                     if (isset($uv_product_options_array[$uvtmp_option_parentid]['shippingfree_check'])) {
  378.                         if ($uvtmp_products_oo->get('shippingFree') == '1') {
  379.                             $uv_product_options_array[$uvtmp_option_parentid]['shippingfree_check'] = $uvtmp_products_oo->get('shippingFree');
  380.                         }
  381.                     } else {
  382.                         $uv_product_options_array[$uvtmp_option_parentid]['shippingfree_check'] = $uvtmp_products_oo->get('shippingFree');
  383.                     }
  384.                 }
  385.             }
  386.             // last run: collect data and write output to product
  387.             $uv_product_data_array = [];
  388.             $uvtmp_variants_data '';
  389.             if ($uv_product_options_load == 1) {
  390.                 if (isset($uv_product_options_array[$uv_current_product->get('parentId')])) {
  391.                     $uvtmp_variants_data $uv_product_options_array[$uv_current_product->get('parentId')];
  392.                 }
  393.             }
  394.             $uvtmp_properties_data '';
  395.             if ($uv_product_properties_load == 1) {
  396.                 if (!empty($uv_product_properties_array)) {
  397.                     $uvtmp_properties_data $uv_product_properties_array;
  398.                 }
  399.             }
  400.             $uvtmp_discount_value '0';
  401.             if ($uv_current_product->get('calculatedPrice')->getListPrice() != '') {
  402.                 $uvtmp_discount_value $uv_current_product->get('calculatedPrice')->getListPrice()->getPercentage();
  403.             }
  404.             $uvtmp_delivery_time_min '0';
  405.             $uvtmp_delivery_time_max '0';
  406.             if ($uv_current_product->get('deliveryTime') != '') {
  407.                 $uvtmp_delivery_time_min $this->uv_recalculate_delivery_time($uv_current_product->get('deliveryTime')->get('min'), $uv_current_product->get('deliveryTime')->get('unit'));
  408.                 $uvtmp_delivery_time_max $this->uv_recalculate_delivery_time($uv_current_product->get('deliveryTime')->get('max'), $uv_current_product->get('deliveryTime')->get('unit'));
  409.             }
  410.             $uv_product_data_array = ['variants' => $uvtmp_variants_data,
  411.                 'properties' => $uvtmp_properties_data,
  412.                 'stock_current' => $uv_current_product->get('availableStock'),
  413.                 'discount_value' => $uvtmp_discount_value,
  414.                 'delivery_time_min' => $uvtmp_delivery_time_min,
  415.                 'delivery_time_max' => $uvtmp_delivery_time_max,
  416.                 'shippingfree_check' => $uv_current_product->get('shippingFree'),
  417.                 'topseller_check' => $uv_current_product->get('markAsTopseller'),
  418.                 'newproduct_check' => $uv_current_product->get('isNew')
  419.             ];
  420.             $uv_current_page->addExtension('badge_manager', new ArrayEntity(['badges_array' => $this->uv_badge_manager_output($uv_product_data_array)]));
  421.         }
  422.     }
  423.     public function uv_badge_manager_output($uv_product_data) {
  424.         global $uv_plugin_global_settings;
  425.         $uvoutput_array = [];
  426.         $uv_plugin_setting_name 'uvalaBadgeManagerVsix.config.';
  427.         for ($uvbgct 1$uvbgct<=8$uvbgct++) {
  428.             if (isset($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstStatePart'.$uvbgct])) {
  429.                 if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstStatePart'.$uvbgct] == 'activated') {
  430.                     if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'prod_prop') {
  431.                         // Only deal with product properties
  432.                         $uvtmp_prop_array = [];
  433.                         if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'only_master') {
  434.                             if (isset($uv_product_data['properties']['properties_groups'])) {
  435.                                 if (!empty($uv_product_data['properties']['properties_groups'])) {
  436.                                     $uvtmp_prop_array $uv_product_data['properties']['properties_groups'];
  437.                                 }
  438.                             }
  439.                         } else {
  440.                             if (isset($uv_product_data['variants']['properties_groups'])) {
  441.                                 if (!empty($uv_product_data['variants']['properties_groups'])) {
  442.                                     $uvtmp_prop_array $uv_product_data['variants']['properties_groups'];
  443.                                 }
  444.                             } else {
  445.                                 if (isset($uv_product_data['properties']['properties_groups'])) {
  446.                                     if (!empty($uv_product_data['properties']['properties_groups'])) {
  447.                                         $uvtmp_prop_array $uv_product_data['properties']['properties_groups'];
  448.                                     }
  449.                                 }
  450.                             }
  451.                         }
  452.                         if (!empty($uvtmp_prop_array)) {
  453.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOutputFormating'.$uvbgct] == 'each_options') {
  454.                                 foreach ($uvtmp_prop_array as $uvtmp_prop) {
  455.                                     if (!array_key_exists('excluded'$uvtmp_prop) || !$uvtmp_prop['excluded'] || $uvtmp_prop['excluded'][$uvbgct] == false) {
  456.                                     foreach ($uvtmp_prop['properties'] as $uvtmp_value) {
  457.                                         $uvoutput_array[] = ['bg_nr' => $uvbgct,
  458.                                             'bg_sorting' => $uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstSorting'.$uvbgct],
  459.                                             'bg_replace_initialval' => '',
  460.                                             'bg_replace_prop' => $uvtmp_prop['name'],
  461.                                             'bg_replace_prop_val' => $uvtmp_value['name'],
  462.                                             'bg_css' => $uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstBadgeCSSAddendCode'.$uvbgct],
  463.                                             'bg_color' => $uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstColorPart'.$uvbgct],
  464.                                             'bg_background' => $uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstBackgroundPart'.$uvbgct]
  465.                                         ];
  466.                                     }
  467.                                     }
  468.                                 }
  469.                             } else {
  470.                                 foreach ($uvtmp_prop_array as $uvtmp_prop) {
  471.                                     $uvtmp_bgpos_property_string '';
  472.                                     if (!array_key_exists('excluded'$uvtmp_prop) || !$uvtmp_prop['excluded'] || $uvtmp_prop['excluded'][$uvbgct] == false) {
  473.                                         foreach ($uvtmp_prop['properties'] as $uvtmp_value) {
  474.                                             $uvtmp_bgpos_property_string .= $uvtmp_value['name'] . ', ';
  475.                                         }
  476.                                         $uvoutput_array[] = ['bg_nr' => $uvbgct,
  477.                                             'bg_sorting' => $uv_plugin_global_settings[$uv_plugin_setting_name 'uvbdmgrstSorting' $uvbgct],
  478.                                             'bg_replace_initialval' => '',
  479.                                             'bg_replace_prop' => $uvtmp_prop['name'],
  480.                                             'bg_replace_prop_val' => rtrim($uvtmp_bgpos_property_string', '),
  481.                                             'bg_css' => $uv_plugin_global_settings[$uv_plugin_setting_name 'uvbdmgrstBadgeCSSAddendCode' $uvbgct],
  482.                                             'bg_color' => $uv_plugin_global_settings[$uv_plugin_setting_name 'uvbdmgrstColorPart' $uvbgct],
  483.                                             'bg_background' => $uv_plugin_global_settings[$uv_plugin_setting_name 'uvbdmgrstBackgroundPart' $uvbgct],
  484.                                         ];
  485.                                     }
  486.                                 }
  487.                             }
  488.                         }
  489.                     } else {
  490.                         // Deal with output values
  491.                         $uvtmp_bgpos_initial_value 0;
  492.                         $uvtmp_bgpos_initial_value_max 0;
  493.                         if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'stock') {
  494.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'only_master') {
  495.                                 $uvtmp_bgpos_initial_value $uv_product_data['stock_current'];
  496.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'biggest') {
  497.                                 if (isset($uv_product_data['variants']['stock_max'])) {
  498.                                     $uvtmp_bgpos_initial_value $uv_product_data['variants']['stock_max'];
  499.                                 } else {
  500.                                     $uvtmp_bgpos_initial_value $uv_product_data['stock_current'];
  501.                                 }
  502.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'smallest') {
  503.                                 if (isset($uv_product_data['variants']['stock_min'])) {
  504.                                     $uvtmp_bgpos_initial_value $uv_product_data['variants']['stock_min'];
  505.                                 } else {
  506.                                     $uvtmp_bgpos_initial_value $uv_product_data['stock_current'];
  507.                                 }
  508.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'combine') {
  509.                                 if (isset($uv_product_data['variants']['stock_calc'])) {
  510.                                     $uvtmp_bgpos_initial_value $uv_product_data['variants']['stock_calc'];
  511.                                 } else {
  512.                                     $uvtmp_bgpos_initial_value $uv_product_data['stock_current'];
  513.                                 }
  514.                             }
  515.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'discount') {
  516.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'only_master') {
  517.                                 $uvtmp_bgpos_initial_value $uv_product_data['discount_value'];
  518.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'biggest') {
  519.                                 if (isset($uv_product_data['variants']['discount_max'])) {
  520.                                     $uvtmp_bgpos_initial_value $uv_product_data['variants']['discount_max'];
  521.                                 } else {
  522.                                     $uvtmp_bgpos_initial_value $uv_product_data['discount_value'];
  523.                                 }
  524.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'smallest') {
  525.                                 if (isset($uv_product_data['variants']['discount_min'])) {
  526.                                     $uvtmp_bgpos_initial_value $uv_product_data['variants']['discount_min'];
  527.                                 } else {
  528.                                     $uvtmp_bgpos_initial_value $uv_product_data['discount_value'];
  529.                                 }
  530.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'combine') {
  531.                                 if (isset($uv_product_data['variants']['discount_calc'])) {
  532.                                     $uvtmp_bgpos_initial_value $uv_product_data['variants']['discount_calc'];
  533.                                 } else {
  534.                                     $uvtmp_bgpos_initial_value $uv_product_data['discount_value'];
  535.                                 }
  536.                             }
  537.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'delivery') {
  538.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'only_master') {
  539.                                 $uvtmp_bgpos_initial_value $uv_product_data['delivery_time_min'];
  540.                                 $uvtmp_bgpos_initial_value_max $uv_product_data['delivery_time_max'];
  541.                             } else {
  542.                                 if (isset($uv_product_data['variants']['delivery_max']) && isset($uv_product_data['variants']['delivery_min'])) {
  543.                                     if (($uv_product_data['variants']['delivery_max'] == '0') && ($uv_product_data['variants']['delivery_min'] == '0')) {
  544.                                         $uvtmp_bgpos_initial_value $uv_product_data['delivery_time_min'];
  545.                                         $uvtmp_bgpos_initial_value_max $uv_product_data['delivery_time_max'];
  546.                                     } else {
  547.                                         $uvtmp_bgpos_initial_value $uv_product_data['variants']['delivery_min'];
  548.                                         $uvtmp_bgpos_initial_value_max $uv_product_data['variants']['delivery_max'];
  549.                                     }
  550.                                 } else {
  551.                                     $uvtmp_bgpos_initial_value $uv_product_data['delivery_time_min'];
  552.                                     $uvtmp_bgpos_initial_value_max $uv_product_data['delivery_time_max'];
  553.                                 }
  554.                             }
  555.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'check_freeshipping') {
  556.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstVariantHandlingPart'.$uvbgct] == 'only_master') {
  557.                                 if ($uv_product_data['shippingfree_check'] == '1') {
  558.                                     $uvtmp_bgpos_initial_value 1;
  559.                                 }
  560.                             } else {
  561.                                 if (isset($uv_product_data['variants']['shippingfree_check'])) {
  562.                                     if ($uv_product_data['variants']['shippingfree_check'] == '1') {
  563.                                         $uvtmp_bgpos_initial_value 1;
  564.                                     }
  565.                                 }
  566.                             }
  567.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'check_variants') {
  568.                             if (!empty($uv_product_data['variants'])) {
  569.                                 $uvtmp_bgpos_initial_value 1;
  570.                             }
  571.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'check_topseller') {
  572.                             if ($uv_product_data['topseller_check'] == '1') {
  573.                                 $uvtmp_bgpos_initial_value 1;
  574.                             }
  575.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'check_new') {
  576.                             if ($uv_product_data['newproduct_check'] == '1') {
  577.                                 $uvtmp_bgpos_initial_value 1;
  578.                             }
  579.                         }
  580.                         // done, check if allow to output
  581.                         $uvtmp_badge_activate 0;
  582.                         $uvtmp_reference_check $uvtmp_bgpos_initial_value;
  583.                         $uvtmp_reference_check_max $uvtmp_bgpos_initial_value;
  584.                         if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstActivatedOnFuncPart'.$uvbgct] == 'delivery') {
  585.                             $uvtmp_reference_check $uvtmp_bgpos_initial_value;
  586.                             $uvtmp_reference_check_max $uvtmp_bgpos_initial_value_max;
  587.                         }
  588.                         if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOperatorPart'.$uvbgct] == 'equal') {
  589.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstValuePart'.$uvbgct] == $uvtmp_reference_check) {
  590.                                 $uvtmp_badge_activate 1;
  591.                             }
  592.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOperatorPart'.$uvbgct] == 'smaller') {
  593.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstValuePart'.$uvbgct] > $uvtmp_reference_check) {
  594.                                 $uvtmp_badge_activate 1;
  595.                             }
  596.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOperatorPart'.$uvbgct] == 'bigger') {
  597.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstValuePart'.$uvbgct] < $uvtmp_reference_check) {
  598.                                 $uvtmp_badge_activate 1;
  599.                             }
  600.                         } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOperatorPart'.$uvbgct] == 'reference') {
  601.                             if (($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstValuePart'.$uvbgct] < $uvtmp_reference_check) && ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstMaxValuePart'.$uvbgct] > $uvtmp_reference_check_max)) {
  602.                                 $uvtmp_badge_activate 1;
  603.                             }
  604.                         }
  605.                         if ($uvtmp_badge_activate == 1) {
  606.                             if ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOutputFormating'.$uvbgct] == 'cut_decimal') {
  607.                                 $uvtmp_bgpos_initial_value explode('.'strval($uvtmp_bgpos_initial_value));
  608.                                 $uvtmp_bgpos_initial_value $uvtmp_bgpos_initial_value[0];
  609.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOutputFormating'.$uvbgct] == 'round_up') {
  610.                                 $uvtmp_bgpos_initial_value number_format($uvtmp_bgpos_initial_value0);
  611.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOutputFormating'.$uvbgct] == 'round_two') {
  612.                                 if (strpos(strval($uvtmp_bgpos_initial_value), '.') === false) {
  613.                                 } else {
  614.                                     $uvtmp_bgpos_initial_value number_format($uvtmp_bgpos_initial_value2',''');
  615.                                 }
  616.                             } elseif ($uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstOutputFormating'.$uvbgct] == 'round_one') {
  617.                                 if (strpos(strval($uvtmp_bgpos_initial_value), '.') === false) {
  618.                                 } else {
  619.                                     $uvtmp_bgpos_initial_value number_format($uvtmp_bgpos_initial_value1',''');
  620.                                 }
  621.                             } else {
  622.                                 $uvtmp_bgpos_initial_value str_replace('.'','$uvtmp_bgpos_initial_value);
  623.                             }
  624.                             $uvoutput_array[] = ['bg_nr' => $uvbgct,
  625.                                 'bg_sorting' => $uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstSorting'.$uvbgct],
  626.                                 'bg_replace_initialval' => $uvtmp_bgpos_initial_value,
  627.                                 'bg_replace_prop' => '',
  628.                                 'bg_replace_prop_val' => '',
  629.                                 'bg_css' => $uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstBadgeCSSAddendCode'.$uvbgct],
  630.                                 'bg_color' => $uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstColorPart'.$uvbgct],
  631.                                 'bg_background' => $uv_plugin_global_settings[$uv_plugin_setting_name.'uvbdmgrstBackgroundPart'.$uvbgct]
  632.                             ];
  633.                         }
  634.                     }
  635.                 }
  636.             }
  637.         }
  638.         if (count($uvoutput_array) > 0) {
  639.             $uvtmp_array_position = array();
  640.             foreach ($uvoutput_array as $key => $row) {
  641.                 $uvtmp_array_position[$key] = $row['bg_sorting'];
  642.             }
  643.             array_multisort($uvtmp_array_positionSORT_ASC$uvoutput_array);
  644.         }
  645.         return $uvoutput_array;
  646.     }
  647.     public function uv_load_plugin_settings($uv_saleschannel_id) {
  648.         global $uv_plugin_global_settings;
  649.         $uv_settings $this->systemConfigService->getDomain('uvalaBadgeManagerVsix');
  650.         $uv_settings_saleschannel $this->systemConfigService->getDomain('uvalaBadgeManagerVsix'$uv_saleschannel_id);
  651.         $uv_plugin_global_settings array_merge($uv_settings$uv_settings_saleschannel);
  652.         return true;
  653.     }
  654.     private function addExcludedForPropertyGroup($customFields) {
  655.         $filtered = [];
  656.         if ($customFields) {
  657.             foreach($customFields as $key => $val) {
  658.                 if(false !== strpos($keyuvalaBadgeManagerVsix::PROPERTY_GROUP_EXCLUDED_CF_NAME)) {
  659.                     $filtered[substr($key, -1)] = $val;
  660.                 }
  661.             }
  662.         }
  663.         return $filtered;
  664.     }
  665.     public function uv_recalculate_delivery_time($uv_delivery_time$uv_delivery_unit) {
  666.         $uv_output_calc 0;
  667.         if ($uv_delivery_unit == 'week') {
  668.             $uv_output_calc = ($uv_delivery_time*7);
  669.         } elseif ($uv_delivery_unit == 'month') {
  670.             $uv_output_calc = ($uv_delivery_time*30);
  671.         } elseif ($uv_delivery_unit == 'year') {
  672.             $uv_output_calc = ($uv_delivery_time*365);
  673.         } else {
  674.             // unit: day
  675.             $uv_output_calc $uv_delivery_time;
  676.         }
  677.         return $uv_output_calc;
  678.     }
  679. }