From b223ac71e5a99630fe12d98446b0c3aa1d86f1c3 Mon Sep 17 00:00:00 2001 From: Joeri van Veen Date: Thu, 14 Nov 2024 17:31:21 +0100 Subject: [PATCH] feat(carriers): add ups shipping options (#873) --- Adapter/ShipmentOptionsFromAdapter.php | 1 + Block/Sales/NewShipmentForm.php | 8 +- Helper/Data.php | 8 ++ Helper/ShipmentOptions.php | 9 ++ Model/Quote/Checkout.php | 8 ++ Model/Sales/MagentoCollection.php | 1 + Model/Sales/TrackTraceHolder.php | 1 + Model/Source/DefaultOptions.php | 2 +- composer.json | 2 +- etc/adminhtml/system.xml | 144 +++++++++++++++++++++++++ etc/di.xml | 7 ++ i18n/fr_FR.csv | 7 ++ i18n/nl_NL.csv | 7 ++ 13 files changed, 200 insertions(+), 5 deletions(-) diff --git a/Adapter/ShipmentOptionsFromAdapter.php b/Adapter/ShipmentOptionsFromAdapter.php index 753ee1f2..840e1822 100644 --- a/Adapter/ShipmentOptionsFromAdapter.php +++ b/Adapter/ShipmentOptionsFromAdapter.php @@ -17,6 +17,7 @@ public function __construct(array $inputData) { $options = $inputData; $this->signature = (bool) ($options['signature'] ?? false); + $this->collect = (bool) ($options['collect'] ?? false); $this->receipt_code = (bool) ($options['receipt_code'] ?? false); $this->only_recipient = (bool) ($options['only_recipient'] ?? false); $this->large_format = (bool) ($options['large_format'] ?? false); diff --git a/Block/Sales/NewShipmentForm.php b/Block/Sales/NewShipmentForm.php index 7bbc2945..76224427 100644 --- a/Block/Sales/NewShipmentForm.php +++ b/Block/Sales/NewShipmentForm.php @@ -42,13 +42,14 @@ class NewShipmentForm /** * @var array */ - private $shipmentOptionsExplanation; + private $shipmentOptionsExplanationMap; public function __construct() { $this->shipmentOptionsHumanMap = [ AbstractConsignment::SHIPMENT_OPTION_SIGNATURE => __('Signature on receipt'), + AbstractConsignment::SHIPMENT_OPTION_COLLECT => __('Collect package'), AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE => __('Receiving code'), AbstractConsignment::SHIPMENT_OPTION_ONLY_RECIPIENT => __('Home address only'), AbstractConsignment::SHIPMENT_OPTION_AGE_CHECK => __('Age check 18+'), @@ -57,8 +58,9 @@ public function __construct() AbstractConsignment::SHIPMENT_OPTION_RETURN => __('Return if no answer'), AbstractConsignment::SHIPMENT_OPTION_SAME_DAY_DELIVERY => __('Same day delivery'), ]; - $this->shipmentOptionsExplanation = [ + $this->shipmentOptionsExplanationMap = [ AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE => __('Insurance is mandatory and will be set. Other shipment options will be removed.'), + AbstractConsignment::SHIPMENT_OPTION_COLLECT => __('The package will be collected at the location for this webshop. Please make sure you completely filled in the address including the company name in the MyParcel Backoffice. You can do so under ‘Shop settings’ -> ‘Company details’ under the tab ‘Return address’. Verify that you selected the shop corresponding to the API key you are using in your Magento installation.'), ]; } @@ -90,6 +92,6 @@ public function getShipmentOptionsHumanMap(): array */ public function getShipmentOptionsExplanationMap(): array { - return $this->shipmentOptionsExplanation; + return $this->shipmentOptionsExplanationMap; } } diff --git a/Helper/Data.php b/Helper/Data.php index 1fe7d8c8..8bb51f9c 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -18,6 +18,7 @@ use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; use MyParcelNL\Sdk\src\Model\Consignment\DropOffPoint; use MyParcelNL\Sdk\src\Services\CheckApiKeyService; +use MyParcelNL\Sdk\src\Services\CountryCodes; class Data extends AbstractHelper { @@ -269,6 +270,13 @@ public function consignmentHasShipmentOption(AbstractConsignment $consignment, s AbstractConsignment::SHIPMENT_OPTION_SIGNATURE], true); } + // UPS shipment options are available for all countries in the EU + if (CarrierUPS::NAME === $consignment->getCarrierName() + && in_array($consignment->getCountry(), CountryCodes::EU_COUNTRIES, false) + ) { + return true; + } + // No shipment options available in any other case return false; } diff --git a/Helper/ShipmentOptions.php b/Helper/ShipmentOptions.php index b1bb82e0..5e11a172 100644 --- a/Helper/ShipmentOptions.php +++ b/Helper/ShipmentOptions.php @@ -16,6 +16,7 @@ class ShipmentOptions private const ONLY_RECIPIENT = 'only_recipient'; private const SAME_DAY_DELIVERY = 'same_day_delivery'; private const SIGNATURE = 'signature'; + private const COLLECT = AbstractConsignment::SHIPMENT_OPTION_COLLECT; private const RECEIPT_CODE = AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE; private const RETURN = 'return'; private const AGE_CHECK = 'age_check'; @@ -125,6 +126,13 @@ public function hasReceiptCode(): bool return self::getValueOfOptionWhenSet(self::RECEIPT_CODE, $this->options) ?? $this->optionIsEnabled(self::RECEIPT_CODE); } + public function hasCollect(): bool + { + $collectFromOptions = self::getValueOfOptionWhenSet(self::COLLECT, $this->options); + + return $collectFromOptions ?? $this->optionIsEnabled(self::COLLECT); + } + /** * @return bool */ @@ -399,6 +407,7 @@ public function getShipmentOptions(): array self::RETURN => $this->hasReturn(), self::ONLY_RECIPIENT => $this->hasOnlyRecipient(), self::SIGNATURE => $this->hasSignature(), + self::COLLECT => $this->hasCollect(), self::RECEIPT_CODE => $this->hasReceiptCode(), self::AGE_CHECK => $this->hasAgeCheck(), self::LARGE_FORMAT => $this->hasLargeFormat(), diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php index e0a1210d..4933ec9a 100644 --- a/Model/Quote/Checkout.php +++ b/Model/Quote/Checkout.php @@ -190,7 +190,9 @@ private function getDeliveryData(?string $packageType = null): array $canHaveMonday = $consignment->canHaveExtraOption(AbstractConsignment::EXTRA_OPTION_DELIVERY_MONDAY); $canHaveMorning = $consignment->canHaveDeliveryType(AbstractConsignment::DELIVERY_TYPE_MORNING_NAME); $canHaveEvening = $consignment->canHaveDeliveryType(AbstractConsignment::DELIVERY_TYPE_EVENING_NAME); + $canHaveExpress = $consignment->canHaveDeliveryType(AbstractConsignment::DELIVERY_TYPE_EXPRESS_NAME); $canHaveSignature = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_SIGNATURE); + $canHaveCollect = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_COLLECT); $canHaveReceiptCode = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE); $canHaveOnlyRecipient = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_ONLY_RECIPIENT); $canHaveAgeCheck = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_AGE_CHECK); @@ -212,6 +214,7 @@ private function getDeliveryData(?string $packageType = null): array $eveningFee = $canHaveEvening ? $this->helper->getMethodPrice($carrierPath, 'evening/fee') : 0; $sameDayFee = $canHaveSameDay ? (int) $this->helper->getMethodPrice($carrierPath, 'delivery/same_day_delivery_fee') : 0; $signatureFee = $canHaveSignature ? $this->helper->getMethodPrice($carrierPath, 'delivery/signature_fee', false) : 0; + $collectFee = $canHaveCollect ? $this->helper->getMethodPrice($carrierPath, 'delivery/collect_fee', false) : 0; $receiptCodeFee = $canHaveReceiptCode ? $this->helper->getMethodPrice($carrierPath, 'delivery/receipt_code_fee', false) : 0; $onlyRecipientFee = $canHaveOnlyRecipient ? $this->helper->getMethodPrice($carrierPath, 'delivery/only_recipient_fee', false) : 0; $isAgeCheckActive = $canHaveAgeCheck && $this->isAgeCheckActive($carrierPath); @@ -220,6 +223,7 @@ private function getDeliveryData(?string $packageType = null): array $allowStandardDelivery = $this->helper->getBoolConfig($carrierPath, 'delivery/active'); $allowMorningDelivery = ! $isAgeCheckActive && $canHaveMorning && $this->helper->getBoolConfig($carrierPath, 'morning/active'); $allowEveningDelivery = ! $isAgeCheckActive && $canHaveEvening && $this->helper->getBoolConfig($carrierPath, 'evening/active'); + $allowExpressDelivery = $canHaveExpress && $this->helper->getBoolConfig($carrierPath, 'express/active'); $allowDeliveryOptions = ! $this->package->deliveryOptionsDisabled && ($allowPickup || $allowStandardDelivery || $allowMorningDelivery || $allowEveningDelivery); @@ -232,6 +236,7 @@ private function getDeliveryData(?string $packageType = null): array $myParcelConfig['carrierSettings'][$carrier] = [ 'allowDeliveryOptions' => $allowDeliveryOptions, 'allowStandardDelivery' => $allowStandardDelivery, + 'allowCollect' => $canHaveCollect && $this->helper->getBoolConfig($carrierPath, 'delivery/collect_active'), 'allowSignature' => $canHaveSignature && $this->helper->getBoolConfig($carrierPath, 'delivery/signature_active'), 'allowReceiptCode' => $canHaveReceiptCode && $this->helper->getBoolConfig($carrierPath, 'delivery/receipt_code_active'), 'allowOnlyRecipient' => $canHaveOnlyRecipient && $this->helper->getBoolConfig($carrierPath, 'delivery/only_recipient_active'), @@ -240,10 +245,12 @@ private function getDeliveryData(?string $packageType = null): array 'allowPickupLocations' => $canHavePickup && $this->isPickupAllowed($carrierPath), 'allowMondayDelivery' => $canHaveMonday && $this->helper->getBoolConfig($carrierPath, 'delivery/monday_active'), 'allowSameDayDelivery' => $canHaveSameDay && $this->helper->getBoolConfig($carrierPath, 'delivery/same_day_delivery_active'), + 'allowExpressDelivery' => $allowExpressDelivery, 'dropOffDays' => $this->getDropOffDays($carrierPath), 'priceSignature' => $signatureFee, + 'priceCollect' => $collectFee, 'priceReceiptCode' => $receiptCodeFee, 'priceOnlyRecipient' => $onlyRecipientFee, 'priceStandardDelivery' => $showTotalPrice ? $basePrice : 0, @@ -251,6 +258,7 @@ private function getDeliveryData(?string $packageType = null): array 'priceMorningDelivery' => $morningFee, 'priceEveningDelivery' => $eveningFee, 'priceSameDayDelivery' => $sameDayFee, + 'priceExpressDelivery' => $allowExpressDelivery ? $this->helper->getMethodPrice($carrierPath, 'express/fee') : 0, 'priceSameDayDeliveryAndOnlyRecipient' => $sameDayFee + $onlyRecipientFee, 'priceMorningSignature' => ($morningFee + $signatureFee), diff --git a/Model/Sales/MagentoCollection.php b/Model/Sales/MagentoCollection.php index 680a583c..c87811ec 100755 --- a/Model/Sales/MagentoCollection.php +++ b/Model/Sales/MagentoCollection.php @@ -111,6 +111,7 @@ abstract class MagentoCollection implements MagentoCollectionInterface 'carrier' => 'postnl', 'positions' => null, 'signature' => null, + 'collect' => null, 'receipt_code' => null, 'only_recipient' => null, 'return' => null, diff --git a/Model/Sales/TrackTraceHolder.php b/Model/Sales/TrackTraceHolder.php index 2ae29e4d..5fb0ee71 100755 --- a/Model/Sales/TrackTraceHolder.php +++ b/Model/Sales/TrackTraceHolder.php @@ -218,6 +218,7 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options) ->setDropOffPoint($dropOffPoint) ->setOnlyRecipient($this->shipmentOptionsHelper->hasOnlyRecipient()) ->setSignature($this->shipmentOptionsHelper->hasSignature()) + ->setCollect($this->shipmentOptionsHelper->hasCollect()) ->setReceiptCode($this->shipmentOptionsHelper->hasReceiptCode()) ->setReturn($this->shipmentOptionsHelper->hasReturn()) ->setSameDayDelivery($this->shipmentOptionsHelper->hasSameDayDelivery()) diff --git a/Model/Source/DefaultOptions.php b/Model/Source/DefaultOptions.php index 7f62bf6d..cb95e025 100755 --- a/Model/Source/DefaultOptions.php +++ b/Model/Source/DefaultOptions.php @@ -89,7 +89,7 @@ public function __construct(Order $order, Data $helper) /** * Get default of the option * - * @param string $option 'only_recipient'|'signature'|'receipt_code'|'return'|'large_format' + * @param string $option 'only_recipient'|'signature'|'collect'|'receipt_code'|'return'|'large_format' * @param string $carrier * * @return bool diff --git a/composer.json b/composer.json index 62eb5ac6..1d531033 100755 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "type": "magento2-module", "require": { "php": "^7.1 || ^8.0", - "myparcelnl/sdk": "~v7.18", + "myparcelnl/sdk": "~v7.19", "magento/framework": ">=101.0.8 <102 || >=102.0.1" }, "require-dev": { diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 4726743b..69f8e756 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1509,6 +1509,58 @@ Magento\Config\Model\Config\Source\Yesno + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + This will be added to the regular shipping price + + 1 + 1 + + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + This will be added to the regular shipping price + + 1 + 1 + + + + + Magento\Config\Model\Config\Source\Yesno + + 1 + + + + + This will be added to the regular shipping price + + 1 + 1 + + @@ -1615,6 +1667,98 @@ For orders before this time, the drop-off is considered done on this day. + + + Fill in your preferences for a shipment. These settings will only apply for the mass actions in + the order grid. When creating a single shipment, these settings can be changed manually. These + settings will activate based on the order total amount. + + + + Magento\Config\Model\Config\Source\Yesno + + + + validate-number validate-zero-or-greater + 'Signature on receipt' operates above a certain order total amount + + 1 + + + + + Magento\Config\Model\Config\Source\Yesno + + + + validate-number validate-zero-or-greater + + 1 + + + + + Magento\Config\Model\Config\Source\Yesno + + + + validate-number validate-zero-or-greater + 'Home address only' operates above a certain order total amount + + 1 + + + + + Magento\Config\Model\Config\Source\Yesno + + + + validate-number validate-zero-or-greater + The minimum amount from when insurance is active. + + + + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\UPS\Local + + + + validate-number validate-number-range number-range-0-100 + Use percentage of total order amount for insurance. After the calculation, the next + available price scale is selected. + + + + + + + + Magento\Config\Model\Config\Source\Yesno + UPS guarantees delivery within one day with this option active. + + + + This will be added to the regular shipping price + + 1 + + +
+ + + ups + local + + + diff --git a/i18n/fr_FR.csv b/i18n/fr_FR.csv index 93284b04..1e73a64b 100644 --- a/i18n/fr_FR.csv +++ b/i18n/fr_FR.csv @@ -75,6 +75,7 @@ Select a standard orientation for printing labels.,Sélectionnez une orientation Default shipping options,Options d'expédition standards "Fill in your preferences for a shipment. These settings will only apply for the mass actions in the order grid. When creating a single shipment, these settings can be changed manually. These settings will activate based on the order total amount.","Indiquez ici vos préférences standards quant aux options d'expédition. S'ils sont d'application, ces paramètres seront utilisés par défaut pour tous vos envois. Ces options peuvent bien sûr toujours être modifiées lors du traitement." Automate 'Signature on receipt',Automatisation de la 'Signature pour réception' +Automate 'Collect package',Automatisation de 'Livré en 1 jour' Automate 'Receipt code',Automatisation de la 'Code de réception' Signature on receipt' operates above a certain order total amount,La 'Signature pour réception' est activée lorsque le montant total dépasse le montant indiqué ci-dessus Automate 'Insurance € 500',Automatisation de l''Assurance jusqu'à € 500' @@ -88,6 +89,7 @@ Package,Colis Signature on receipt,Signature pour réception Receipt code,Code de réception Receipt code fee,Frais de code de réception +Collect package,Faire récupérer le colis Home address only,Livraison à domicile uniquement Hide sender title,Titre de masquer l'expéditeur Insured up to:,Assuré jusqu'à : @@ -139,6 +141,9 @@ Cut-off time,Heure limite de commande "If a request is made for the delivery options between Friday after, and Monday before, cut-off time then Tuesday will be shown as the next possible delivery date.","Lorsqu'une commande est passée après la dernière heure de commande le vendredi et avant celle-ci le lundi, c'est donc le mardi qui sera affiché comme premier jour de livraison." Drop-off days,Jours de dépôt Monday delivery,Livraison le lundi +Express delivery,Livré en un jour +Express delivery fee,Livré en un jour - prix +Express delivery active,Livré en un jour actif Same day delivery,Livraison le jour même Same day title,Titre le jour même "Delivery on monday may require special conditions compared to other (week)days including but not limited to fee and cutoff time.","La livraison le lundi peut nécessiter des conditions spéciales par rapport aux autres jours de la semaine, y compris mais sans s'y limiter, des frais et heure limite de commande." @@ -166,6 +171,8 @@ Hide sender,Masquer l'expéditeur This will be added to the regular shipping price, Ceci sera ajouté aux frais d'expédition standards If both have been selected this price will be added to the regular shipping price. Leave empty for not using it.,Si les deux éléments sont sélectionnés, ce prix sera ajouté aux frais d'expédition standards. Laissez vide pour ignorer cette option. "To use this optimally, set a weight or 'Fit in mailbox' volume of each product. Regardless, shipments heavier than the weight specified here will not be mailbox.","Pour utiliser cette fonction de manière optimale, spécifiez d'abord le poids ou le volume de vos produits. Les envois plus lourds que le poids spécifié ici ne seront pas considérés comme des envois pour Boîte aux lettres." +"Insurance is mandatory and will be set. Other shipment options will be removed.","L’assurance est obligatoire et sera activée. Les autres options d'envoi seront supprimées." +"The package will be collected at the location for this webshop. Please make sure you completely filled in the address including the company name in the MyParcel Backoffice. You can do so under ‘Shop settings’ -> ‘Company details’ under the tab ‘Return address’. Verify that you selected the shop corresponding to the API key you are using in your Magento installation.","Le colis sera collecté à l’adresse de ce webshop. Assurez-vous que l’adresse est complète, y compris le nom de l’entreprise, dans le backoffice de MyParcel. Vous pouvez le faire sous ‘Shop settings’ -> ‘Company details’ dans l’onglet ‘Adresse de retour’. Vérifiez que vous avez sélectionné la boutique correspondant à la clé API que vous utilisez dans votre installation Magento." This will be added to the regular shipping price,Ceci sera ajouté aux frais d'expédition standards Pickup at PostNL location,Collecte dans un point postnl Pickup active,Collecte active diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index 81f85927..03e432ab 100755 --- a/i18n/nl_NL.csv +++ b/i18n/nl_NL.csv @@ -89,6 +89,7 @@ Show map first,Toon kaart eerst Default shipping options,Standaard verzendinstellingen "Fill in your preferences for a shipment. These settings will only apply for the mass actions in the order grid. When creating a single shipment, these settings can be changed manually. These settings will activate based on the order total amount.","Vul hier uw standaard voorkeuren in voor uw verzendopties. Deze instellingen worden als default op al uw zendingen toegepast, indien van toepassing. Deze opties zijn later, per zending, uiteraard nog wel aan te passen tijdens het verwerken." Automate 'Signature on receipt',Automatiseer 'Handtekening voor ontvangst' +Automate 'Collect package',Automatiseer 'Pakket laten ophalen' Automate 'Receipt code',Automatiseer 'Ontvangstcode' Automate 'Home address only',Automatiseer 'Alleen huisadres' Automate 'Return if no answer',Automatiseer 'Retour bij geen gehoor' @@ -115,6 +116,9 @@ Enter a basic price for a mailbox. The regular price will not affect this price. Morning delivery,Ochtendlevering Evening delivery,Avondlevering Evening delivery fee,Avondlevering kosten +Express delivery,Binnen 1 dag bezorgd +Express delivery fee,Binnen 1 dag bezorgd kosten +Express delivery active,Binnen 1 dag bezorgd ingeschakeld Same day delivery,Zelfde dag bezorgd Same day title,Zelfde dag titel Morning delivery active,Ochtendlevering ingeschakeld @@ -128,6 +132,7 @@ Number of days,Aantal dagen Delivery enabled,Bezorging ingeschakeld Receipt code,Ontvangstcode Receipt code fee,Ontvangstcode kosten +Collect package,Pakket laten ophalen Home address only,Alleen huisadres Home address only fee,Alleen huisadres kosten Digital stamp settings,Digitalepostzegel instellingen @@ -232,6 +237,8 @@ Hide sender,Verberg afzender This will be added to the regular shipping price, Dit zal bij de normale verzendkosten worden opgeteld If both have been selected this price will be added to the regular shipping price. Leave empty for not using it.,Als beide geselecteerd zijn zal deze prijs bij de normale verzendkosten worden opgeteld. Laat leeg om dit niet te gebruiken. "To use this optimally, set a weight or 'Fit in mailbox' volume of each product. Regardless, shipments heavier than the weight specified here will not be mailbox.","Om deze functie optimaal te gebruiken, stel je eerst het gewicht of volume in van jouw producten. Ongeacht deze instelling, zendingen zwaarder dan het hier opgegeven gewicht zullen niet als brievenbuspakket worden verzonden." +"Insurance is mandatory and will be set. Other shipment options will be removed.","Verzekering is verplicht en zal worden ingesteld. Andere verzendopties worden verwijderd." +"The package will be collected at the location for this webshop. Please make sure you completely filled in the address including the company name in the MyParcel Backoffice. You can do so under ‘Shop settings’ -> ‘Company details’ under the tab ‘Return address’. Verify that you selected the shop corresponding to the API key you are using in your Magento installation.","Het pakket zal worden opgehaald bij de locatie voor deze webshop. Zorg ervoor dat je het adres volledig hebt ingevuld, inclusief de bedrijfsnaam, in de MyParcel Backoffice. Dit kan onder ‘Shopinstellingen’ -> ‘Bedrijfsgegevens’ onder het tabblad ‘Retouradres’. Controleer of je de winkel hebt geselecteerd die overeenkomt met de API-sleutel die je gebruikt in jouw Magento-installatie." This will be added to the regular shipping price,Dit zal bij de normale verzendkosten worden opgeteld Pickup at PostNL location,Ophalen bij een PostNL locatie Pickup active,Ophalen actief