Hallo zusammen,
ich habe hier ein kleines legacy Plugin, was seit dem Update auf 5.7 nicht mehr funktioniert.
Meine Bootstrap.php:
<?php
use ShopwarePlugins\LnetTextbausteine\Bundle\StoreFrontBundle\ListProductService;
class Shopware_Plugins_Frontend_LnetTextbausteine_Bootstrap extends Shopware_Components_Plugin_Bootstrap {
public function getVersion() {
return '1.0.0';
}
public function getLabel() {
return 'Plugin: Ersetzt Textbausteine in der Storefront';
}
public function afterInit() {
$this->get('loader')->registerNamespace('ShopwarePlugins\LnetTextbausteine', $this->Path());
}
public function install() {
$this->createConfiguration();
$events = [
'Enlight_Bootstrap_AfterInitResource_shopware_storefront.list_product_service' => 'decorateListProductService',
];
foreach ($events as $event => $listener) {
$this->subscribeEvent($event, $listener);
}
return true;
}
public function decorateListProductService()
{
$coreService = $this->get('shopware_storefront.list_product_service');
$newService = new ListProductService($coreService);
Shopware()->Container()->set('shopware_storefront.list_product_service', $newService);
}
public function uninstall() {
return true;
}
public function createConfiguration() {
$form = $this->Form();
$form->setElement('text', 'namespace',
array(
'label' => 'Standard Namespace',
'description' => 'Der Standard Namespace in dem Textbausteine gesucht werden',
'value' => 'products',
)
);
$form->setElement('text', 'fields',
array(
'label' => 'zu ersetzende Felder',
'description' => 'Felder welche ersetzt werden sollen (Datenbanktitel)',
'value' => 'description_long',
)
);
return true;
}
}
Zeile 16 $this->get(‚loader‘) war vorher $this->get(‚Loader‘). Ich hatte im Forum gelesen, dass das ein beliebter Fehler war. Funktioniert leider trotzdem nicht.
Und das ist meine Bundle/StoreFrontBundle/ListProductService.php:
namespace ShopwarePlugins\LnetTextbausteine\Bundle\StoreFrontBundle;
use Shopware\Bundle\StoreFrontBundle\Service\ListProductServiceInterface;
use Shopware\Bundle\StoreFrontBundle\Struct;
class ListProductService implements ListProductServiceInterface
{
/**
* @var ListProductServiceInterface
*/
private $coreService;
private $config;
/**
* @param ListProductServiceInterface $coreService
*/
function __construct(
ListProductServiceInterface $coreService
) {
$this->coreService = $coreService;
$this->config = Shopware()->Plugins()->Frontend()->LnetTextbausteine()->Config();
}
public function getList(array $numbers, Struct\ProductContextInterface $context)
{
$products = $this->coreService->getList($numbers, $context);
foreach ($products as $product) {
foreach (explode(',', $this->config->fields) as $field) {
switch($field) {
case 'description_long':
$addText = '';
$productAttributes = $product->getAttributes()['core']->get('attr1');
if(!empty($productAttributes)) {
$items = explode(',', $productAttributes);
$addText = '<ul>';
foreach ($items as $item) {
$addText .= '<li>[['.trim($item).']]</li>';
}
$addText .= '</ul>';
}
$product->setLongDescription(preg_replace_callback('/\[\[([^]]+)\]\]/', array($this, 'replaceTextBlock'), $product->getLongDescription().$addText));
break;
}
}
}
return $products;
}
public function get($number, Struct\ProductContextInterface $context)
{
$products = $this->getList([$number], $context);
return array_shift($products);
}
protected function replaceTextBlock($text) {
$config = Shopware()->Plugins()->Frontend()->LnetTextbausteine()->Config();
if (strpos($text[1], '/')) {
preg_match('/.*\/(.*)/', $text[1], $matches);
$key = $matches[1];
$namespace = substr($matches[0], 0, strlen($matches[0])-strlen($matches[1])-1);
} else {
$key = $text[1];
if (strlen($config->namespace) > 0) {
$namespace = $config->namespace;
} else {
$namespace = '';
}
}
$query = 'SELECT `value` FROM s_core_snippets WHERE `namespace` = "'.$namespace.'" AND `name` = "'.$key.'"';
$result = Shopware()->Db()->fetchRow($query);
if ($result) {
return $result['value'];
} else {
return $text[0];
}
}
}
Über jeden Hinweis wäre ich sehr dankbar!
Viele Grüße
Frank