Esd example

public function __construct(AttributeHydrator $attributeHydrator)
    {
        $this->attributeHydrator = $attributeHydrator;
    }

    /** * @return Esd */
    public function hydrate(array $data)
    {
        $esd = new Esd();

        if (isset($data['__esd_id'])) {
            $esd->setId((int) $data['__esd_id']);
        }

        if (isset($data['__esd_datum'])) {
            $esd->setCreatedAt(new DateTime($data['__esd_datum']));
        }

        if (isset($data['__esd_file'])) {
            $esd->setFile($data['__esd_file']);
        }
private function prepareEsdAssociation($data, Detail $variant)
    {
        if (\is_array($data['esd'])) {
            $esd = $variant->getEsd();

            // Use already uploaded download file             if (!isset($data['esd']['reuse'])) {
                $data['esd']['reuse'] = false;
            }

            if (!$esd) {
                $esd = new Esd();
                $esd->setArticleDetail($variant);
            }

            if (isset($data['esd']['file'])) {
                $file = $this->getMediaResource()->load($data['esd']['file']);
                $fileName = pathinfo($data['esd']['file'], PATHINFO_FILENAME);
                $fileExt = pathinfo($data['esd']['file'], PATHINFO_EXTENSION);

                $esdDir = Shopware()->DocPath('files_' . Shopware()->Config()->get('sESDKEY'));

                // File already exists?
$variant = $this->get('models')->getRepository(ProductVariant::class)->find($variantId);
        if (!$variant) {
            $this->View()->assign([
                'success' => false,
                'message' => sprintf('Product variant by id %s not found', $variantId),
            ]);

            return;
        }

        $esd = new Esd();
        $esd->setArticleDetail($variant);

        $this->getManager()->persist($esd);
        $this->getManager()->flush();

        $this->View()->assign([
            'success' => true,
        ]);
    }

    /** * Event listener function of the product backend module. * Will be fired when the user saves ESD */
Home | Imprint | This part of the site doesn't use cookies.