src/AppBundle/EventListener/NameSettingListener.php line 41

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 AppBundle\EventListener;
  15. use \Pimcore\Model\DataObject;
  16. use AppBundle\Model\Product\Category;
  17. use Pimcore\Event\Model\DataObjectEvent;
  18. use Pimcore\Model\DataObject\Color;
  19. use Pimcore\Model\DataObject\Brand;
  20. use Pimcore\Model\DataObject\Attribute;
  21. use Pimcore\Model\DataObject\Buyer;
  22. use Pimcore\Model\DataObject\SubBrand;
  23. use Pimcore\Model\DataObject\Vendor;
  24. use Pimcore\Model\DataObject\Size;
  25. use Pimcore\Model\DataObject\Season;
  26. use Pimcore\Model\DataObject\ExtdClass;
  27. use Pimcore\Model\DataObject\Hierarchy;
  28. use Pimcore\Model\DataObject\Dept;
  29. use Pimcore\Model\DataObject\UnitOfMeasure;
  30. use Pimcore\Model\DataObject\TermCode;
  31. use Pimcore\Model\DataObject\MasterItemStatus;
  32. use Pimcore\Model\DataObject\SKUType;
  33. use Pimcore\Model\DataObject\ItemMaster;
  34. use Pimcore\Model\DataObject\PriceEvent;
  35. use Pimcore\Db;
  36. class NameSettingListener
  37. {
  38.     public function onPreAdd(DataObjectEvent $event)
  39.     {
  40.         $object $event->getObject();
  41.         if ($object instanceof Category) {
  42.           //  $object->setName($object->getKey());
  43.         }
  44.         if ($object instanceof Color) {
  45.           //  $object->setDesc($object->getKey());
  46.         }
  47.         if ($object instanceof Brand) {
  48.            // $object->setBrandName($object->getKey());
  49.         }
  50.         if ($object instanceof Attribute) {
  51.          //  $object->setDescription($object->getKey());
  52.         }
  53.         if ($object instanceof Buyer) {
  54.           //  $object->setBuyerName($object->getKey());
  55.         }
  56.         if ($object instanceof SubBrand) {
  57.           //  $object->setSubbrandName($object->getKey());
  58.         }
  59.         if ($object instanceof Vendor) {
  60.            // $object->setVendorName($object->getKey());
  61.         }
  62.         if ($object instanceof Size) {
  63.             //$object->setDescription($object->getKey());
  64.         }
  65.         if ($object instanceof Season) {
  66.            // $object->setDescription($object->getKey());
  67.         }
  68.         if ($object instanceof ExtdClass) {
  69.           //  $object->setExtdClassName($object->getKey());
  70.         }
  71.         if ($object instanceof ItemMaster) {
  72.           $otype $object->geto_type();
  73.              
  74.             if($otype == 'variant')
  75.             {
  76. $object->setmfrNum('');
  77.             }
  78.            // $object->setitemShortDesc($object->getKey());
  79.             $object->setitemMasterStatus("Draft");
  80.            // $object->setsetCode("1"); 
  81.        }
  82.         if ($object instanceof PriceEvent) {
  83.            // $object->setitemShortDesc($object->getKey());
  84.             $object->setStatus("For Approval");
  85.             $id $object->getId();
  86. //throw new \Pimcore\Model\Element\ValidationException($id, 1234); 
  87. $o_parentId$object->getParentId();
  88. $parentData DataObject::getById($o_parentId);
  89.                  $po_type $parentData->geto_type();
  90.                    //throw new \Pimcore\Model\Element\ValidationException($po_type, 1234);   
  91. if($po_type == 'folder')
  92. {
  93.  $queryOne="select FLOOR(10000 + RAND() * 899999) AS random_num from object_price where 'eventNum' NOT IN (select eventNum from object_price WHERE eventNum IS NOT NULL) LIMIT 1";
  94.                             $statmentEvnt Db::get()->prepare($queryOne);
  95.                             $statmentEvnt->execute();
  96.                             $dataGetEvnt =$statmentEvnt->fetchAll();
  97.                             $uniqueBumberPar=$dataGetEvnt[0]['random_num'];
  98.                 $object->seteventNum($uniqueBumberPar); 
  99. }
  100.             
  101.        }
  102.  
  103.         if ($object instanceof SKUType || $object instanceof MasterItemStatus || $object instanceof TermCode || $object instanceof UnitOfMeasure) {
  104.           //  $object->setDescription($object->getKey());
  105.         }
  106. if ($object instanceof Hierarchy) {
  107. $user = \Pimcore\Tool\Admin::getCurrentUser();
  108. if($user != null)
  109. {
  110.   $o_parentId $object->getParentId();
  111. $parentData DataObject::getById($o_parentId);
  112.                  $po_type $parentData->geto_type();
  113. }
  114.           
  115.          // throw new \Pimcore\Model\Element\ValidationException($po_type, 1234); 
  116.           if(($po_type == 'Object' || $po_type == 'object') && $user != null )
  117.           {
  118.             $deptCode $parentData->getdeptCode();
  119.             $deptName $parentData->getdeptName();
  120.             $deptShortName $parentData->getdeptShortName();
  121.             $subdeptCode $parentData->getsubdeptCode();
  122.             $subdeptName $parentData->getsubdeptName();
  123.             $subdeptShortName $parentData->getsubdeptShortName();
  124.             $clCode $parentData->getclCode();
  125.             $clName $parentData->getclName();
  126.             $clShortName $parentData->getclShortName();
  127.             $subClassCode $parentData->getsubClassCode();
  128.             $subClassName $parentData->getsubClassName();
  129.             $subClassShortName $parentData->getsubClassShortName();
  130.             if($deptCode =!'')
  131.             {
  132.                 $object->setdeptCode($parentData->getdeptCode()); 
  133.             }
  134.             if($deptName =!'')
  135.             {
  136.                 $object->setdeptName($parentData->getdeptName()); 
  137.             }
  138.             if($deptShortName =!'')
  139.             {
  140.                 $object->setdeptShortName($parentData->getdeptShortName());
  141.             }
  142.             if($subdeptCode =!'')
  143.             {
  144.                 $object->setsubdeptCode($parentData->getsubdeptCode());
  145.             }
  146.             if($subdeptName =!'')
  147.             {
  148.                  $object->setsubdeptName($parentData->getsubdeptName());
  149.             }
  150.             if($subdeptShortName =!'')
  151.             {
  152.                 $object->setsubdeptShortName($parentData->getsubdeptShortName());
  153.             }
  154.             if($clCode =!'')
  155.             {
  156.                 $object->setclCode($parentData->getclCode()); 
  157.             }
  158.             if($clName =!'')
  159.             {
  160.                  $object->setclName($parentData->getclName());
  161.             }
  162.             if($clShortName =!'')
  163.             {
  164.                  $object->setclShortName($parentData->getclShortName());
  165.             }
  166.             if($subClassCode =!'')
  167.             {
  168.                  $object->setsubClassCode($parentData->getsubClassCode()); 
  169.             }
  170.             if($subClassName =!'')
  171.             {
  172.                  $object->setsubClassName($parentData->getsubClassName());
  173.             }
  174.             if($subClassShortName =!'')
  175.             {
  176.                 $object->setsubClassShortName($parentData->getsubClassShortName());
  177.             }
  178.            
  179.             
  180.             
  181.              
  182.            
  183.             
  184.              
  185.            
  186.             
  187.            
  188.            
  189.             
  190.           }
  191.            
  192.         }
  193. /*       if ($object instanceof Dept) {
  194.            $object->setName($object->getKey());
  195.            $object->setShortName(preg_replace('#[aeiou\s]+#i', '', $object));
  196.         }*/
  197.     
  198.         
  199.     }
  200. }