Skip to content

Commit

Permalink
Shopware6: Matatags (Titel, Beschreibung, Keywords) in Shop übernehmen
Browse files Browse the repository at this point in the history
  • Loading branch information
z4m1n0 committed Oct 22, 2024
1 parent 87572c0 commit 88b1a5d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
9 changes: 9 additions & 0 deletions SL/Controller/ShopPart.pm
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,15 @@ sub create_or_update {

my $is_new = !$self->shop_part->id;
my $params = delete($::form->{shop_part}) || { };

my $shop = SL::DB::Manager::Shop->find_by(id => $params->{shop_id});
if ($shop && $shop->connector eq 'shopware6') {
die t8("Part Metatag Title is too long for this Shopware version. It should have lower than 255 characters.")
if length $params->{metatag_title} > 255;
die t8("Part Metatag Description is too long for this Shopware version. It should have lower than 255 characters.")
if length $params->{metatag_description} > 255;
}

$self->shop_part->assign_attributes(%{ $params });
$self->shop_part->save;

Expand Down
28 changes: 22 additions & 6 deletions SL/ShopConnector/Shopware6.pm
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ sub update_part {
? _u8($part->notes)
: _u8($shop_part->shop_description);

$update_p->{metaTitle} = _u8($shop_part->metatag_title) if $shop_part->metatag_title;
$update_p->{metaDescription} = _u8($shop_part->metatag_description) if $shop_part->metatag_description;
$update_p->{keywords} = _u8($shop_part->metatag_keywords) if $shop_part->metatag_keywords;

# locales simple check for english
my $english = SL::DB::Manager::Language->get_first(query => [ description => { ilike => 'Englisch' },
or => [ template_code => { ilike => 'en' } ],
Expand Down Expand Up @@ -180,11 +184,7 @@ sub update_part {
}
undef $update_p->{partNumber}; # we dont need this one
$ret = $self->connector->PATCH('api/product/' . $one_d->{id}, to_json($update_p));
unless (204 == $ret->responseCode()) {
die t8('Part Description is too long for this Shopware version. It should have lower than 255 characters.')
if $ret->responseContent() =~ m/Diese Zeichenkette ist zu lang. Sie sollte.*255 Zeichen/;
die "Updating part with " . $part->partnumber . " failed: " . $ret->responseContent() unless (204 == $ret->responseCode());
}
$self->_die_on_error($part, $ret) unless (204 == $ret->responseCode());
} else {
# create part
# 1. get the correct tax for this product
Expand Down Expand Up @@ -227,7 +227,7 @@ sub update_part {
$update_p->{price}->[0]->{linked} = \1; # link product variants

$ret = $self->connector->POST('api/product', to_json($update_p));
die "Create for Product " . $part->partnumber . " failed: " . $ret->responseContent() unless (204 == $ret->responseCode());
$self->_die_on_error($part, $ret) unless (204 == $ret->responseCode());
}

# if there are images try to sync this with the shop_part
Expand All @@ -242,6 +242,22 @@ sub update_part {

return 1; # no invalid response code -> success
}

sub _die_on_error {
my ($self, $part, $ret) = @_;

die t8('Part Description is too long for this Shopware version. It should have lower than 255 characters.')
if $ret->responseContent() =~ m/Diese Zeichenkette ist zu lang. Sie sollte.*255 Zeichen/
&& $ret->responseContent() =~ m/description/;
die t8('Part Metatag Title is too long for this Shopware version. It should have lower than 255 characters.')
if $ret->responseContent() =~ m/Diese Zeichenkette ist zu lang. Sie sollte.*255 Zeichen/
&& $ret->responseContent() =~ m/metaTitle/;
die t8('Part Metatag Description is too long for this Shopware version. It should have lower than 255 characters.')
if $ret->responseContent() =~ m/Diese Zeichenkette ist zu lang. Sie sollte.*255 Zeichen/
&& $ret->responseContent() =~ m/metaDescription/;
die "Action for part with " . $part->partnumber . " failed: " . $ret->responseContent();
};

sub sync_all_categories {
my ($self, %params) = @_;

Expand Down
2 changes: 2 additions & 0 deletions locale/de/all
Original file line number Diff line number Diff line change
Expand Up @@ -2809,6 +2809,8 @@ $ ./scripts/installation_check.pl',
'Part Description' => 'Artikelbeschreibung',
'Part Description is too long for this Shopware version. It should have lower than 255 characters.' => 'Artikelbeschreibung enthält mehr als 255 Zeichen. Shopware in dieser Version kann nur Artikelbeschreibungen mit weniger als 255 Zeichen verarbeiten.',
'Part Description missing!' => 'Artikelbezeichnung fehlt!',
'Part Metatag Description is too long for this Shopware version. It should have lower than 255 characters.' => 'Metatag Beschreibung enthält mehr als 255 Zeichen. Shopware in dieser Version kann nur Beschreibungen mit weniger als 255 Zeichen verarbeiten.',
'Part Metatag Title is too long for this Shopware version. It should have lower than 255 characters.' => 'Metatag Titel enthält mehr als 255 Zeichen. Shopware in dieser Version kann nur Titel mit weniger als 255 Zeichen verarbeiten.',
'Part Notes' => 'Bemerkungen',
'Part Number' => 'Artikelnummer',
'Part Number missing!' => 'Artikelnummer fehlt!',
Expand Down
2 changes: 2 additions & 0 deletions locale/en/all
Original file line number Diff line number Diff line change
Expand Up @@ -2808,6 +2808,8 @@ $self->{texts} = {
'Part Description' => '',
'Part Description is too long for this Shopware version. It should have lower than 255 characters.' => '',
'Part Description missing!' => '',
'Part Metatag Description is too long for this Shopware version. It should have lower than 255 characters.' => '',
'Part Metatag Title is too long for this Shopware version. It should have lower than 255 characters.' => '',
'Part Notes' => '',
'Part Number' => '',
'Part Number missing!' => '',
Expand Down

0 comments on commit 88b1a5d

Please sign in to comment.