Shopware: Alle Attr-Felder im Export

Ich hatte es schon fertig und dachte ich könnte es später auch mal im Community Store anbieten.. aber dann kam mir schon jemand zu vor und dann auch noch kosten los.

Also hier einfach mein Plugin als Code für jeden:


<?php
namespace HPrExportAttrExtend;

use Doctrine\DBAL\Connection;
use Shopware\Components\Plugin;

class HPrExportAttrExtend extends Plugin{

private $ignoreFields = [
'articleID',
'articledetailsID',
'attr1',
'attr2',
'attr3',
'attr4',
'attr5',
'attr6',
'attr7',
'attr8',
'attr9',
'attr10',
'attr11',
'attr12',
'attr13',
'attr14',
'attr15',
'attr16',
'attr17',
'attr18',
'attr19',
'attr20',
];

public static function getSubscribedEvents(){
return [
'sExport::sCreateSql::after' => 'extendExportArticleSql',
];
}

public function extendExportArticleSql(\Enlight_Hook_HookArgs $args){
$sql = $args->getReturn();

$fields = $this->getAllColumnNames();
if(count($fields) > 0){
$fields[] = 'at.attr20';

$sql = preg_replace("/at\.attr20/i", implode(', ', $fields), $sql);
}

$args->setReturn($sql);
}

private function getAllColumnNames(){
/** @var Connection $dbal */
$dbal = $this->container->get('dbal_connection');
$sql = 'SHOW columns FROM :tablename';
$stmt = $dbal->prepare($sql);
$stmt->execute(['tablename' => 's_articles_attributes']);
$rows = $stmt->fetchAll();
$fields = [];
foreach ($rows as $row){
$name = $row['field'];
if(!in_array($name, $this->ignoreFields)){
$fields[] = 'at.' . $name;
}
}
return $fields;
}
}
User annonyme 2017-10-20 21:09

write comment:
Two + = 8

Möchtest Du AdSense-Werbung erlauben und mir damit helfen die laufenden Kosten des Blogs tragen zu können?