From 6feaa03b8edea803dae54b6af1b44b09c3875b15 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Fri, 6 Oct 2023 22:25:04 +0200 Subject: [PATCH 1/5] Shopware: Shopware TaxId can be defined in config (e.g. if multiple countries with different tax rates and a different default values are used) --- www/pages/shopimporter_shopware6.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/www/pages/shopimporter_shopware6.php b/www/pages/shopimporter_shopware6.php index 87f8ed0c..3d639e1b 100644 --- a/www/pages/shopimporter_shopware6.php +++ b/www/pages/shopimporter_shopware6.php @@ -38,6 +38,9 @@ class Shopimporter_Shopware6 extends ShopimporterBase public $propertyOption; public $shopwareDefaultSalesChannel; public $shopwareMediaFolder; + + private $normalTaxId; + private $reducedTaxId; public $protocol; /** @var bool */ @@ -586,6 +589,8 @@ class Shopimporter_Shopware6 extends ShopimporterBase $this->propertyOption = $einstellungen['felder']['shopwarePropertyOption']; $this->shopwareDefaultSalesChannel = $einstellungen['felder']['shopwareDefaultSalesChannel']; $this->shopwareMediaFolder = $einstellungen['felder']['shopwareMediaFolder']; + $this->normalTaxId = $einstellungen['felder']['normalTaxId']; + $this->reducedTaxId = $einstellungen['felder']['reducedTaxId']; $query = sprintf('SELECT `steuerfreilieferlandexport` FROM `shopexport` WHERE `id` = %d', $this->shopid); $this->taxationByDestinationCountry = !empty($this->app->DB->Select($query)); @@ -669,6 +674,16 @@ class Shopimporter_Shopware6 extends ShopimporterBase 'size' => 40, 'default' => 'Product Media' ], + 'normalTaxId' => [ + 'typ' => 'text', + 'bezeichnung' => '{|TaxId für Steuersatz "normal"|}', + 'size' => 40, + ], + 'reducedTaxId' => [ + 'typ' => 'text', + 'bezeichnung' => '{|TaxId für Steuersatz "ermäßigt"|}', + 'size' => 40, + ], 'statesToFetch' => [ 'typ' => 'text', 'bezeichnung' => '{|Abzuholender Bestellstatus|}:', @@ -927,7 +942,12 @@ class Shopimporter_Shopware6 extends ShopimporterBase $quantity = $this->getCorrectedStockFromAvailable($active, (int)$quantity, $articleInfo); $taxRate = (float)$article['steuersatz']; - $taxId = $this->getTaxIdByRate($taxRate); + if (!empty($this->normalTaxId) && $article['umsatzsteuer'] == 'normal') + $taxId = $this->normalTaxId; + else if (!empty($this->reducedTaxId) && $article['umsatzsteuer'] == 'ermäßigt') + $taxId = $this->reducedTaxId; + else + $taxId = $this->getTaxIdByRate($taxRate); $mediaToAdd = $this->mediaToExport($article, $articleIdShopware); From 9eb958a1a6e6cd689265405c31e46bdb59d480c3 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sat, 7 Oct 2023 23:23:17 +0200 Subject: [PATCH 2/5] Shopware6: apply taxId on variants as well and small bug fixes (maybe for PHP8.1) --- www/pages/shopimporter_shopware6.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/www/pages/shopimporter_shopware6.php b/www/pages/shopimporter_shopware6.php index 3d639e1b..d69101bc 100644 --- a/www/pages/shopimporter_shopware6.php +++ b/www/pages/shopimporter_shopware6.php @@ -2725,7 +2725,7 @@ class Shopimporter_Shopware6 extends ShopimporterBase } foreach ($internalPropertyGroupValues as $internalPropertyGroupValue => $valueNotNeeded) { - if (!array_key_exists($internalPropertyGroupValue, $internalGroupPropertiesToShopwareId[$propertyGroupName])) { + if (!array_key_exists($internalPropertyGroupValue, $internalGroupPropertiesToShopwareId[$propertyGroupName] ?? [])) { $newOptionData = [ 'name' => (string)$internalPropertyGroupValue ]; @@ -2798,6 +2798,13 @@ class Shopimporter_Shopware6 extends ShopimporterBase $isCloseOut = true; } + if ($variant['umsatzsteuer'] == 'normal' && !empty($this->normalTaxId)) + $taxId = $this->normalTaxId; + else if ($variant['umsatzsteuer'] == 'ermäßigt' && !empty($this->reducedTaxId)) + $taxId = $this->reducedTaxId; + else + $taxId = $this->getTaxIdByRate($variant['steuersatz']); + $variantProductData = [ 'active' => $active, 'isCloseout' => $isCloseOut, @@ -2820,7 +2827,7 @@ class Shopimporter_Shopware6 extends ShopimporterBase ], 'stock' => (int)$stock, 'ean' => null, - 'taxId' => $this->getTaxIdByRate($variant['steuersatz']), + 'taxId' => $taxId, ]; if(!empty($weight)){ $variantProductData['weight'] = $weight; @@ -2837,7 +2844,7 @@ class Shopimporter_Shopware6 extends ShopimporterBase foreach ($internalVariantMatrixData as $expression) { if (!in_array( $internalGroupPropertiesToShopwareId[$expression['name']][$expression['values']], - $existingCombinationsByNumber[$productNumber]['options'], + $existingCombinationsByNumber[$productNumber]['options'] ?? [], false)) { $renewVariant = true; } else { From 85c699f5ee2fe6a46ff10a0eeb8a1d4226ef6656 Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Sat, 7 Oct 2023 23:34:18 +0200 Subject: [PATCH 3/5] Shopware6: pass through "umsatzsteuer" for variants, fix "ermaessigt" --- www/lib/class.remote.php | 2 +- www/pages/shopimporter_shopware6.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/www/lib/class.remote.php b/www/lib/class.remote.php index 18000c0f..b542d48b 100644 --- a/www/lib/class.remote.php +++ b/www/lib/class.remote.php @@ -1892,7 +1892,7 @@ class Remote 'altersfreigabe' => $eigenschaft['altersfreigabe'], 'ean' => $eigenschaft['ean'], 'lag' => $matrixStock, 'pseudolager' => $matrixPseudoStorage, 'pseudopreis' => $eigenschaft['pseudopreis'], - 'restmenge' => $eigenschaft['restmenge'], 'steuersatz' => ($steuer - 1) * 100, + 'restmenge' => $eigenschaft['restmenge'], 'steuersatz' => ($steuer - 1) * 100, 'umsatzsteuer' => $eigenschaft['umsatzsteuer'], 'bruttopreis' => $eigenschaft['preis'] * $steuer, 'inaktiv' => $eigenschaft['inaktiv'], 'name_de' => $eigenschaft['name_de'], 'name_en' => $eigenschaft['name_en'], 'uebersicht_de' => $eigenschaft['uebersicht_de'], 'uebersicht_en' => $eigenschaft['uebersicht_en']); diff --git a/www/pages/shopimporter_shopware6.php b/www/pages/shopimporter_shopware6.php index d69101bc..57680394 100644 --- a/www/pages/shopimporter_shopware6.php +++ b/www/pages/shopimporter_shopware6.php @@ -944,7 +944,7 @@ class Shopimporter_Shopware6 extends ShopimporterBase if (!empty($this->normalTaxId) && $article['umsatzsteuer'] == 'normal') $taxId = $this->normalTaxId; - else if (!empty($this->reducedTaxId) && $article['umsatzsteuer'] == 'ermäßigt') + else if (!empty($this->reducedTaxId) && $article['umsatzsteuer'] == 'ermaessigt') $taxId = $this->reducedTaxId; else $taxId = $this->getTaxIdByRate($taxRate); @@ -2800,7 +2800,7 @@ class Shopimporter_Shopware6 extends ShopimporterBase if ($variant['umsatzsteuer'] == 'normal' && !empty($this->normalTaxId)) $taxId = $this->normalTaxId; - else if ($variant['umsatzsteuer'] == 'ermäßigt' && !empty($this->reducedTaxId)) + else if ($variant['umsatzsteuer'] == 'ermaessigt' && !empty($this->reducedTaxId)) $taxId = $this->reducedTaxId; else $taxId = $this->getTaxIdByRate($variant['steuersatz']); From d39f9bb2fefc1eaf2c9f57fd1a43676ab63e0e5a Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Mon, 9 Oct 2023 23:32:49 +0200 Subject: [PATCH 4/5] Shopware6: improvements and fixed regarding property-groups --- www/pages/shopimporter_shopware6.php | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) diff --git a/www/pages/shopimporter_shopware6.php b/www/pages/shopimporter_shopware6.php index 57680394..8496872a 100644 --- a/www/pages/shopimporter_shopware6.php +++ b/www/pages/shopimporter_shopware6.php @@ -1372,8 +1372,7 @@ class Shopimporter_Shopware6 extends ShopimporterBase */ protected function mediaToExport($internalArticleData, $articleIdShopware) { - $mediaToAdd = [ - ]; + $mediaToAdd = []; if (empty($internalArticleData['Dateien'])) { return $mediaToAdd; @@ -1846,7 +1845,6 @@ class Shopimporter_Shopware6 extends ShopimporterBase protected function createPropertyOption($propertyGroupId, $propertyOptionName): ?string { $propertyOptionData = [ - 'id' => '', 'name' => $propertyOptionName ]; $createdPropertyOption = $this->shopwareRequest( @@ -1901,13 +1899,7 @@ class Shopimporter_Shopware6 extends ShopimporterBase if (empty($countryIsoToPropertyTranslation['DE'])) { continue; } - $propertyGroupId = ''; - if (array_key_exists($propertyDefaultName, $this->knownPropertyGroupIds)) { - $propertyGroupId = $this->knownPropertyGroupIds[$propertyDefaultName]; - } - if (empty($propertyGroupId)) { - $propertyGroupId = $this->getPropertyGroupId($propertyDefaultName); - } + $propertyGroupId = $this->getPropertyGroupId($propertyDefaultName); if (empty($propertyGroupId)) { $propertyGroupId = $this->createPropertyGroup($propertyDefaultName); } @@ -2684,15 +2676,10 @@ class Shopimporter_Shopware6 extends ShopimporterBase if (empty($article['matrix_varianten']) || empty($articleIdShopware)) { return false; } + $headerInformation = ['sw-language-id: ' . $languageId]; $internalGroupPropertiesToShopwareId = []; foreach ($article['matrix_varianten']['gruppen'] as $propertyGroupName => $internalPropertyGroupValues) { - $propertyGroupId = ''; - if (array_key_exists($propertyGroupName, $this->knownPropertyGroupIds)) { - $propertyGroupId = $this->knownPropertyGroupIds[$propertyGroupName]; - } - if (empty($propertyGroupId)) { - $propertyGroupId = $this->getPropertyGroupId($propertyGroupName); - } + $propertyGroupId = $this->getPropertyGroupId($propertyGroupName); if (empty($propertyGroupId)) { $propertyGroupId = $this->createPropertyGroup($propertyGroupName); } @@ -2713,8 +2700,6 @@ class Shopimporter_Shopware6 extends ShopimporterBase } } - $languageId = $this->getLanguageIdByCountryIso('DE'); - $headerInformation = ['sw-language-id: ' . $languageId]; $shopwarePropertyGroupOptions = $this->shopwareRequest( 'GET', 'property-group/' . $propertyGroupId . '/options?limit=100', From 10c077006d6a03a96bb6b20e40af6b8d072d516a Mon Sep 17 00:00:00 2001 From: Andreas Palm Date: Fri, 13 Oct 2023 22:55:06 +0200 Subject: [PATCH 5/5] Shopware6: fix extended Prices --- .../Shopware6/Client/Shopware6Client.php | 2 ++ classes/Modules/Shopware6/Data/PriceData.php | 24 ++++++++++++++++++- www/pages/shopimporter_shopware6.php | 23 +++++++++++------- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/classes/Modules/Shopware6/Client/Shopware6Client.php b/classes/Modules/Shopware6/Client/Shopware6Client.php index a7b3eed3..5b9eb20d 100644 --- a/classes/Modules/Shopware6/Client/Shopware6Client.php +++ b/classes/Modules/Shopware6/Client/Shopware6Client.php @@ -129,6 +129,8 @@ final class Shopware6Client ], ], ]; + if ($priceData->getEndingQuantity() > 0) + $data['quantityEnd'] = $priceData->getEndingQuantity(); return $this->request( 'POST', diff --git a/classes/Modules/Shopware6/Data/PriceData.php b/classes/Modules/Shopware6/Data/PriceData.php index 5e997bfd..3a2e2719 100644 --- a/classes/Modules/Shopware6/Data/PriceData.php +++ b/classes/Modules/Shopware6/Data/PriceData.php @@ -8,6 +8,8 @@ class PriceData { /** @var int */ protected $startingQuantity; + /** @var int|null */ + protected $endingQuantity; /** @var float */ protected $net; /** @var float */ @@ -26,13 +28,14 @@ class PriceData * @param $currency * @param $groupName */ - public function __construct(int $startingQuantity, float $net, float $gross, string $currency, string $groupName) + public function __construct(int $startingQuantity, float $net, float $gross, string $currency, string $groupName, int $endingQuantity = null) { $this->startingQuantity = $startingQuantity; $this->net = $net; $this->gross = $gross; $this->currency = $currency; $this->groupName = $groupName; + $this->endingQuantity = $endingQuantity; } /** @@ -95,6 +98,25 @@ class PriceData return $this; } + /** + * @return int|null + */ + public function getEndingQuantity(): int|null + { + return $this->endingQuantity; + } + + /** + * @param int $endingQuantity + * @return PriceData + */ + public function setEndingQuantity(int $endingQuantity): PriceData + { + $this->endingQuantity = $endingQuantity; + + return $this; + } + /** * @return float */ diff --git a/www/pages/shopimporter_shopware6.php b/www/pages/shopimporter_shopware6.php index 8496872a..61872a2e 100644 --- a/www/pages/shopimporter_shopware6.php +++ b/www/pages/shopimporter_shopware6.php @@ -2972,14 +2972,21 @@ class Shopimporter_Shopware6 extends ShopimporterBase * @return PriceData[] */ protected function getPricesFromArray($priceArray): array{ - return array_map(static function($price){ - return new PriceData( - (int)$price['ab_menge'], - (float)$price['preis'], - (float)$price['bruttopreis'], - $price['waehrung'], - $price['gruppeextern'] ?? '') ; - },$priceArray); + $c = count($priceArray); + $result = []; + for ($i = 0; $i < $c; $i++) { + $end = null; + if ($i+1 < $c && ($priceArray[$i+1]['gruppeextern'] ?? '') == ($priceArray[$i]['gruppeextern'] ?? '')) + $end = (int)$priceArray[$i+1]['ab_menge'] - 1; + $result[] = new PriceData( + (int)$priceArray[$i]['ab_menge'], + (float)$priceArray[$i]['preis'], + (float)$priceArray[$i]['bruttopreis'], + $priceArray[$i]['waehrung'], + $priceArray[$i]['gruppeextern'] ?? '', + $end); + } + return $result; } /**