EsdSerial example

        $serials = array_unique($serials);

        $newSerials = 0;

        foreach ($serials as $serialnumber) {
            $serialnumber = trim($serialnumber);
            $serial = $this->get('models')->getRepository(EsdSerial::class)->findOneBy(['serialnumber' => $serialnumber]);
            if ($serial) {
                continue;
            }

            $serial = new EsdSerial();
            $serial->setSerialnumber($serialnumber);
            $serial->setEsd($esd);
            $this->getManager()->persist($serial);
            ++$newSerials;
        }
        $this->getManager()->flush();

        // Update stock         $freeSerialsCount = $this->getFreeSerialCount($esdId);
        $variant = $esd->getArticleDetail();
        $variant->setInStock($freeSerialsCount);

        
        foreach ($data['esd']['serials'] as $newSerial) {
            $found = false;

            foreach ($esd->getSerials() as $serial) {
                if ($newSerial['serialnumber'] === $serial->getSerialnumber()) {
                    $found = true;
                    break;
                }
            }

            if ($found === false) {
                $newSerialModel = new EsdSerial();
                $newSerialModel->fromArray($newSerial);
                $newSerialModel->setEsd($esd);
                $this->getManager()->persist($newSerialModel);
                $esd->getSerials()->add($newSerialModel);
            }
        }

        unset($data['esd']['serials']);

        return $data;
    }
}
Home | Imprint | This part of the site doesn't use cookies.