bundles/Jabber/GenericBundle/EventListener/GridListener.php line 10

Open in your IDE?
  1. <?php 
  2. namespace Jabber\GenericBundle\EventListener;
  3. use \Pimcore\Bundle\AdminBundle\Controller\AdminController;
  4. use Symfony\Component\EventDispatcher\GenericEvent;
  5. class GridListener extends AdminController {
  6.     public function beforeListLoad(GenericEvent $list$context) {
  7.         $test "test";
  8.         $objects $list->getArgument('list');
  9.         $listData $objects['data'];
  10.         foreach ($listData as $key=>$object) {
  11.             if (isset($object['AssociatedProducts'])) {
  12.                 $listData $this->GetAssociatedProductValue($listData$key$object['AssociatedProducts']);
  13.             }
  14.             if (isset($object['ProductLevel'])) {
  15.                 $listData $this->GetProductLevel($listData$key$object['ProductLevel']);
  16.             }
  17.         }
  18.         $objects['data'] = $listData;
  19.         $list->setArgument('list'$objects);
  20.     }
  21.     private function GetAssociatedProductValue($listData$key$associatedProducts) {
  22.         foreach ($associatedProducts as $linkKey=>$linkValue) {
  23.             if (isset($linkValue['PmCode']) && !empty($linkValue['PmCode'])) {
  24.                 $listData[$key]['AssociatedProducts'][$linkKey]['fullpath'] = $linkValue['PmCode'];
  25.                 continue;
  26.             }
  27.             if (!empty($linkValue['Colour'])) {
  28.                 
  29.                 $colour array_filter($linkValue['Colour%options'], function($ar) use($linkValue) {
  30.                     return ($ar['value'] == $linkValue['Colour']);
  31.                     //return ($ar['name'] == 'cat 1' AND $ar['id'] == '3');// you can add multiple conditions
  32.                 });
  33.                 $colour reset($colour)['key'] ?? '';
  34.             } else {
  35.                 $colour "";
  36.             }
  37.             $colour = !empty($colour) ? '-'.$colour '';
  38.             $listData[$key]['AssociatedProducts'][$linkKey]['fullpath'] = "<span class=\"text-xs bg-pink-50 border border-1 rounded-md px-1\">" $linkValue['SKU'].$colour "</span>";
  39.         }
  40.         return $listData;
  41.     }
  42.     private function GetProductLevel($listData$key$productLevel) {
  43.         if ($productLevel == "PARENT") {
  44.             $value "<div class='bg-purple-100 text-purple-700 text-center rounded-md'>PARENT</div>";
  45.         } else if ($productLevel == "STYLE") {
  46.             $value "<div class='bg-blue-100 text-blue-700 text-center rounded-md'>STYLE</div>";
  47.         } else if ($productLevel == "CHILD") {
  48.             $value "<div class='bg-yellow-100 text-yellow-700 text-center rounded-md'>CHILD</div>";
  49.         }
  50.         $listData[$key]['ProductLevel'] = $value;
  51.         return $listData;
  52.     }
  53. }