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..992b9a517c 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 t8("Action for part #1 failed: #2", $part->partnumber, $ret->responseContent()); +}; + sub sync_all_categories { my ($self, %params) = @_; diff --git a/locale/de/all b/locale/de/all index 0a1047eb58..7818210bb2 100755 --- a/locale/de/all +++ b/locale/de/all @@ -174,6 +174,7 @@ $self->{texts} = { 'Accrual' => 'Soll-Versteuerung', 'Accrual accounting' => 'Soll-Versteuerung', 'Action' => 'Aktion', + 'Action for part #1 failed: #2' => 'Aktion für Artikel #1 ist fehlgeschlagen: #2', 'Actions' => 'Aktionen', 'Active' => 'Aktiv', 'Active shops:' => 'Webshops aktiv', @@ -2809,6 +2810,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..50433ddf8e 100755 --- a/locale/en/all +++ b/locale/en/all @@ -174,6 +174,7 @@ $self->{texts} = { 'Accrual' => '', 'Accrual accounting' => '', 'Action' => '', + 'Action for part #1 failed: #2' => '', 'Actions' => '', 'Active' => '', 'Active shops:' => '', @@ -2808,6 +2809,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!' => '',