diff --git a/CHANGELOG.md b/CHANGELOG.md index 17b2074c..4016858c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# 3.1.0 +- Added new Belgium to Netherlands products for shipping and pickup points +- Added an ID/age check option for shipping and pickup points in the Netherlands +- Fixed an issue whereby the pickup point location code was not stored on the order. Affected all 3.0 versions. +- Fixes an issue when changing the shipping method in the administration would always select NL as the sender's country +- Added support for MariaDB versions older than 10.5.2 + - If you've already tried installing the plugin on an older MariaDB version, then take these steps to remove the plugin data before trying to install the new version: + - Remove any database table starting with `postnl_` from the database + - Remove all entries from the `migration` database table where the `class` field starts with `PostNL\Shopware6` + - Optional: Remove the old plugin files first and refresh the plugin listing in the admin + # 3.0.2 - Fix an issue whereby selected delivery dates or pickup points were not stored. - Added delivery date and send date to the admin order detail page again. diff --git a/CHANGELOG_de-DE.md b/CHANGELOG_de-DE.md index 2f964483..8ed4ff47 100644 --- a/CHANGELOG_de-DE.md +++ b/CHANGELOG_de-DE.md @@ -1,3 +1,14 @@ +# 3.1.0 +- Neue Produkte für Belgien zu den Niederlanden für Versand- und Abholstellen hinzugefügt +- Es wurde eine Option zur Überprüfung von ID/Alter für Versand- und Abholstellen in den Niederlanden hinzugefügt. +- Es wurde ein Problem behoben, bei dem der Code der Abholstelle nicht in der Bestellung gespeichert wurde. Dies betraf alle 3.0-Versionen. +- Behebt ein Problem, bei dem beim Ändern der Versandmethode in der Verwaltung immer NL als Land des Absenders ausgewählt wurde +- Unterstützung für MariaDB-Versionen älter als 10.5.2 wurde hinzugefügt. + - Wenn Sie bereits versucht haben, das Plugin auf einer älteren MariaDB-Version zu installieren, führen Sie diese Schritte aus, um die Plugin-Daten zu entfernen, bevor Sie versuchen, die neue Version zu installieren: + - Entfernen Sie alle Datenbanktabellen, die mit `postnl_` beginnen, aus der Datenbank + - Entfernen Sie alle Einträge aus der Datenbanktabelle `migration`, bei denen das Feld `class` mit `PostNL\Shopware6` beginnt + - Optional: Entfernen Sie zuerst die alten Plugin-Dateien und aktualisieren Sie die Plugin-Liste in der Verwaltung + # 3.0.2 - Behebung eines Problems, bei dem ausgewählte Lieferdaten oder Abholpunkte nicht gespeichert wurden. - Das Lieferdatum und das Versanddatum wurden auf der administrativen Bestellungsdetailseite wieder hinzugefügt. diff --git a/CHANGELOG_nl-NL.md b/CHANGELOG_nl-NL.md index 96f91a81..3f241af9 100644 --- a/CHANGELOG_nl-NL.md +++ b/CHANGELOG_nl-NL.md @@ -1,3 +1,14 @@ +# 3.1.0 +- Nieuwe België naar Nederland-producten toegevoegd voor verzend- en afhaalpunten +- Een ID/leeftijdscontroleoptie toegevoegd voor verzend- en afhaalpunten in Nederland +- Probleem verholpen waarbij de locatiecode van het afhaalpunt niet werd opgeslagen in de bestelling. Dit betrof alle 3.0 versies. +- Verhelpt een probleem waarbij bij het wijzigen van de verzendmethode in de administratie altijd NL werd geselecteerd als het land van de afzender +- Ondersteuning toegevoegd voor MariaDB-versies ouder dan 10.5.2 + - Als je al geprobeerd hebt de plugin te installeren op een oudere MariaDB versie, neem dan deze stappen om de plugin gegevens te verwijderen voordat je probeert de nieuwe versie te installeren: + - Verwijder elke database tabel die begint met `postnl_` uit de database + - Verwijder alle items uit de `migratie` database tabel waar het `klasse` veld begint met `PostNL\Shopware6`. + - Optioneel: Verwijder eerst de oude plugin bestanden en ververs de plugin lijst in de admin + # 3.0.2 - Probleem verholpen waarbij geselecteerde afleverdata of afhaalpunten niet werden opgeslagen. - Afleverdatum en verzenddatum weer toegevoegd aan de admin order detailpagina. diff --git a/composer.json b/composer.json index 68226218..15fbb4f0 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "postnl/shopware6", "description": "PostNL", "type": "shopware-platform-plugin", - "version": "3.0.2", + "version": "3.1.0", "license": "proprietary", "authors": [ { diff --git a/makefile b/makefile index f0da388f..95dfb65a 100644 --- a/makefile +++ b/makefile @@ -7,6 +7,7 @@ PLUGIN_NAME=PostNLShopware PLUGIN_VERSION=`php -r 'echo json_decode(file_get_contents("$(PLUGIN_NAME)/composer.json"))->version;'` +RELEASE_DIR=/var/www/html/.plugins/ help: @grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' @@ -94,6 +95,7 @@ release: ## Create a new release @make install @make build @make zip + @make copy-release zip: ## Creates a new ZIP package @php update-composer-require.php --shopware=">=6.5.2 <6.6" --env=prod --admin --storefront @@ -101,3 +103,7 @@ zip: ## Creates a new ZIP package @cd .. && rm -rf $(PLUGIN_NAME)-$(PLUGIN_VERSION).zip @cd .. && zip -qq -r -0 $(PLUGIN_NAME)-$(PLUGIN_VERSION).zip $(PLUGIN_NAME)/ -x@$(PLUGIN_NAME)/zip.exclude.lst @php update-composer-require.php --shopware=">=6.5.2 <6.6" --env=dev --admin --storefront + +copy-release: ## Copies it to the releases directory + @mkdir -p $(RELEASE_DIR)$(PLUGIN_NAME) + @cd .. && cp -f $(PLUGIN_NAME)-$(PLUGIN_VERSION).zip $(RELEASE_DIR)$(PLUGIN_NAME)/$(PLUGIN_NAME)-$(PLUGIN_VERSION).zip diff --git a/src/Controller/Api/ShipmentController.php b/src/Controller/Api/ShipmentController.php index 3c4dad0e..ef32ab3a 100644 --- a/src/Controller/Api/ShipmentController.php +++ b/src/Controller/Api/ShipmentController.php @@ -58,10 +58,12 @@ public function determineZones(QueryDataBag $data, Context $context): JsonRespon { $orderIds = $data->get('orderIds', new QueryDataBag())->all(); - $zones = $this->shipmentFacade->determineZones($orderIds, $context); + $sourceZones = $this->shipmentFacade->determineSourceZones($orderIds, $context); + $destinationZones = $this->shipmentFacade->determineDestinationZones($orderIds, $context); return $this->json([ - 'zones' => $zones, + 'source' => $sourceZones, + 'destination' => $destinationZones, ]); } diff --git a/src/Defaults.php b/src/Defaults.php index 43804b70..502e37a4 100644 --- a/src/Defaults.php +++ b/src/Defaults.php @@ -49,6 +49,9 @@ class Defaults const PRODUCT_SHIPMENT_BE_BE = self::PRODUCT_SHIPMENT_BE_BE_4960; const PRODUCT_PICKUP_BE_BE = self::PRODUCT_PICKUP_BE_BE_4880; + const PRODUCT_SHIPMENT_BE_NL = self::PRODUCT_SHIPMENT_BE_NL_4890; + const PRODUCT_PICKUP_BE_NL = self::PRODUCT_PICKUP_BE_NL_4898; + const PRODUCT_SHIPMENT_BE_EU = self::PRODUCT_SHIPMENT_BE_EU_4907_005_025; const PRODUCT_SHIPMENT_BE_GLOBAL = self::PRODUCT_SHIPMENT_BE_GLOBAL_4909_005_025; //endregion @@ -143,7 +146,7 @@ class Defaults // BE->BE, Verzending, niet bij buren bezorgen, verzekerd const PRODUCT_SHIPMENT_BE_BE_4965 = "76128ef0531645d4a93979f7e58be30f"; - // BE->BE, Pickup,verzekerd + // BE->BE, Pickup, verzekerd const PRODUCT_PICKUP_BE_BE_4878 = "7108d13a1c104ec3a3b0b661c9436186"; // BE->BE, Pickup @@ -234,16 +237,46 @@ class Defaults //endregion //endregion + //region V3.1.0 Identifiers + /** + * V3.1.0 + */ + + //region New BE -> NL productcodes + + // BE->NL, Verzending + const PRODUCT_SHIPMENT_BE_NL_4890 = "45432c40e63f4ec79aa230c0bed4c0e2"; + + // BE->NL, Verzending, handtekening + const PRODUCT_SHIPMENT_BE_NL_4891 = "6014c5955e0c448ab27c37142f0bfdac"; + + // BE->NL, Verzending, niet bij buren bezorgen + const PRODUCT_SHIPMENT_BE_NL_4893 = "be49eed381bc4b7e935a39926273717c"; + + // BE->NL, Verzending, handtekening, niet bij buren bezorgen + const PRODUCT_SHIPMENT_BE_NL_4894 = "47ab691cd2504280b1af6e6e002c94f2"; + + // BE->NL, Verzending, handtekening, retour b.g.g. + const PRODUCT_SHIPMENT_BE_NL_4896 = "dac322ddf7db4e3c95e7ba915b21f15c"; + + // BE->NL, Verzending, verzekerd, handtekening + const PRODUCT_SHIPMENT_BE_NL_4897 = "2cc40e192141468cb57852305596ad37"; + + // BE->NL, Pickup, handtekening + const PRODUCT_PICKUP_BE_NL_4898 = "bc5f4a5e53df412b80600eaa68d7d335"; + //endregion + + //region ID Check products initial + + // NL->NL, Verzending, verzekerd, handtekening + const PRODUCT_SHIPMENT_NL_NL_3438 = "aa67b151850646849464e633d4a14beb"; + + // NL->NL, Pickup, handtekening + const PRODUCT_PICKUP_NL_NL_3571 = "91cca8b821f4413dad3f3133b7b5dffe"; + //endregion + //endregion + //region Placeholder identifiers -// const PLACEHOLDER = "45432c40e63f4ec79aa230c0bed4c0e2"; -// const PLACEHOLDER = "6014c5955e0c448ab27c37142f0bfdac"; -// const PLACEHOLDER = "be49eed381bc4b7e935a39926273717c"; -// const PLACEHOLDER = "47ab691cd2504280b1af6e6e002c94f2"; -// const PLACEHOLDER = "dac322ddf7db4e3c95e7ba915b21f15c"; -// const PLACEHOLDER = "2cc40e192141468cb57852305596ad37"; -// const PLACEHOLDER = "bc5f4a5e53df412b80600eaa68d7d335"; -// const PLACEHOLDER = "aa67b151850646849464e633d4a14beb"; -// const PLACEHOLDER = "91cca8b821f4413dad3f3133b7b5dffe"; // const PLACEHOLDER = "596c345d25684e729909175ed50c9897"; // const PLACEHOLDER = "cbd12ab384534364919140e09f1c77bb"; // const PLACEHOLDER = "01d9979b809b4458b0e9ab16051a3570"; diff --git a/src/Facade/ProductFacade.php b/src/Facade/ProductFacade.php index 093b74b3..fb348695 100644 --- a/src/Facade/ProductFacade.php +++ b/src/Facade/ProductFacade.php @@ -200,7 +200,8 @@ public function selectProduct( $changeSet, $context ); - // Should always only have one. + + // Should have only one, if the combinations are available $filteredProducts = $this->productService->filterProductsByFlags($products, $filters); $product = $filteredProducts->first(); @@ -209,6 +210,15 @@ public function selectProduct( return $product; } + // Combination was not available, try to filter by the change set. Can have multiple + $filteredProducts = $this->productService->filterProductsByChangeSet($products, $changeSet); + + $product = $filteredProducts->first(); + + if ($product instanceof ProductEntity) { + return $product; + } + // TODO Exception throw new \Exception('Could not select product'); } diff --git a/src/Facade/ShipmentFacade.php b/src/Facade/ShipmentFacade.php index 608e544e..49cdc9b7 100644 --- a/src/Facade/ShipmentFacade.php +++ b/src/Facade/ShipmentFacade.php @@ -74,7 +74,28 @@ public function generateBarcodes(array $orderIds, Context $context): array * @return string[] * @throws \Exception */ - public function determineZones(array $orderIds, Context $context): array + public function determineSourceZones(array $orderIds, Context $context): array + { + $sourceZones = []; + + foreach ($orderIds as $orderId) { + $order = $this->orderService->getOrder($orderId, $context); + + $config = $this->configService->getConfiguration($order->getSalesChannelId(), $context); + + $sourceZones[] = $config->getSenderAddress()->getCountrycode(); + } + + return array_values(array_unique($sourceZones)); + } + + /** + * @param string[] $orderIds + * @param Context $context + * @return string[] + * @throws \Exception + */ + public function determineDestinationZones(array $orderIds, Context $context): array { $deliveryZones = []; diff --git a/src/Migration/Migration1674128763RenameOptionTables.php b/src/Migration/Migration1674128763RenameOptionTables.php index 3c6b04ba..4c147b93 100644 --- a/src/Migration/Migration1674128763RenameOptionTables.php +++ b/src/Migration/Migration1674128763RenameOptionTables.php @@ -23,12 +23,22 @@ public function update(Connection $connection): void RENAME TABLE `postnl_product_option_mapping` TO `postnl_product_option_required_mapping`; ALTER TABLE `postnl_option_translation` CHANGE `postnl_product_option_id` `postnl_option_id` BINARY(16) NOT NULL; - ALTER TABLE `postnl_option_translation` RENAME INDEX `fk.postnl_product_option_translation.product_option_id` TO `fk.postnl_option_translation.postnl_option_id`; - ALTER TABLE `postnl_option_translation` RENAME INDEX `fk.postnl_product_option_translation.language_id` TO `fk.postnl_option_translation.language_id`; +-- MariaDB <10.5.2 compatibility +-- ALTER TABLE `postnl_option_translation` RENAME INDEX `fk.postnl_product_option_translation.product_option_id` TO `fk.postnl_option_translation.postnl_option_id`; +-- ALTER TABLE `postnl_option_translation` RENAME INDEX `fk.postnl_product_option_translation.language_id` TO `fk.postnl_option_translation.language_id`; + ALTER TABLE `postnl_option_translation` ADD INDEX `fk.postnl_option_translation.postnl_option_id` (`postnl_option_id`); + ALTER TABLE `postnl_option_translation` ADD INDEX `fk.postnl_option_translation.language_id` (`language_id`); + ALTER TABLE `postnl_option_translation` DROP INDEX `fk.postnl_product_option_translation.product_option_id`; + ALTER TABLE `postnl_option_translation` DROP INDEX `fk.postnl_product_option_translation.language_id`; ALTER TABLE `postnl_product_option_required_mapping` CHANGE `product_option_id` `option_id` BINARY(16) NOT NULL; - ALTER TABLE `postnl_product_option_required_mapping` RENAME INDEX `fk.postnl_product_option_mapping.product_id` TO `fk.postnl_product_option_required_mapping.product_id`; - ALTER TABLE `postnl_product_option_required_mapping` RENAME INDEX `fk.postnl_product_option_mapping.product_option_id` TO `fk.postnl_product_option_required_mapping.option_id`; +-- MariaDB <10.5.2 compatibility +-- ALTER TABLE `postnl_product_option_required_mapping` RENAME INDEX `fk.postnl_product_option_mapping.product_id` TO `fk.postnl_product_option_required_mapping.product_id`; +-- ALTER TABLE `postnl_product_option_required_mapping` RENAME INDEX `fk.postnl_product_option_mapping.product_option_id` TO `fk.postnl_product_option_required_mapping.option_id`; + ALTER TABLE `postnl_product_option_required_mapping` ADD INDEX `fk.postnl_product_option_required_mapping.product_id` (`product_id`); + ALTER TABLE `postnl_product_option_required_mapping` ADD INDEX `fk.postnl_product_option_required_mapping.option_id` (`option_id`); + ALTER TABLE `postnl_product_option_required_mapping` DROP INDEX `fk.postnl_product_option_mapping.product_id`; + ALTER TABLE `postnl_product_option_required_mapping` DROP INDEX `fk.postnl_product_option_mapping.product_option_id`; SQL; $this->execute($connection, $sql); diff --git a/src/Migration/Migration1708424779CreateV3_1_0BelgianProducts.php b/src/Migration/Migration1708424779CreateV3_1_0BelgianProducts.php new file mode 100644 index 00000000..e3740826 --- /dev/null +++ b/src/Migration/Migration1708424779CreateV3_1_0BelgianProducts.php @@ -0,0 +1,131 @@ + Uuid::fromHexToBytes(Defaults::PRODUCT_SHIPMENT_BE_NL_4890), + 'product_code_delivery' => '4890', + 'source_zone' => Zone::BE, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::SHIPMENT, + ProductDefinition::STOR_HOME_ALONE => 0, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => 0, + ProductDefinition::STOR_INSURANCE => 0, + ProductDefinition::STOR_SIGNATURE => 0, + ProductDefinition::STOR_AGE_CHECK => 0, + ProductDefinition::STOR_NOTIFICATION => null, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + [ + 'id' => Uuid::fromHexToBytes(Defaults::PRODUCT_SHIPMENT_BE_NL_4891), + 'product_code_delivery' => '4891', + 'source_zone' => Zone::BE, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::SHIPMENT, + ProductDefinition::STOR_HOME_ALONE => 0, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => 0, + ProductDefinition::STOR_INSURANCE => 0, + ProductDefinition::STOR_SIGNATURE => 1, + ProductDefinition::STOR_AGE_CHECK => 0, + ProductDefinition::STOR_NOTIFICATION => null, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + [ + 'id' => Uuid::fromHexToBytes(Defaults::PRODUCT_SHIPMENT_BE_NL_4893), + 'product_code_delivery' => '4893', + 'source_zone' => Zone::BE, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::SHIPMENT, + ProductDefinition::STOR_HOME_ALONE => 1, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => 0, + ProductDefinition::STOR_INSURANCE => 0, + ProductDefinition::STOR_SIGNATURE => 0, + ProductDefinition::STOR_AGE_CHECK => 0, + ProductDefinition::STOR_NOTIFICATION => null, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + [ + 'id' => Uuid::fromHexToBytes(Defaults::PRODUCT_SHIPMENT_BE_NL_4894), + 'product_code_delivery' => '4894', + 'source_zone' => Zone::BE, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::SHIPMENT, + ProductDefinition::STOR_HOME_ALONE => 1, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => 0, + ProductDefinition::STOR_INSURANCE => 0, + ProductDefinition::STOR_SIGNATURE => 1, + ProductDefinition::STOR_AGE_CHECK => 0, + ProductDefinition::STOR_NOTIFICATION => null, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + [ + 'id' => Uuid::fromHexToBytes(Defaults::PRODUCT_SHIPMENT_BE_NL_4896), + 'product_code_delivery' => '4896', + 'source_zone' => Zone::BE, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::SHIPMENT, + ProductDefinition::STOR_HOME_ALONE => 1, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => 1, + ProductDefinition::STOR_INSURANCE => 0, + ProductDefinition::STOR_SIGNATURE => 1, + ProductDefinition::STOR_AGE_CHECK => 0, + ProductDefinition::STOR_NOTIFICATION => null, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + [ + 'id' => Uuid::fromHexToBytes(Defaults::PRODUCT_SHIPMENT_BE_NL_4897), + 'product_code_delivery' => '4897', + 'source_zone' => Zone::BE, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::SHIPMENT, + ProductDefinition::STOR_HOME_ALONE => 1, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => 0, + ProductDefinition::STOR_INSURANCE => 1, + ProductDefinition::STOR_SIGNATURE => 1, + ProductDefinition::STOR_AGE_CHECK => 0, + ProductDefinition::STOR_NOTIFICATION => null, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + [ + 'id' => Uuid::fromHexToBytes(Defaults::PRODUCT_PICKUP_BE_NL_4898), + 'product_code_delivery' => '4898', + 'source_zone' => Zone::BE, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::PICKUP, + ProductDefinition::STOR_HOME_ALONE => null, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => null, + ProductDefinition::STOR_INSURANCE => 0, + ProductDefinition::STOR_SIGNATURE => 1, + ProductDefinition::STOR_AGE_CHECK => 0, + ProductDefinition::STOR_NOTIFICATION => 0, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + ]; + + $this->insertProducts($connection, $products); + } + + public function updateDestructive(Connection $connection): void + { + // implement update destructive + } +} diff --git a/src/Migration/Migration1708424816CreateV3_1_0IdCheckProducts.php b/src/Migration/Migration1708424816CreateV3_1_0IdCheckProducts.php new file mode 100644 index 00000000..5824c117 --- /dev/null +++ b/src/Migration/Migration1708424816CreateV3_1_0IdCheckProducts.php @@ -0,0 +1,61 @@ + Uuid::fromHexToBytes(Defaults::PRODUCT_SHIPMENT_NL_NL_3438), + 'product_code_delivery' => '3438', + 'source_zone' => Zone::NL, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::SHIPMENT, + ProductDefinition::STOR_HOME_ALONE => 0, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => 0, + ProductDefinition::STOR_INSURANCE => 0, + ProductDefinition::STOR_SIGNATURE => 0, + ProductDefinition::STOR_AGE_CHECK => 1, + ProductDefinition::STOR_NOTIFICATION => null, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + [ + 'id' => Uuid::fromHexToBytes(Defaults::PRODUCT_PICKUP_NL_NL_3571), + 'product_code_delivery' => '3571', + 'source_zone' => Zone::NL, + 'destination_zone' => Zone::NL, + 'delivery_type' => DeliveryType::PICKUP, + ProductDefinition::STOR_HOME_ALONE => null, + ProductDefinition::STOR_RETURN_IF_NOT_HOME => null, + ProductDefinition::STOR_INSURANCE => 0, + ProductDefinition::STOR_SIGNATURE => 0, + ProductDefinition::STOR_AGE_CHECK => 1, + ProductDefinition::STOR_NOTIFICATION => 0, + ProductDefinition::STOR_TRACK_AND_TRACE => null, + ], + ]; + + $this->insertProducts($connection, $products); + } + + public function updateDestructive(Connection $connection): void + { + // implement update destructive + } +} diff --git a/src/Resources/app/administration/src/core/service/api/shipment.service.js b/src/Resources/app/administration/src/core/service/api/shipment.service.js index ad9a40c4..15ed37c9 100644 --- a/src/Resources/app/administration/src/core/service/api/shipment.service.js +++ b/src/Resources/app/administration/src/core/service/api/shipment.service.js @@ -27,7 +27,7 @@ export default class ShipmentService extends PostNlApiService }); } - determineDestinationZones(orderIds) { + determineZones(orderIds) { return this.get('zones', { orderIds: orderIds, }) diff --git a/src/Resources/app/administration/src/core/service/postnl-api.service.js b/src/Resources/app/administration/src/core/service/postnl-api.service.js index bc951b74..4de33f33 100644 --- a/src/Resources/app/administration/src/core/service/postnl-api.service.js +++ b/src/Resources/app/administration/src/core/service/postnl-api.service.js @@ -13,10 +13,16 @@ export default class PostNlApiService extends ApiService { super(httpClient, loginService, endpoint.filter(s => s.trim().length > 0).join('/')); } + getEndpoint(url) { + return [this.getApiBasePath(), url] + .filter(s => s.trim().length > 0) + .join('/') + } + async get(url, data = {}) { return this.httpClient .get( - `_action/${ this.getApiBasePath() }/${ url }?${ stringify(data) }`, + `_action/${ this.getEndpoint(url) }?${ stringify(data) }`, { headers: await this.buildHeaders(), } @@ -28,7 +34,7 @@ export default class PostNlApiService extends ApiService { async post(url, data = {}) { return this.httpClient .post( - `_action/${ this.getApiBasePath() }/${ url }`, + `_action/${ this.getEndpoint(url) }`, JSON.stringify(data), { headers: await this.buildHeaders(), @@ -41,7 +47,7 @@ export default class PostNlApiService extends ApiService { async getBlob(url, data = {}) { return this.httpClient .get( - `_action/${ this.getApiBasePath() }/${ url }?${ stringify(data) }`, + `_action/${ this.getEndpoint(url) }?${ stringify(data) }`, { headers: await this.buildHeaders(), responseType: 'blob', diff --git a/src/Resources/app/administration/src/module/postnl/component/config/product-selection/index.js b/src/Resources/app/administration/src/module/postnl/component/config/product-selection/index.js index f4d1051b..b7b09fff 100644 --- a/src/Resources/app/administration/src/module/postnl/component/config/product-selection/index.js +++ b/src/Resources/app/administration/src/module/postnl/component/config/product-selection/index.js @@ -15,7 +15,11 @@ import './postnl-config-product-selection-pickup-nl-be-default'; import './postnl-config-product-selection-shipment-be-be-default'; import './postnl-config-product-selection-shipment-be-be-alternative'; +import './postnl-config-product-selection-pickup-be-be-default'; + +import './postnl-config-product-selection-shipment-be-nl-default'; +import './postnl-config-product-selection-shipment-be-nl-alternative'; + import './postnl-config-product-selection-shipment-be-eu-default'; import './postnl-config-product-selection-shipment-be-global-default'; -import './postnl-config-product-selection-pickup-be-be-default'; diff --git a/src/Resources/app/administration/src/module/postnl/component/config/product-selection/postnl-config-product-selection-shipment-be-nl-alternative/index.js b/src/Resources/app/administration/src/module/postnl/component/config/product-selection/postnl-config-product-selection-shipment-be-nl-alternative/index.js new file mode 100644 index 00000000..8ebe05a2 --- /dev/null +++ b/src/Resources/app/administration/src/module/postnl/component/config/product-selection/postnl-config-product-selection-shipment-be-nl-alternative/index.js @@ -0,0 +1,15 @@ +const { Component } = Shopware; + +Component.extend('postnl-config-product-selection-shipment-be-nl-alternative', 'postnl-config-product-selection-base', { + + data() { + return { + sourceZone: 'BE', + destinationZone: 'NL', + deliveryType: 'shipment', + + isAlt: true, + defaultIsEnabled: false, + }; + }, +}) diff --git a/src/Resources/app/administration/src/module/postnl/component/config/product-selection/postnl-config-product-selection-shipment-be-nl-default/index.js b/src/Resources/app/administration/src/module/postnl/component/config/product-selection/postnl-config-product-selection-shipment-be-nl-default/index.js new file mode 100644 index 00000000..cb67a071 --- /dev/null +++ b/src/Resources/app/administration/src/module/postnl/component/config/product-selection/postnl-config-product-selection-shipment-be-nl-default/index.js @@ -0,0 +1,12 @@ +const { Component } = Shopware; + +Component.extend('postnl-config-product-selection-shipment-be-nl-default', 'postnl-config-product-selection-base', { + + data() { + return { + sourceZone: 'BE', + destinationZone: 'NL', + deliveryType: 'shipment', + }; + }, +}) diff --git a/src/Resources/app/administration/src/module/postnl/component/postnl-change-shipping-modal/index.js b/src/Resources/app/administration/src/module/postnl/component/postnl-change-shipping-modal/index.js index d715438d..20742f6a 100644 --- a/src/Resources/app/administration/src/module/postnl/component/postnl-change-shipping-modal/index.js +++ b/src/Resources/app/administration/src/module/postnl/component/postnl-change-shipping-modal/index.js @@ -1,9 +1,8 @@ import template from './postnl-change-shipping-modal.html.twig'; // import './postnl-shipping-modal.scss'; -import {object} from '../../../../core/service/util.service'; // eslint-disable-next-line no-undef -const {Component, Mixin,} = Shopware; +const { Component, Mixin, } = Shopware; Component.register('postnl-change-shipping-modal', { template, @@ -25,10 +24,12 @@ Component.register('postnl-change-shipping-modal', { data() { return { + isLoading: false, isProcessing: false, isSuccess: false, - deliveryZones: [], + sourceZones: [], + destinationZones: [], isOverrideProduct: false, overrideProductId: null, @@ -45,8 +46,12 @@ Component.register('postnl-change-shipping-modal', { }, canChangeProduct() { - return this.deliveryZones.length === 1; - } + return this.sourceZones.length === 1 && this.destinationZones.length === 1; + }, + + orderIds() { + return Object.values(this.selection).map(order => order.id) + }, }, created() { @@ -60,7 +65,7 @@ Component.register('postnl-change-shipping-modal', { this.isOverrideProduct = !!this.overrideProductId; } - this.determineZones(); + this.determineZones() }, closeModal() { @@ -70,18 +75,22 @@ Component.register('postnl-change-shipping-modal', { }, determineZones() { - this.ShipmentService - .determineDestinationZones(Object.values(object.map(this.selection, 'id'))) - .then(response => this.deliveryZones = response.zones); + this.isLoading = true; + + return this.ShipmentService + .determineZones(this.orderIds) + .then(({ source, destination }) => { + this.sourceZones = source + this.destinationZones = destination + }) + .finally(() => this.isLoading = false) }, sendShipments() { this.isProcessing = true; - const orderIds = Object.values(this.selection).map(order => order.id); - this.ShipmentService - .changeProducts(orderIds, this.overrideProductId) + .changeProducts(this.orderIds, this.overrideProductId) .finally(() => { this.isProcessing = false; this.isSuccess = true; diff --git a/src/Resources/app/administration/src/module/postnl/component/postnl-change-shipping-modal/postnl-change-shipping-modal.html.twig b/src/Resources/app/administration/src/module/postnl/component/postnl-change-shipping-modal/postnl-change-shipping-modal.html.twig index c8b45347..7d81a041 100644 --- a/src/Resources/app/administration/src/module/postnl/component/postnl-change-shipping-modal/postnl-change-shipping-modal.html.twig +++ b/src/Resources/app/administration/src/module/postnl/component/postnl-change-shipping-modal/postnl-change-shipping-modal.html.twig @@ -1,31 +1,44 @@ - - + + diff --git a/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/index.js b/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/index.js index 46a72909..b02ec41d 100644 --- a/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/index.js +++ b/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/index.js @@ -273,7 +273,7 @@ Component.register('postnl-product-selection', { const flags = object.map(this.flags, 'selected'); - this.ProductSelectionService + return this.ProductSelectionService .selectProduct( this.sourceZone, this.destinationZone, @@ -281,7 +281,9 @@ Component.register('postnl-product-selection', { flags, this.changeSet ) - .then(result => this.product = result.product) + .then(result => result.product) + .catch(this.getDefaultProduct) + .then(product => this.product = product) .finally(() => { this.isLoading = false; }) diff --git a/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/postnl-product-selection.html.twig b/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/postnl-product-selection.html.twig index c4b625f8..f163414f 100644 --- a/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/postnl-product-selection.html.twig +++ b/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/postnl-product-selection.html.twig @@ -1,8 +1,12 @@ - + + {{ product.name }} @@ -15,13 +19,20 @@ @change="onChangeDeliveryType" /> - + + + + + - + diff --git a/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/postnl-product-selection.scss b/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/postnl-product-selection.scss index 5209a355..2294c9ae 100644 --- a/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/postnl-product-selection.scss +++ b/src/Resources/app/administration/src/module/postnl/component/postnl-product-selection/postnl-product-selection.scss @@ -3,6 +3,14 @@ .sw-label { margin-right: 0; - margin-bottom: 16px; + margin-bottom: 1rem; + } + + .sw-field--switch { + margin: 0; + } + + .sw-help-text { + margin-top: 0.5rem; } } diff --git a/src/Resources/app/administration/src/module/postnl/snippet/de-DE.json b/src/Resources/app/administration/src/module/postnl/snippet/de-DE.json index 76145378..7e350d1f 100644 --- a/src/Resources/app/administration/src/module/postnl/snippet/de-DE.json +++ b/src/Resources/app/administration/src/module/postnl/snippet/de-DE.json @@ -74,7 +74,8 @@ "headerAltActiveDebug": "[{code}] {name} - ab {amount}", "headerAltDisabled": "Deaktiviert", "enableAltProduct": "Alternatives Produkt aktivieren", - "altProductAmount": "Alternatives Produkt verwenden ab" + "altProductAmount": "Alternatives Produkt verwenden ab", + "combinationNotice": "Es sind nicht alle Kombinationen möglich. Das am besten geeignete Produkt wird auf der Grundlage Ihrer letzten Auswahl ausgewählt." } }, "order": { diff --git a/src/Resources/app/administration/src/module/postnl/snippet/en-GB.json b/src/Resources/app/administration/src/module/postnl/snippet/en-GB.json index fb7d35de..a3bfcca4 100644 --- a/src/Resources/app/administration/src/module/postnl/snippet/en-GB.json +++ b/src/Resources/app/administration/src/module/postnl/snippet/en-GB.json @@ -74,7 +74,8 @@ "headerAltActiveDebug": "[{code}] {name} - from {amount}", "headerAltDisabled": "Disabled", "enableAltProduct": "Enable alternative product", - "altProductAmount": "Use alternative product from" + "altProductAmount": "Use alternative product from", + "combinationNotice": "Not all combinations are possible. The most appropriate product will be selected based on your latest selection." } }, "order": { diff --git a/src/Resources/app/administration/src/module/postnl/snippet/nl-NL.json b/src/Resources/app/administration/src/module/postnl/snippet/nl-NL.json index ac3dd96d..dbe68f3d 100644 --- a/src/Resources/app/administration/src/module/postnl/snippet/nl-NL.json +++ b/src/Resources/app/administration/src/module/postnl/snippet/nl-NL.json @@ -74,7 +74,8 @@ "headerAltActiveDebug": "[{code}] {name} - vanaf {amount}", "headerAltDisabled": "Niet actief", "enableAltProduct": "Schakel alternatief product in", - "altProductAmount": "Alternatief product gebruiken vanaf" + "altProductAmount": "Alternatief product gebruiken vanaf", + "combinationNotice": "Niet alle combinaties zijn mogelijk. Het meest geschikte product wordt geselecteerd op basis van je laatste selectie." } }, "order": { diff --git a/src/Resources/config/config.xml b/src/Resources/config/config.xml index c680c6fb..77af8583 100644 --- a/src/Resources/config/config.xml +++ b/src/Resources/config/config.xml @@ -155,6 +155,21 @@ + + + productShipmentBeNlDefault + + + + + + + productShipmentBeNlAlternative + + + + + sendToEU diff --git a/src/Service/PostNL/Builder/ShipmentBuilder.php b/src/Service/PostNL/Builder/ShipmentBuilder.php index 267b6015..8f18298f 100644 --- a/src/Service/PostNL/Builder/ShipmentBuilder.php +++ b/src/Service/PostNL/Builder/ShipmentBuilder.php @@ -254,7 +254,7 @@ public function buildPickupLocationAddress(OrderEntity $order, Context $context) $apiClient = $this->apiFactory->createClientForSalesChannel($order->getSalesChannelId(), $context); - $locationResult = $apiClient->getLocation(new GetLocation($orderAttributes->getPickupPointLocationCode())); + $locationResult = $apiClient->getLocation(new GetLocation((string)$orderAttributes->getPickupPointLocationCode())); $pickupPoint = $locationResult->getGetLocationsResult()->getResponseLocation()[0]; $address = $pickupPoint->getAddress()->setAddressType('09'); diff --git a/src/Service/PostNL/CustomFieldHelper.php b/src/Service/PostNL/CustomFieldHelper.php new file mode 100644 index 00000000..c053529a --- /dev/null +++ b/src/Service/PostNL/CustomFieldHelper.php @@ -0,0 +1,22 @@ + Zone::EU, // Netherlands + 'NL' => Zone::NL, // Netherlands 'BE' => Zone::BE, // Belgium 'AT' => Zone::EU, // Austria 'BG' => Zone::EU, // Bulgaria diff --git a/src/Service/PostNL/Product/ProductService.php b/src/Service/PostNL/Product/ProductService.php index 32890e2f..1cfad060 100644 --- a/src/Service/PostNL/Product/ProductService.php +++ b/src/Service/PostNL/Product/ProductService.php @@ -232,10 +232,6 @@ public function buildFlagStructs( $structs = []; foreach(ProductDefinition::ALL_FLAGS as $flag) { - if($flag === ProductDefinition::PROP_AGE_CHECK) { - continue; - } - $availableValues = $products->reduceToProperty($flag); /** @@ -256,7 +252,7 @@ public function buildFlagStructs( $structs[$flag] = new ProductFlagStruct( $flag, $isVisible, - $isDisabled, + false,//$isDisabled, $isSelected ); } @@ -395,6 +391,16 @@ public function getDefaultProductId( break; case Zone::BE: switch($destinationZone) { + case Zone::NL: + switch ($deliveryType) { + case DeliveryType::SHIPMENT: + $defaultProductId = Defaults::PRODUCT_SHIPMENT_BE_NL; + break; + case DeliveryType::PICKUP: + $defaultProductId = Defaults::PRODUCT_PICKUP_BE_NL; + break; + } + break; case Zone::BE: switch ($deliveryType) { case DeliveryType::SHIPMENT: @@ -471,13 +477,13 @@ private function requiredFlags( ProductDefinition::PROP_RETURN_IF_NOT_HOME, ProductDefinition::PROP_INSURANCE, ProductDefinition::PROP_SIGNATURE, -// ProductDefinition::PROP_AGE_CHECK, + ProductDefinition::PROP_AGE_CHECK, ]; case DeliveryType::PICKUP: return [ ProductDefinition::PROP_INSURANCE, ProductDefinition::PROP_SIGNATURE, -// ProductDefinition::PROP_AGE_CHECK, + ProductDefinition::PROP_AGE_CHECK, ProductDefinition::PROP_NOTIFICATION, ]; case DeliveryType::MAILBOX: diff --git a/src/Struct/Config/ConfigStruct.php b/src/Struct/Config/ConfigStruct.php index c070dc0b..0eded3fe 100644 --- a/src/Struct/Config/ConfigStruct.php +++ b/src/Struct/Config/ConfigStruct.php @@ -90,6 +90,16 @@ class ConfigStruct extends AttributeStruct */ protected $productPickupBeBeDefault; + /** + * @var ProductSelectionStruct + */ + protected $productShipmentBeNlDefault; + + /** + * @var ProductSelectionStruct + */ + protected $productShipmentBeNlAlternative; + //==================================================================================================== /** @@ -327,6 +337,16 @@ public function getProductPickupBeBeDefault(): ProductSelectionStruct return $this->productPickupBeBeDefault; } + public function getProductShipmentBeNlDefault(): ProductSelectionStruct + { + return $this->productShipmentBeNlDefault; + } + + public function getProductShipmentBeNlAlternative(): ProductSelectionStruct + { + return $this->productShipmentBeNlAlternative; + } + //========================================================================================================= /** diff --git a/src/Subscriber/ConversionSubscriber.php b/src/Subscriber/ConversionSubscriber.php index 96a65bf5..b410ea69 100644 --- a/src/Subscriber/ConversionSubscriber.php +++ b/src/Subscriber/ConversionSubscriber.php @@ -9,6 +9,7 @@ use Firstred\PostNL\Exception\InvalidArgumentException; use PostNL\Shopware6\Defaults; use PostNL\Shopware6\Service\Attribute\Factory\AttributeFactory; +use PostNL\Shopware6\Service\PostNL\CustomFieldHelper; use PostNL\Shopware6\Service\PostNL\Delivery\DeliveryType; use PostNL\Shopware6\Service\PostNL\Delivery\Zone\ZoneService; use PostNL\Shopware6\Service\PostNL\Factory\ApiFactory; @@ -107,6 +108,7 @@ public static function getSubscribedEvents(): array ['addSendDate', 600], ['addDeliveryTypeData', 100], ['addPickupPointAddress', 100], + ['addTypeCodeToAddresses', 200], ], ]; } @@ -200,12 +202,11 @@ public function addSendDate(CartConvertedEvent $event) $sentDateTime->setTime(...$cutOffTimeParts); $convertedCart = $event->getConvertedCart(); - $convertedCart['customFields'][Defaults::CUSTOM_FIELDS_KEY] = array_merge( - $convertedCart['customFields'][Defaults::CUSTOM_FIELDS_KEY] ?? [], - [ - Defaults::CUSTOM_FIELDS_SENT_DATE_KEY => $sentDateTime->format(DATE_ATOM), - ] - ); + + CustomFieldHelper::merge($convertedCart, [ + Defaults::CUSTOM_FIELDS_SENT_DATE_KEY => $sentDateTime->format(DATE_ATOM), + ]); + $event->setConvertedCart($convertedCart); } @@ -286,12 +287,7 @@ public function addPostNLProductId(CartConvertedEvent $event) ); $convertedCart = $event->getConvertedCart(); - $convertedCart['customFields'][Defaults::CUSTOM_FIELDS_KEY] = array_merge( - $convertedCart['customFields'][Defaults::CUSTOM_FIELDS_KEY] ?? [], - [ - 'productId' => $productId, - ] - ); + CustomFieldHelper::merge($convertedCart, ['productId' => $productId]); $event->setConvertedCart($convertedCart); } @@ -376,12 +372,9 @@ public function addDeliveryTypeData(CartConvertedEvent $event) $data = $cart->getExtensionOfType(CartService::EXTENSION, ArrayStruct::class); $convertedCart = $event->getConvertedCart(); - $convertedCart['customFields'][Defaults::CUSTOM_FIELDS_KEY] = array_merge_recursive( - $convertedCart['customFields'][Defaults::CUSTOM_FIELDS_KEY] ?? [], - [ - Defaults::CUSTOM_FIELDS_DELIVERY_DATE_KEY => $data->get(Defaults::CUSTOM_FIELDS_DELIVERY_DATE_KEY)->format(DATE_ATOM) - ] - ); + CustomFieldHelper::merge($convertedCart, [ + Defaults::CUSTOM_FIELDS_DELIVERY_DATE_KEY => $data->get(Defaults::CUSTOM_FIELDS_DELIVERY_DATE_KEY)->format(DATE_ATOM) + ]); $event->setConvertedCart($convertedCart); } @@ -397,42 +390,54 @@ public function addPickupPointAddress(CartConvertedEvent $event) return; } - if (is_null($attributes->getDeliveryType())) { + if ($attributes->getDeliveryType() !== DeliveryType::PICKUP) { return; } /** @var ArrayStruct $cartData */ $cartData = $cart->getExtensionOfType(CartService::EXTENSION, ArrayStruct::class); + if(!$cartData->has('pickupPointLocationCode')) { + return; + } + + $locationCode = $cartData->get('pickupPointLocationCode'); + $convertedCart = $event->getConvertedCart(); + CustomFieldHelper::merge($convertedCart, ['pickupPointLocationCode' => $locationCode]); $convertedCart = $this->setAddresses($convertedCart); + $pickupPoint = $this->getPickupPoint($locationCode, $event->getSalesChannelContext()); - if ($attributes->getDeliveryType() === DeliveryType::PICKUP && $cartData->has('pickupPointLocationCode')) { - $pickupPoint = $this->getPickupPoint( - $cartData->get('pickupPointLocationCode'), - $event->getSalesChannelContext() - ); - - $convertedCart = $this->setPickupPointAsDeliveryAddresses($convertedCart, $pickupPoint, $event->getContext()); - } + $convertedCart = $this->setPickupPointAsDeliveryAddresses($convertedCart, $pickupPoint, $event->getContext()); $event->setConvertedCart($convertedCart); } - protected function setAddresses(array $convertedCart): array + public function addTypeCodeToAddresses(CartConvertedEvent $event) { - $shippingAddresses = array_column($convertedCart['deliveries'], 'shippingOrderAddress'); + $convertedCart = $event->getConvertedCart(); - $addresses = array_map(function (array $shippingAddress) { - $shippingAddress['customFields'] = array_merge_recursive($shippingAddress['customFields'] ?? [], [ - Defaults::CUSTOM_FIELDS_KEY => [ - 'addressType' => '01', - ], + foreach($convertedCart['deliveries'] as $i => $delivery) { + CustomFieldHelper::merge($convertedCart['deliveries'][$i]['shippingOrderAddress'], [ + 'addressType' => '01', ]); + } - return $shippingAddress; - }, $shippingAddresses); + if (array_key_exists('addresses', $convertedCart)) { + foreach ($convertedCart['addresses'] as $i => $existingAddress) { + CustomFieldHelper::merge($convertedCart['addresses'][$i], [ + 'addressType' => '01', + ]); + } + } + + $event->setConvertedCart($convertedCart); + } + + protected function setAddresses(array $convertedCart): array + { + $addresses = array_column($convertedCart['deliveries'], 'shippingOrderAddress'); if (array_key_exists('addresses', $convertedCart)) { foreach ($convertedCart['addresses'] as $existingAddress) { @@ -441,6 +446,10 @@ protected function setAddresses(array $convertedCart): array } foreach ($convertedCart['deliveries'] as &$delivery) { + if(!array_key_exists('shippingOrderAddress', $delivery)) { + continue; + } + $delivery['shippingOrderAddressId'] = $delivery['shippingOrderAddress']['id']; unset($delivery['shippingOrderAddress']); }