<?php
/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Enterprise License (PEL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PEL
*/
namespace AppBundle\EventListener;
use \Pimcore\Model\DataObject;
use AppBundle\Model\Product\Category;
use Pimcore\Event\Model\DataObjectEvent;
use Pimcore\Model\DataObject\Color;
use Pimcore\Model\DataObject\Brand;
use Pimcore\Model\DataObject\Attribute;
use Pimcore\Model\DataObject\Buyer;
use Pimcore\Model\DataObject\SubBrand;
use Pimcore\Model\DataObject\Vendor;
use Pimcore\Model\DataObject\Size;
use Pimcore\Model\DataObject\Season;
use Pimcore\Model\DataObject\ExtdClass;
use Pimcore\Model\DataObject\Hierarchy;
use Pimcore\Model\DataObject\Dept;
use Pimcore\Model\DataObject\UnitOfMeasure;
use Pimcore\Model\DataObject\TermCode;
use Pimcore\Model\DataObject\MasterItemStatus;
use Pimcore\Model\DataObject\SKUType;
use Pimcore\Model\DataObject\ItemMaster;
use Pimcore\Model\DataObject\PriceEvent;
use Pimcore\Db;
class NameSettingListener
{
public function onPreAdd(DataObjectEvent $event)
{
$object = $event->getObject();
if ($object instanceof Category) {
// $object->setName($object->getKey());
}
if ($object instanceof Color) {
// $object->setDesc($object->getKey());
}
if ($object instanceof Brand) {
// $object->setBrandName($object->getKey());
}
if ($object instanceof Attribute) {
// $object->setDescription($object->getKey());
}
if ($object instanceof Buyer) {
// $object->setBuyerName($object->getKey());
}
if ($object instanceof SubBrand) {
// $object->setSubbrandName($object->getKey());
}
if ($object instanceof Vendor) {
// $object->setVendorName($object->getKey());
}
if ($object instanceof Size) {
//$object->setDescription($object->getKey());
}
if ($object instanceof Season) {
// $object->setDescription($object->getKey());
}
if ($object instanceof ExtdClass) {
// $object->setExtdClassName($object->getKey());
}
if ($object instanceof ItemMaster) {
$otype = $object->geto_type();
if($otype == 'variant')
{
$object->setmfrNum('');
}
// $object->setitemShortDesc($object->getKey());
$object->setitemMasterStatus("Draft");
// $object->setsetCode("1");
}
if ($object instanceof PriceEvent) {
// $object->setitemShortDesc($object->getKey());
$object->setStatus("For Approval");
$id = $object->getId();
//throw new \Pimcore\Model\Element\ValidationException($id, 1234);
$o_parentId= $object->getParentId();
$parentData = DataObject::getById($o_parentId);
$po_type = $parentData->geto_type();
//throw new \Pimcore\Model\Element\ValidationException($po_type, 1234);
if($po_type == 'folder')
{
$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";
$statmentEvnt = Db::get()->prepare($queryOne);
$statmentEvnt->execute();
$dataGetEvnt =$statmentEvnt->fetchAll();
$uniqueBumberPar=$dataGetEvnt[0]['random_num'];
$object->seteventNum($uniqueBumberPar);
}
}
if ($object instanceof SKUType || $object instanceof MasterItemStatus || $object instanceof TermCode || $object instanceof UnitOfMeasure) {
// $object->setDescription($object->getKey());
}
if ($object instanceof Hierarchy) {
$user = \Pimcore\Tool\Admin::getCurrentUser();
if($user != null)
{
$o_parentId = $object->getParentId();
$parentData = DataObject::getById($o_parentId);
$po_type = $parentData->geto_type();
}
// throw new \Pimcore\Model\Element\ValidationException($po_type, 1234);
if(($po_type == 'Object' || $po_type == 'object') && $user != null )
{
$deptCode = $parentData->getdeptCode();
$deptName = $parentData->getdeptName();
$deptShortName = $parentData->getdeptShortName();
$subdeptCode = $parentData->getsubdeptCode();
$subdeptName = $parentData->getsubdeptName();
$subdeptShortName = $parentData->getsubdeptShortName();
$clCode = $parentData->getclCode();
$clName = $parentData->getclName();
$clShortName = $parentData->getclShortName();
$subClassCode = $parentData->getsubClassCode();
$subClassName = $parentData->getsubClassName();
$subClassShortName = $parentData->getsubClassShortName();
if($deptCode =!'')
{
$object->setdeptCode($parentData->getdeptCode());
}
if($deptName =!'')
{
$object->setdeptName($parentData->getdeptName());
}
if($deptShortName =!'')
{
$object->setdeptShortName($parentData->getdeptShortName());
}
if($subdeptCode =!'')
{
$object->setsubdeptCode($parentData->getsubdeptCode());
}
if($subdeptName =!'')
{
$object->setsubdeptName($parentData->getsubdeptName());
}
if($subdeptShortName =!'')
{
$object->setsubdeptShortName($parentData->getsubdeptShortName());
}
if($clCode =!'')
{
$object->setclCode($parentData->getclCode());
}
if($clName =!'')
{
$object->setclName($parentData->getclName());
}
if($clShortName =!'')
{
$object->setclShortName($parentData->getclShortName());
}
if($subClassCode =!'')
{
$object->setsubClassCode($parentData->getsubClassCode());
}
if($subClassName =!'')
{
$object->setsubClassName($parentData->getsubClassName());
}
if($subClassShortName =!'')
{
$object->setsubClassShortName($parentData->getsubClassShortName());
}
}
}
/* if ($object instanceof Dept) {
$object->setName($object->getKey());
$object->setShortName(preg_replace('#[aeiou\s]+#i', '', $object));
}*/
}
}