From 88b1a5d4e6fd03ffe9e329ccaa445fb56ec43da0 Mon Sep 17 00:00:00 2001 From: Tamino Steinert Date: Tue, 22 Oct 2024 10:53:53 +0200 Subject: [PATCH] =?UTF-8?q?Shopware6:=20Matatags=20(Titel,=20Beschreibung,?= =?UTF-8?q?=20Keywords)=20in=20Shop=20=C3=BCbernehmen?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SL/Controller/ShopPart.pm | 9 +++++++++ SL/ShopConnector/Shopware6.pm | 28 ++++++++++++++++++++++------ locale/de/all | 2 ++ locale/en/all | 2 ++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/SL/Controller/ShopPart.pm b/SL/Controller/ShopPart.pm index 6ab65076c7..23b542c2c2 100644 --- a/SL/Controller/ShopPart.pm +++ b/SL/Controller/ShopPart.pm @@ -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; diff --git a/SL/ShopConnector/Shopware6.pm b/SL/ShopConnector/Shopware6.pm index cbf70574ab..c9f48c4046 100644 --- a/SL/ShopConnector/Shopware6.pm +++ b/SL/ShopConnector/Shopware6.pm @@ -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' } ], @@ -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 @@ -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 @@ -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) = @_; diff --git a/locale/de/all b/locale/de/all index 0a1047eb58..48e503ccce 100755 --- a/locale/de/all +++ b/locale/de/all @@ -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!', diff --git a/locale/en/all b/locale/en/all index 489def3a4f..68ea2aa6e6 100755 --- a/locale/en/all +++ b/locale/en/all @@ -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!' => '',