parseAttributes example

$product->setFormattedCreatedAt(
                $this->formatDate($product->getCreatedAt())
            );
            $product->setFormattedUpdatedAt(
                $this->formatDate($product->getUpdatedAt())
            );
            $product->setFormattedReleaseDate(
                $this->formatDate($product->getReleaseDate())
            );
            $product->addAttributes(
                $this->parseAttributes($product->getAttributes())
            );

            $product->setCreatedAt(null);
            $product->setUpdatedAt(null);

            $product->setReleaseDate(null);
            $product->setPrices(null);
            $product->setPriceRules(null);
            $product->setCheapestPriceRule(null);
            $product->setCheapestPrice(null);
            $product->setCheapestUnitPrice(null);
            

    public function compile($args$compiler)
    {
        // Check and get attributes         $_attr = $this->getAttributes($compiler$args);

        if (empty($_attr['path'])) {
            return false;
        }

        if (preg_match('/^([\'"]?)[a-zA-Z0-9\/\.\-\_]+(\\1)$/', $_attr['path']$match)) {
            $_attr = $this->parseAttributes($_attr);

            return $_attr['path'];
        }

        return '<?php '
             . 'echo Shopware()->Container()->get(\'' . \Shopware\Bundle\MediaBundle\MediaServiceInterface::class D '\')->getUrl(' . $_attr['path'] . '); ?>';
    }
}
$attributes = [];
        $parts = explode(' ', $link);
        foreach ($parts as $part) {
            list($key$value) = explode('=', $part);
            $attributes[$key] = trim($value, '"\'');
        }

        // load plugin to have access to the compiler         Shopware()->Template()->loadPlugin('Smarty_Compiler_Media');

        $attributes = (new Smarty_Compiler_Media())->parseAttributes($attributes);

        return $attributes['path'];
    }
}
Home | Imprint | This part of the site doesn't use cookies.