diff --git a/Adapter/ShipmentOptionsFromAdapter.php b/Adapter/ShipmentOptionsFromAdapter.php index 956fd35f..753ee1f2 100644 --- a/Adapter/ShipmentOptionsFromAdapter.php +++ b/Adapter/ShipmentOptionsFromAdapter.php @@ -4,7 +4,6 @@ namespace MyParcelNL\Magento\Adapter; -use MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractDeliveryOptionsAdapter; use MyParcelNL\Sdk\src\Adapter\DeliveryOptions\AbstractShipmentOptionsAdapter; class ShipmentOptionsFromAdapter extends AbstractShipmentOptionsAdapter @@ -16,8 +15,9 @@ class ShipmentOptionsFromAdapter extends AbstractShipmentOptionsAdapter */ public function __construct(array $inputData) { - $options = $inputData ?? []; + $options = $inputData; $this->signature = (bool) ($options['signature'] ?? 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); $this->age_check = (bool) ($options['age_check'] ?? false); diff --git a/Block/Sales/NewShipment.php b/Block/Sales/NewShipment.php index ba1f7cda..216159b1 100755 --- a/Block/Sales/NewShipment.php +++ b/Block/Sales/NewShipment.php @@ -14,6 +14,7 @@ namespace MyParcelNL\Magento\Block\Sales; +use Exception; use Magento\Backend\Block\Template\Context; use Magento\CatalogInventory\Api\StockConfigurationInterface; use Magento\CatalogInventory\Api\StockRegistryInterface; @@ -21,10 +22,10 @@ use Magento\Framework\Registry; use Magento\Sales\Block\Adminhtml\Items\AbstractItems; use MyParcelNL\Magento\Helper\Checkout; -use MyParcelNL\Magento\Model\Sales\MagentoOrderCollection; -use MyParcelNL\Magento\Model\Source\DefaultOptions; use MyParcelNL\Magento\Helper\Data; +use MyParcelNL\Magento\Model\Sales\MagentoOrderCollection; use MyParcelNL\Magento\Model\Sales\TrackTraceHolder; +use MyParcelNL\Magento\Model\Source\DefaultOptions; use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; class NewShipment extends AbstractItems @@ -72,13 +73,14 @@ class NewShipment extends AbstractItems * @param \Magento\Framework\ObjectManagerInterface $objectManager */ public function __construct( - Context $context, - Data $helper, - StockRegistryInterface $stockRegistry, + Context $context, + Data $helper, + StockRegistryInterface $stockRegistry, StockConfigurationInterface $stockConfiguration, - Registry $registry, - ObjectManagerInterface $objectManager - ) { + Registry $registry, + ObjectManagerInterface $objectManager + ) + { // Set order $this->order = $registry->registry('current_shipment')->getOrder(); $this->dataHelper = $helper; @@ -97,8 +99,8 @@ public function __construct( } /** - * @param string $option 'signature', 'only_recipient' - * @param string $carrier + * @param string $option 'signature', 'only_recipient' + * @param string $carrier * * @return bool */ @@ -110,8 +112,8 @@ public function hasDefaultOption(string $option, string $carrier): bool /** * Get default value of age check * - * @param string $carrier - * @param string $option + * @param string $carrier + * @param string $option * * @return bool */ @@ -123,7 +125,7 @@ public function hasDefaultOptionsWithoutPrice(string $carrier, string $option): /** * Get default value of insurance based on order grand total * - * @param string $carrier + * @param string $carrier * * @return int */ @@ -171,6 +173,18 @@ public function getCountry() return $this->order->getShippingAddress()->getCountryId(); } + public function getDeliveryType(): int + { + try { + $deliveryTypeName = json_decode($this->order->getData(Checkout::FIELD_DELIVERY_OPTIONS), true)['deliveryType']; + $deliveryType = AbstractConsignment::DELIVERY_TYPES_NAMES_IDS_MAP[$deliveryTypeName]; + } catch (Exception $e) { + $deliveryType = AbstractConsignment::DEFAULT_DELIVERY_TYPE; + } + + return $deliveryType; + } + public function consignmentHasShipmentOption(AbstractConsignment $consignment, string $shipmentOption): bool { return $this->dataHelper->consignmentHasShipmentOption($consignment, $shipmentOption); diff --git a/Block/Sales/NewShipmentForm.php b/Block/Sales/NewShipmentForm.php index ec361cbd..7bbc2945 100644 --- a/Block/Sales/NewShipmentForm.php +++ b/Block/Sales/NewShipmentForm.php @@ -2,6 +2,7 @@ namespace MyParcelNL\Magento\Block\Sales; +use Exception; use MyParcelNL\Sdk\src\Factory\ConsignmentFactory; use MyParcelNL\Sdk\src\Model\Carrier\CarrierDHLEuroplus; use MyParcelNL\Sdk\src\Model\Carrier\CarrierDHLForYou; @@ -14,33 +15,41 @@ class NewShipmentForm { - public const ALLOWED_CARRIER_CLASSES = [ - CarrierPostNL::class, - CarrierDHLForYou::class, - CarrierDHLEuroplus::class, - CarrierDHLParcelConnect::class, - CarrierUPS::class, - CarrierDPD::class, - ]; + public const ALLOWED_CARRIER_CLASSES + = [ + CarrierPostNL::class, + CarrierDHLForYou::class, + CarrierDHLEuroplus::class, + CarrierDHLParcelConnect::class, + CarrierUPS::class, + CarrierDPD::class, + ]; - public const PACKAGE_TYPE_HUMAN_MAP = [ - AbstractConsignment::PACKAGE_TYPE_PACKAGE => 'Package', - AbstractConsignment::PACKAGE_TYPE_MAILBOX => 'Mailbox', - AbstractConsignment::PACKAGE_TYPE_LETTER => 'Letter', - AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP => 'Digital stamp', - AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL => 'Small package', - ]; + public const PACKAGE_TYPE_HUMAN_MAP + = [ + AbstractConsignment::PACKAGE_TYPE_PACKAGE => 'Package', + AbstractConsignment::PACKAGE_TYPE_MAILBOX => 'Mailbox', + AbstractConsignment::PACKAGE_TYPE_LETTER => 'Letter', + AbstractConsignment::PACKAGE_TYPE_DIGITAL_STAMP => 'Digital stamp', + AbstractConsignment::PACKAGE_TYPE_PACKAGE_SMALL => 'Small package', + ]; /** * @var array */ private $shipmentOptionsHumanMap; + /** + * @var array + */ + private $shipmentOptionsExplanation; + public function __construct() { - $this->shipmentOptionsHumanMap = [ + $this->shipmentOptionsHumanMap = [ AbstractConsignment::SHIPMENT_OPTION_SIGNATURE => __('Signature on receipt'), + AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE => __('Receiving code'), AbstractConsignment::SHIPMENT_OPTION_ONLY_RECIPIENT => __('Home address only'), AbstractConsignment::SHIPMENT_OPTION_AGE_CHECK => __('Age check 18+'), AbstractConsignment::SHIPMENT_OPTION_HIDE_SENDER => __('Hide sender'), @@ -48,10 +57,14 @@ public function __construct() AbstractConsignment::SHIPMENT_OPTION_RETURN => __('Return if no answer'), AbstractConsignment::SHIPMENT_OPTION_SAME_DAY_DELIVERY => __('Same day delivery'), ]; + $this->shipmentOptionsExplanation = [ + AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE => __('Insurance is mandatory and will be set. Other shipment options will be removed.'), + ]; } + /** * @return AbstractConsignment[] - * @throws \Exception + * @throws Exception */ public function getCarrierSpecificAbstractConsignments(): array { @@ -71,4 +84,12 @@ public function getShipmentOptionsHumanMap(): array { return $this->shipmentOptionsHumanMap; } + + /** + * @return array + */ + public function getShipmentOptionsExplanationMap(): array + { + return $this->shipmentOptionsExplanation; + } } diff --git a/Helper/Data.php b/Helper/Data.php index 3e50b30a..1fe7d8c8 100755 --- a/Helper/Data.php +++ b/Helper/Data.php @@ -31,14 +31,15 @@ class Data extends AbstractHelper public const XML_PATH_DPD_SETTINGS = 'myparcelnl_magento_dpd_settings/'; public const XML_PATH_LOCALE_WEIGHT_UNIT = 'general/locale/weight_unit'; public const DEFAULT_WEIGHT = 1000; - public const CARRIERS_XML_PATH_MAP = [ - CarrierPostNL::NAME => self::XML_PATH_POSTNL_SETTINGS, - CarrierDHLForYou::NAME => self::XML_PATH_DHLFORYOU_SETTINGS, - CarrierDHLEuroplus::NAME => self::XML_PATH_DHLEUROPLUS_SETTINGS, - CarrierDHLParcelConnect::NAME => self::XML_PATH_DHLPARCELCONNECT_SETTINGS, - CarrierUPS::NAME => self::XML_PATH_UPS_SETTINGS, - CarrierDPD::NAME => self::XML_PATH_DPD_SETTINGS, - ]; + public const CARRIERS_XML_PATH_MAP + = [ + CarrierPostNL::NAME => self::XML_PATH_POSTNL_SETTINGS, + CarrierDHLForYou::NAME => self::XML_PATH_DHLFORYOU_SETTINGS, + CarrierDHLEuroplus::NAME => self::XML_PATH_DHLEUROPLUS_SETTINGS, + CarrierDHLParcelConnect::NAME => self::XML_PATH_DHLPARCELCONNECT_SETTINGS, + CarrierUPS::NAME => self::XML_PATH_UPS_SETTINGS, + CarrierDPD::NAME => self::XML_PATH_DPD_SETTINGS, + ]; /** * @var \Magento\Framework\Module\ModuleListInterface @@ -53,15 +54,16 @@ class Data extends AbstractHelper /** * Get settings by field * - * @param Context $context - * @param ModuleListInterface $moduleList - * @param CheckApiKeyService $checkApiKeyService + * @param Context $context + * @param ModuleListInterface $moduleList + * @param CheckApiKeyService $checkApiKeyService */ public function __construct( Context $context, ModuleListInterface $moduleList, CheckApiKeyService $checkApiKeyService - ) { + ) + { parent::__construct($context); $this->moduleList = $moduleList; $this->checkApiKeyService = $checkApiKeyService; @@ -71,7 +73,7 @@ public function __construct( * Get settings by field * * @param $field - * @param null $storeId + * @param null $storeId * * @return mixed */ @@ -83,8 +85,8 @@ public function getConfigValue($field, $storeId = null) /** * Get general settings * - * @param string $code - * @param null|int $storeId + * @param string $code + * @param null|int $storeId * * @return mixed */ @@ -117,9 +119,9 @@ public function getDropOffPoint(AbstractCarrier $carrier): ?DropOffPoint /** * Get default settings * - * @param string $carrier - * @param string $code - * @param null $storeId + * @param string $carrier + * @param string $code + * @param null $storeId * * @return mixed */ @@ -131,8 +133,8 @@ public function getStandardConfig(string $carrier, string $code = '', $storeId = /** * Get carrier setting * - * @param string $code - * @param string $carrier + * @param string $code + * @param string $carrier * * @return mixed */ @@ -174,7 +176,7 @@ public function apiKeyIsCorrect(): bool $apiKey = $this->getApiKey(); return $this->checkApiKeyService->setApiKey($apiKey) - ->apiKeyIsCorrect(); + ->apiKeyIsCorrect(); } /** @@ -200,7 +202,7 @@ public function hasApiKey(): bool /** * Get date in YYYY-MM-DD HH:MM:SS format * - * @param string|null $date + * @param string|null $date * * @return string|null */ @@ -224,7 +226,7 @@ public function convertDeliveryDate(?string $date): ?string /** * Get delivery type and when it is null use 'standard' * - * @param int|null $deliveryType + * @param int|null $deliveryType * * @return int */ @@ -238,16 +240,16 @@ public function checkDeliveryType(?int $deliveryType): int } /** - * @param int $orderId - * @param string $status + * @param int $orderId + * @param string $status */ public function setOrderStatus(int $orderId, string $status): void { $order = ObjectManager::getInstance() - ->create('\Magento\Sales\Model\Order') - ->load($orderId); + ->create('\Magento\Sales\Model\Order') + ->load($orderId); $order->setState($status) - ->setStatus($status); + ->setStatus($status); $order->save(); } @@ -267,14 +269,14 @@ public function consignmentHasShipmentOption(AbstractConsignment $consignment, s AbstractConsignment::SHIPMENT_OPTION_SIGNATURE], true); } - // No shipment options available in any other cases + // No shipment options available in any other case return false; } /** * Get the correct weight type * - * @param null|float $weight + * @param null|float $weight * * @return int */ diff --git a/Helper/ShipmentOptions.php b/Helper/ShipmentOptions.php index 27ebf134..f41a8f0a 100644 --- a/Helper/ShipmentOptions.php +++ b/Helper/ShipmentOptions.php @@ -3,10 +3,12 @@ namespace MyParcelNL\Magento\Helper; use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\ResourceConnection; use Magento\Framework\ObjectManagerInterface; +use Magento\Sales\Model\Order; use MyParcelNL\Magento\Model\Source\DefaultOptions; +use MyParcelNL\Sdk\src\Model\Carrier\CarrierPostNL; use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; -use Magento\Framework\App\ResourceConnection; class ShipmentOptions { @@ -14,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 RECEIPT_CODE = AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE; private const RETURN = 'return'; private const AGE_CHECK = 'age_check'; private const LARGE_FORMAT = 'large_format'; @@ -61,21 +64,22 @@ class ShipmentOptions private $cc; /** - * @param \MyParcelNL\Magento\Model\Source\DefaultOptions $defaultOptions - * @param \MyParcelNL\Magento\Helper\Data $helper - * @param \Magento\Sales\Model\Order $order - * @param \Magento\Framework\ObjectManagerInterface $objectManager - * @param string $carrier - * @param array $options + * @param \MyParcelNL\Magento\Model\Source\DefaultOptions $defaultOptions + * @param \MyParcelNL\Magento\Helper\Data $helper + * @param \Magento\Sales\Model\Order $order + * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param string $carrier + * @param array $options */ public function __construct( - DefaultOptions $defaultOptions, - Data $helper, - \Magento\Sales\Model\Order $order, - ObjectManagerInterface $objectManager, - string $carrier, - array $options = [] - ) { + DefaultOptions $defaultOptions, + Data $helper, + Order $order, + ObjectManagerInterface $objectManager, + string $carrier, + array $options = [] + ) + { self::$defaultOptions = $defaultOptions; $this->helper = $helper; $this->order = $order; @@ -107,6 +111,21 @@ public function hasSignature(): bool return $signatureFromOptions ?? $this->optionIsEnabled(self::SIGNATURE); } + public function hasReceiptCode(): bool + { + $deliveryOptions = $this->order->getData(Checkout::FIELD_DELIVERY_OPTIONS) ?? []; + $deliveryType = $deliveryOptions['deliveryType'] ?? AbstractConsignment::DEFAULT_DELIVERY_TYPE; + + if (AbstractConsignment::CC_NL !== $this->cc + || CarrierPostNL::NAME !== $this->carrier + || AbstractConsignment::DELIVERY_TYPE_STANDARD !== $deliveryType + ) { + return false; + } + + return self::getValueOfOptionWhenSet(self::RECEIPT_CODE, $this->options) ?? $this->optionIsEnabled(self::RECEIPT_CODE); + } + /** * @return bool */ @@ -187,9 +206,9 @@ public static function getAgeCheckFromProduct($products): ?bool } /** - * @param string $tableName - * @param string $entityId - * @param string $column + * @param string $tableName + * @param string $entityId + * @param string $column * * @return null|string */ @@ -213,9 +232,9 @@ public static function getAttributeValue(string $tableName, string $entityId, st } /** - * @param $connection - * @param string $tableName - * @param string $databaseColumn + * @param $connection + * @param string $tableName + * @param string $databaseColumn * * @return mixed */ @@ -230,10 +249,10 @@ public static function getAttributeId($connection, string $tableName, string $da } /** - * @param object $connection - * @param string $tableName - * @param string $attributeId - * @param string $entityId + * @param object $connection + * @param string $tableName + * @param string $attributeId + * @param string $entityId * * @return string|null */ @@ -242,7 +261,8 @@ public static function getValueFromAttribute( string $tableName, string $attributeId, string $entityId - ): ?string { + ): ?string + { $sql = $connection ->select() ->from($tableName, ['value']) @@ -253,8 +273,8 @@ public static function getValueFromAttribute( } /** - * @param string $key - * @param array $options + * @param string $key + * @param array $options * * @return bool|null boolean value of the option named $key, or null when not set in $options */ @@ -321,8 +341,8 @@ public function getLabelDescription(): string } /** - * @param array $productInfo - * @param string $field + * @param array $productInfo + * @param string $field * * @return string|null */ @@ -342,14 +362,14 @@ private function getProductInfo(array $productInfo, string $field): ?string */ public function getItemsCollectionByShipmentId($shipmentId): array { - /** @var \Magento\Framework\App\ResourceConnection $connection */ + /** @var ResourceConnection $connection */ $connection = $this->objectManager->create(ResourceConnection::class); $conn = $connection->getConnection(); $select = $conn->select() - ->from( - ['main_table' => $connection->getTableName('sales_shipment_item')] - ) - ->where('main_table.parent_id=?', $shipmentId); + ->from( + ['main_table' => $connection->getTableName('sales_shipment_item')] + ) + ->where('main_table.parent_id=?', $shipmentId); return $conn->fetchAll($select); } @@ -380,6 +400,7 @@ public function getShipmentOptions(): array self::RETURN => $this->hasReturn(), self::ONLY_RECIPIENT => $this->hasOnlyRecipient(), self::SIGNATURE => $this->hasSignature(), + self::RECEIPT_CODE => $this->hasReceiptCode(), self::AGE_CHECK => $this->hasAgeCheck(), self::LARGE_FORMAT => $this->hasLargeFormat(), self::LABEL_DESCRIPTION => $this->getLabelDescription(), diff --git a/Model/Quote/Checkout.php b/Model/Quote/Checkout.php index 7f184cde..e0a1210d 100644 --- a/Model/Quote/Checkout.php +++ b/Model/Quote/Checkout.php @@ -10,6 +10,7 @@ use MyParcelNL\Magento\Model\Source\PriceDeliveryOptionsView; use MyParcelNL\Sdk\src\Factory\ConsignmentFactory; use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; +use Throwable; class Checkout { @@ -27,7 +28,7 @@ class Checkout private $quoteId; /** - * @var PackageRepository + * @var \MyParcelNL\Magento\Model\Sales\Repository\PackageRepository */ private $package; @@ -49,20 +50,20 @@ class Checkout /** * Checkout constructor. * - * @param \Magento\Checkout\Model\Session $session - * @param \Magento\Checkout\Model\Cart $cart - * @param \MyParcelNL\Magento\Helper\Checkout $helper - * @param PackageRepository $package - * @param \Magento\Store\Model\StoreManagerInterface $currency - * + * @param \Magento\Checkout\Model\Session $session + * @param \Magento\Checkout\Model\Cart $cart + * @param \MyParcelNL\Magento\Helper\Checkout $helper + * @param \MyParcelNL\Magento\Model\Sales\Repository\PackageRepository $package + * @param \Magento\Store\Model\StoreManagerInterface $currency */ public function __construct( - Session $session, - Cart $cart, - \MyParcelNL\Magento\Helper\Checkout $helper, - PackageRepository $package, - StoreManagerInterface $currency - ) { + Session $session, + Cart $cart, + \MyParcelNL\Magento\Helper\Checkout $helper, // FQCN required for Magento + PackageRepository $package, + StoreManagerInterface $currency + ) + { $this->helper = $helper; $this->quoteId = $session->getQuoteId(); $this->cart = $cart->getQuote(); @@ -112,7 +113,7 @@ public function getDeliveryOptions(array $forAddress = []): array /** * Get general data * - * @return array) + * @return array * @throws \Magento\Framework\Exception\NoSuchEntityException */ private function getGeneralData() @@ -177,7 +178,7 @@ private function getDeliveryData(?string $packageType = null): array try { $consignment = ConsignmentFactory::createByCarrierName($carrier); $consignment->setPackageType(AbstractConsignment::PACKAGE_TYPE_PACKAGE); - } catch (\Throwable $ex) { + } catch (Throwable $ex) { $this->helper->log(sprintf('getDeliveryData: Could not create default consignment for %s', $carrier)); continue; } @@ -190,6 +191,7 @@ private function getDeliveryData(?string $packageType = null): array $canHaveMorning = $consignment->canHaveDeliveryType(AbstractConsignment::DELIVERY_TYPE_MORNING_NAME); $canHaveEvening = $consignment->canHaveDeliveryType(AbstractConsignment::DELIVERY_TYPE_EVENING_NAME); $canHaveSignature = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_SIGNATURE); + $canHaveReceiptCode = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE); $canHaveOnlyRecipient = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_ONLY_RECIPIENT); $canHaveAgeCheck = $consignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_AGE_CHECK); $canHavePickup = $consignment->canHaveDeliveryType(AbstractConsignment::DELIVERY_TYPE_PICKUP_NAME); @@ -210,6 +212,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; + $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); @@ -230,6 +233,7 @@ private function getDeliveryData(?string $packageType = null): array 'allowDeliveryOptions' => $allowDeliveryOptions, 'allowStandardDelivery' => $allowStandardDelivery, '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'), 'allowMorningDelivery' => $allowMorningDelivery, 'allowEveningDelivery' => $allowEveningDelivery, @@ -237,9 +241,10 @@ private function getDeliveryData(?string $packageType = null): array 'allowMondayDelivery' => $canHaveMonday && $this->helper->getBoolConfig($carrierPath, 'delivery/monday_active'), 'allowSameDayDelivery' => $canHaveSameDay && $this->helper->getBoolConfig($carrierPath, 'delivery/same_day_delivery_active'), - 'dropOffDays' => $this->getDropOffDays($carrierPath), + 'dropOffDays' => $this->getDropOffDays($carrierPath), 'priceSignature' => $signatureFee, + 'priceReceiptCode' => $receiptCodeFee, 'priceOnlyRecipient' => $onlyRecipientFee, 'priceStandardDelivery' => $showTotalPrice ? $basePrice : 0, 'priceMondayDelivery' => $mondayFee, @@ -281,14 +286,15 @@ public function getActiveCarriers(): array return $carriers; } - private function getDropOffDays(string $carrierPath): array { + private function getDropOffDays(string $carrierPath): array + { $dropOffDays = []; for ($weekday = 0; $weekday < 7; $weekday++) { $cutoffTimeSameDay = $this->helper->getTimeConfig($carrierPath, "drop_off_days/cutoff_time_same_day_$weekday"); - $sameDayTimeEntry = $cutoffTimeSameDay ? ['cutoffTimeSameDay' => $cutoffTimeSameDay] : []; + $sameDayTimeEntry = $cutoffTimeSameDay ? ['cutoffTimeSameDay' => $cutoffTimeSameDay] : []; if ($this->helper->getBoolConfig($carrierPath, "drop_off_days/day_{$weekday}_active")) { $dropOffDays[] = (object) array_merge([ - 'weekday' => $weekday, + 'weekday' => $weekday, 'cutoffTime' => $this->helper->getTimeConfig($carrierPath, "drop_off_days/cutoff_time_$weekday"), ], $sameDayTimeEntry); } @@ -305,22 +311,22 @@ private function getDropOffDays(string $carrierPath): array { private function getDeliveryOptionsStrings(): array { return [ - 'deliveryTitle' => $this->helper->getGeneralConfig('delivery_titles/delivery_title') ?: __('delivery_title'), - 'deliveryStandardTitle' => $this->helper->getGeneralConfig('delivery_titles/standard_delivery_title') ?: __('standard_delivery'), - 'deliveryMorningTitle' => $this->helper->getGeneralConfig('delivery_titles/morning_title') ?: __('morning_title'), - 'deliveryEveningTitle' => $this->helper->getGeneralConfig('delivery_titles/evening_title') ?: __('evening_title'), - 'deliveryPickupTitle' => $this->helper->getGeneralConfig('delivery_titles/pickup_title') ?: __('pickup_title'), - 'pickupTitle' => $this->helper->getGeneralConfig('delivery_titles/pickup_title') ?: __('pickup_title'), - 'deliverySameDayTitle' => $this->helper->getGeneralConfig('delivery_titles/same_day_title') ?: __('same_day_title'), - 'hideSenderTitle' => $this->helper->getGeneralConfig('delivery_titles/hide_sender_title') ?: __('hide_sender_title'), - 'list' => $this->helper->getGeneralConfig('delivery_titles/pickup_list_button_title') ?: __('list_title'), - 'map' => $this->helper->getGeneralConfig('delivery_titles/pickup_map_button_title') ?: __('map_title'), - 'packageTypeMailbox' => $this->helper->getGeneralConfig('delivery_titles/mailbox_title') ?: __('mailbox_title'), - 'packageTypeDigitalStamp' => $this->helper->getGeneralConfig('delivery_titles/digital_stamp_title') ?: __('digital_stamp_title'), - 'packageTypePackageSmall' => $this->helper->getGeneralConfig('delivery_titles/package_small_title') ?: __('packet_title'), - 'signatureTitle' => $this->helper->getGeneralConfig('delivery_titles/signature_title') ?: __('signature_title'), - 'onlyRecipientTitle' => $this->helper->getGeneralConfig('delivery_titles/only_recipient_title') ?: __('only_recipient_title'), - 'saturdayDeliveryTitle' => $this->helper->getGeneralConfig('delivery_titles/saturday_title') ?: __('saturday_delivery_title'), + 'deliveryTitle' => $this->helper->getGeneralConfig('delivery_titles/delivery_title') ?: __('delivery_title'), + 'deliveryStandardTitle' => $this->helper->getGeneralConfig('delivery_titles/standard_delivery_title') ?: __('standard_delivery'), + 'deliveryMorningTitle' => $this->helper->getGeneralConfig('delivery_titles/morning_title') ?: __('morning_title'), + 'deliveryEveningTitle' => $this->helper->getGeneralConfig('delivery_titles/evening_title') ?: __('evening_title'), + 'deliveryPickupTitle' => $this->helper->getGeneralConfig('delivery_titles/pickup_title') ?: __('pickup_title'), + 'pickupTitle' => $this->helper->getGeneralConfig('delivery_titles/pickup_title') ?: __('pickup_title'), + 'deliverySameDayTitle' => $this->helper->getGeneralConfig('delivery_titles/same_day_title') ?: __('same_day_title'), + 'hideSenderTitle' => $this->helper->getGeneralConfig('delivery_titles/hide_sender_title') ?: __('hide_sender_title'), + 'list' => $this->helper->getGeneralConfig('delivery_titles/pickup_list_button_title') ?: __('list_title'), + 'map' => $this->helper->getGeneralConfig('delivery_titles/pickup_map_button_title') ?: __('map_title'), + 'packageTypeMailbox' => $this->helper->getGeneralConfig('delivery_titles/mailbox_title') ?: __('mailbox_title'), + 'packageTypeDigitalStamp' => $this->helper->getGeneralConfig('delivery_titles/digital_stamp_title') ?: __('digital_stamp_title'), + 'packageTypePackageSmall' => $this->helper->getGeneralConfig('delivery_titles/package_small_title') ?: __('packet_title'), + 'signatureTitle' => $this->helper->getGeneralConfig('delivery_titles/signature_title') ?: __('signature_title'), + 'onlyRecipientTitle' => $this->helper->getGeneralConfig('delivery_titles/only_recipient_title') ?: __('only_recipient_title'), + 'saturdayDeliveryTitle' => $this->helper->getGeneralConfig('delivery_titles/saturday_title') ?: __('saturday_delivery_title'), 'wrongPostalCodeCity' => __('Postcode/city combination unknown'), 'addressNotFound' => __('Address details are not entered'), @@ -336,17 +342,17 @@ private function getDeliveryOptionsStrings(): array 'showMoreHours' => __('Show more opening hours'), 'showMoreLocations' => __('Show more locations'), - 'error3212' => __('{field} is required.'), - 'error3501' => __('Address not found.'), - 'error3505' => __('Postal code is invalid for the current country.'), - - 'cityText' => __('City'), - 'city' => __('City'), - 'cc' => __('Country'), - 'houseNumber' => __('House number'), - 'numberText' => __('House number'), - 'postalCode' => __('Postal code'), - 'street' => __('Street'), + 'error3212' => __('{field} is required.'), + 'error3501' => __('Address not found.'), + 'error3505' => __('Postal code is invalid for the current country.'), + + 'cityText' => __('City'), + 'city' => __('City'), + 'cc' => __('Country'), + 'houseNumber' => __('House number'), + 'numberText' => __('House number'), + 'postalCode' => __('Postal code'), + 'street' => __('Street'), ]; } @@ -360,7 +366,7 @@ public function checkPackageType(string $carrier, ?string $country = null): stri { try { $consignment = ConsignmentFactory::createByCarrierName($carrier); - } catch (\Throwable $e) { + } catch (Throwable $e) { $this->helper->log(sprintf('checkPackageType: Could not create default consignment for %s', $carrier)); return AbstractConsignment::DEFAULT_PACKAGE_TYPE_NAME; @@ -425,7 +431,7 @@ public function getDropOffDelay(string $carrierPath, string $key): int } /** - * @return $this + * @return self */ public function hideDeliveryOptionsForProduct() { @@ -436,7 +442,7 @@ public function hideDeliveryOptionsForProduct() } /** - * @param string $carrier + * @param string $carrier * * @return bool */ diff --git a/Model/Sales/MagentoCollection.php b/Model/Sales/MagentoCollection.php index eca7b02f..680a583c 100755 --- a/Model/Sales/MagentoCollection.php +++ b/Model/Sales/MagentoCollection.php @@ -14,10 +14,15 @@ namespace MyParcelNL\Magento\Model\Sales; +use Exception; +use Magento\Framework\App\Area; +use Magento\Framework\App\ResourceConnection; use Magento\Framework\Module\Manager; use Magento\Framework\ObjectManagerInterface; use Magento\Sales\Model\Order; -use MyParcelNL\Magento\Model\Order\Email\Sender\TrackSender; +use Magento\Sales\Model\Order\Shipment\Track; +use Magento\Sales\Model\ResourceModel\Order\Shipment; +use Magento\Sales\Model\ResourceModel\Order\Shipment\Collection; use MyParcelNL\Magento\Model\Source\ReturnInTheBox; use MyParcelNL\Magento\Model\Source\SourceItem; use MyParcelNL\Magento\Observer\NewShipment; @@ -26,7 +31,6 @@ use MyParcelNL\Sdk\src\Model\Carrier\CarrierPostNL; use MyParcelNL\Sdk\src\Model\Consignment\AbstractConsignment; use MyParcelNL\Sdk\src\Model\Consignment\BaseConsignment; -use Magento\Framework\App\ResourceConnection; /** * Class MagentoOrderCollection @@ -35,19 +39,19 @@ */ abstract class MagentoCollection implements MagentoCollectionInterface { - public const PATH_HELPER_DATA = '\MyParcelNL\Magento\Helper\Data'; - public const PATH_MODEL_ORDER = '\Magento\Sales\Model\ResourceModel\Order\Collection'; - public const PATH_MODEL_SHIPMENT = '\Magento\Sales\Model\ResourceModel\Order\Shipment\Collection'; - public const ERROR_ORDER_HAS_NO_SHIPMENT = 'No shipment can be made with this order. Shipments can not be created if the status is On Hold or if the product is digital.'; - public const ERROR_ORDER_HAS_NO_SOURCE = 'Creating shipments via bulk actions is not possible for orders without a source. Go to the details of the order and process the shipment manually.'; - public const DEFAULT_ERROR_ORDER_HAS_NO_SOURCE = 'Source item not found by source code'; + public const PATH_HELPER_DATA = '\MyParcelNL\Magento\Helper\Data'; + public const PATH_MODEL_ORDER = '\Magento\Sales\Model\ResourceModel\Order\Collection'; + public const PATH_MODEL_SHIPMENT = '\Magento\Sales\Model\ResourceModel\Order\Shipment\Collection'; + public const ERROR_ORDER_HAS_NO_SHIPMENT = 'No shipment can be made with this order. Shipments can not be created if the status is On Hold or if the product is digital.'; + public const ERROR_ORDER_HAS_NO_SOURCE = 'Creating shipments via bulk actions is not possible for orders without a source. Go to the details of the order and process the shipment manually.'; + public const DEFAULT_ERROR_ORDER_HAS_NO_SOURCE = 'Source item not found by source code'; private const PATH_ORDER_TRACK = '\Magento\Sales\Model\Order\Shipment\Track'; private const PATH_MANAGER_INTERFACE = '\Magento\Framework\Message\ManagerInterface'; private const PATH_ORDER_TRACK_COLLECTION = '\Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection'; /** - * @var MyParcelCollection + * @var \MyParcelNL\Sdk\src\Helper\MyParcelCollection */ public $myParcelCollection; @@ -67,17 +71,17 @@ abstract class MagentoCollection implements MagentoCollectionInterface public $request = null; /** - * @var TrackSender + * @var \MyParcelNL\Magento\Model\Order\Email\Sender\TrackSender */ protected $trackSender; /** - * @var ObjectManagerInterface + * @var \Magento\Framework\ObjectManagerInterface */ protected $objectManager; /** - * @var Order\Shipment\Track + * @var \Magento\Sales\Model\Order\Shipment\Track */ protected $modelTrack; @@ -99,34 +103,37 @@ abstract class MagentoCollection implements MagentoCollectionInterface /** * @var array */ - protected $options = [ - 'create_track_if_one_already_exist' => true, - 'request_type' => 'download', - 'package_type' => 'default', - 'carrier' => 'postnl', - 'positions' => null, - 'signature' => null, - 'only_recipient' => null, - 'return' => null, - 'large_format' => null, - 'age_check' => null, - 'insurance' => null, - 'label_amount' => NewShipment::DEFAULT_LABEL_AMOUNT, - 'digital_stamp_weight' => null, - 'return_in_the_box' => false, - 'same_day_delivery' => false, - ]; - - /** - * @param ObjectManagerInterface $objectManager - * @param null $request - * @param null $areaList + protected $options + = [ + 'create_track_if_one_already_exist' => true, + 'request_type' => 'download', + 'package_type' => 'default', + 'carrier' => 'postnl', + 'positions' => null, + 'signature' => null, + 'receipt_code' => null, + 'only_recipient' => null, + 'return' => null, + 'large_format' => null, + 'age_check' => null, + 'insurance' => null, + 'label_amount' => NewShipment::DEFAULT_LABEL_AMOUNT, + 'digital_stamp_weight' => null, + 'return_in_the_box' => false, + 'same_day_delivery' => false, + ]; + + /** + * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param null $request + * @param null $areaList */ public function __construct( ObjectManagerInterface $objectManager, $request = null, $areaList = null - ) { + ) + { // @todo; Adjust if there is a solution to the following problem: https://github.com/magento/magento2/pull/8413 if ($areaList) { $this->areaList = $areaList; @@ -151,7 +158,7 @@ public function __construct( /** * Set options from POST or GET variables * - * @return $this + * @return self */ public function setOptionsFromParameters() { @@ -222,10 +229,10 @@ public function getOption($option) /** * Add MyParcel consignment to collection * - * @param $consignment BaseConsignment + * @param \MyParcelNL\Sdk\src\Model\Consignment\BaseConsignment $consignment * - * @return $this - * @throws \Exception + * @return self + * @throws Exception */ public function addConsignment(BaseConsignment $consignment) { @@ -272,8 +279,8 @@ public function getHtmlForGridColumns($orderId) */ // Temporarily fix to translate in cronjob if (! empty($this->areaList)) { - $areaObject = $this->areaList->getArea(\Magento\Framework\App\Area::AREA_ADMINHTML); - $areaObject->load(\Magento\Framework\App\Area::PART_TRANSLATE); + $areaObject = $this->areaList->getArea(Area::AREA_ADMINHTML); + $areaObject->load(Area::PART_TRANSLATE); } return $this->getHtmlForGridColumnsByTracks($this->getTracksCollectionByOrderId($orderId)); @@ -325,14 +332,14 @@ protected function shipmentHasTrack($shipment) /** * Create new Magento Track * - * @param Order\Shipment $shipment + * @param \Magento\Sales\Model\Order\Shipment $shipment * * @return \Magento\Sales\Model\Order\Shipment\Track - * @throws \Exception + * @throws Exception */ protected function setNewMagentoTrack($shipment) { - /** @var \Magento\Sales\Model\Order\Shipment\Track $track */ + /** @var Track $track */ $track = $this->objectManager->create('Magento\Sales\Model\Order\Shipment\Track'); $track ->setOrderId($shipment->getOrderId()) @@ -355,7 +362,7 @@ protected function setNewMagentoTrack($shipment) */ protected function getTrackByShipment($shipment) { - /* @var \Magento\Sales\Model\ResourceModel\Order\Shipment\Track\Collection $collection */ + /* @var Shipment\Track\Collection $collection */ $collection = $this->objectManager->create(self::PATH_ORDER_TRACK_COLLECTION); $collection ->addAttributeToFilter('parent_id', $shipment->getId()); @@ -366,9 +373,9 @@ protected function getTrackByShipment($shipment) /** * Get MyParcel Track from Magento Track * - * @param Order\Shipment\Track $magentoTrack + * @param \Magento\Sales\Model\Order\Shipment\Track $magentoTrack * - * @return TrackTraceHolder $myParcelTrack + * @return \MyParcelNL\Magento\Model\Sales\TrackTraceHolder $myParcelTrack * @throws \Magento\Framework\Exception\LocalizedException */ protected function createConsignmentAndGetTrackTraceHolder($magentoTrack): TrackTraceHolder @@ -384,7 +391,7 @@ protected function createConsignmentAndGetTrackTraceHolder($magentoTrack): Track } /** - * @return $this + * @return self */ public function syncMagentoToMyparcel(): self { @@ -395,7 +402,7 @@ public function syncMagentoToMyparcel(): self $consignmentIds, $this->getApiKey() ); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); } @@ -403,10 +410,10 @@ public function syncMagentoToMyparcel(): self } /** - * @return $this + * @return self * @throws \MyParcelNL\Sdk\src\Exception\ApiException * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException - * @throws \Exception + * @throws Exception */ public function createMyParcelConcepts(): self { @@ -417,7 +424,7 @@ public function createMyParcelConcepts(): self try { $this->myParcelCollection->createConcepts(); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); return $this; } @@ -430,8 +437,8 @@ public function createMyParcelConcepts(): self /** * Add MyParcel Track from Magento Track * - * @return $this - * @throws \Exception + * @return self + * @throws Exception */ public function setNewMyParcelTracks(): self { @@ -439,8 +446,8 @@ public function setNewMyParcelTracks(): self $multiColloConsignments = []; /** - * @var Order\Shipment $shipment - * @var Order\Shipment\Track $magentoTrack + * @var Order\Shipment $shipment + * @var Track $magentoTrack */ foreach ($shipments as $shipment) { $magentoTracks = $this->getTrackByShipment($shipment)->getItems(); @@ -473,7 +480,7 @@ public function setNewMyParcelTracks(): self /** * @param array $multiColloConsignments * - * @return $this + * @return self */ protected function addGroupedConsignments(array $multiColloConsignments): self { @@ -505,7 +512,7 @@ protected function addConsignmentMultipleTimes(AbstractConsignment $consignment, while ($i < $quantity) { try { $this->myParcelCollection->addConsignment($consignment); - } catch (\Exception $e) { + } catch (Exception $e) { return; } @@ -548,8 +555,8 @@ function ( } /** - * @return $this - * @throws \Exception + * @return self + * @throws Exception */ public function updateMagentoTrack(): self { @@ -592,7 +599,7 @@ public function updateMagentoTrack(): self } /** - * @return $this + * @return self * @throws \MyParcelNL\Sdk\src\Exception\AccountNotActiveException * @throws \MyParcelNL\Sdk\src\Exception\ApiException * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException @@ -609,7 +616,7 @@ public function addReturnShipments(): self } /** - * @return $this + * @return self */ protected function updateOrderGrid(): self { @@ -639,7 +646,7 @@ protected function updateOrderGrid(): self return $this; } - abstract protected function getShipmentsCollection(): \Magento\Sales\Model\ResourceModel\Order\Shipment\Collection; + abstract protected function getShipmentsCollection(): Collection; /** * @param $orderId @@ -648,7 +655,7 @@ abstract protected function getShipmentsCollection(): \Magento\Sales\Model\Resou */ private function getTracksCollectionByOrderId($orderId): array { - /** @var \Magento\Framework\App\ResourceConnection $connection */ + /** @var ResourceConnection $connection */ $connection = $this->objectManager->create(ResourceConnection::class); $conn = $connection->getConnection(); $select = $conn->select() diff --git a/Model/Sales/TrackTraceHolder.php b/Model/Sales/TrackTraceHolder.php index 68806ee7..24dc5184 100755 --- a/Model/Sales/TrackTraceHolder.php +++ b/Model/Sales/TrackTraceHolder.php @@ -28,7 +28,6 @@ use MyParcelNL\Magento\Model\Source\DefaultOptions; use MyParcelNL\Magento\Services\Normalizer\ConsignmentNormalizer; use MyParcelNL\Magento\Ui\Component\Listing\Column\TrackAndTrace; -use MyParcelNL\Sdk\src\Exception\MissingFieldException; use MyParcelNL\Sdk\src\Factory\ConsignmentFactory; use MyParcelNL\Sdk\src\Factory\DeliveryOptionsAdapterFactory; use MyParcelNL\Sdk\src\Model\Carrier\CarrierFactory; @@ -62,7 +61,7 @@ class TrackTraceHolder public $consignment; /** - * @var Order\Shipment\Track + * @var \Magento\Sales\Model\Order\Shipment\Track */ public $mageTrack; @@ -82,7 +81,7 @@ class TrackTraceHolder private $dataHelper; /** - * @var ObjectManagerInterface + * @var \Magento\Framework\ObjectManagerInterface */ private $objectManager; @@ -94,15 +93,16 @@ class TrackTraceHolder /** * TrackTraceHolder constructor. * - * @param ObjectManagerInterface $objectManager - * @param Data $helper - * @param \Magento\Sales\Model\Order $order + * @param \Magento\Framework\ObjectManagerInterface $objectManager + * @param \MyParcelNL\Magento\Helper\Data $helper + * @param \Magento\Sales\Model\Order $order */ public function __construct( ObjectManagerInterface $objectManager, Data $helper, Order $order - ) { + ) + { $this->objectManager = $objectManager; $this->dataHelper = $helper; $this->messageManager = $this->objectManager->create('Magento\Framework\Message\ManagerInterface'); @@ -113,7 +113,7 @@ public function __construct( } /** - * @param float $price + * @param float $price * * @return int */ @@ -125,24 +125,24 @@ public static function getCentsByPrice(float $price): int /** * Set all data to MyParcel object * - * @param Order\Shipment\Track $magentoTrack - * @param array $options + * @param \Magento\Sales\Model\Order\Shipment\Track $magentoTrack + * @param array $options * - * @return $this - * @throws \Exception + * @return self + * @throws Exception * @throws LocalizedException */ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options): self { - $shipment = $magentoTrack->getShipment(); - $address = $shipment->getShippingAddress(); - $order = $shipment->getOrder(); - $checkoutData = $order->getData('myparcel_delivery_options') ?? ''; - $deliveryOptions = json_decode($checkoutData, true) ?? []; - $deliveryOptions['carrier'] = $this->getCarrierFromOptions($options) + $shipment = $magentoTrack->getShipment(); + $address = $shipment->getShippingAddress(); + $order = $shipment->getOrder(); + $checkoutData = $order->getData('myparcel_delivery_options') ?? ''; + $deliveryOptions = json_decode($checkoutData, true) ?? []; + $deliveryOptions['carrier'] = $this->getCarrierFromOptions($options) ?? $deliveryOptions['carrier'] ?? DefaultOptions::getDefaultCarrier() - ->getName(); + ->getName(); $totalWeight = $options['digital_stamp_weight'] !== null ? (int) $options['digital_stamp_weight'] : (int) self::$defaultOptions->getDigitalStampDefaultWeight(); @@ -186,14 +186,14 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options) ->setFullStreet($address->getData('street')) ->setPostalCode(preg_replace('/\s+/', '', $address->getPostcode())); } catch (Exception $e) { - $errorHuman = - sprintf( - 'An error has occurred while validating order number %s. Check address.', - $order->getIncrementId() - ); + $errorHuman + = sprintf( + 'An error has occurred while validating order number %s. Check address.', + $order->getIncrementId() + ); $this->messageManager->addErrorMessage($errorHuman . ' View log file for more information.'); $this->objectManager->get('Psr\Log\LoggerInterface') - ->critical($errorHuman . '-' . $e); + ->critical($errorHuman . '-' . $e); $this->dataHelper->setOrderStatus($magentoTrack->getOrderId(), Order::STATE_NEW); } @@ -204,7 +204,7 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options) ); $regionCode = $address->getRegionCode(); - $state = $regionCode && strlen($regionCode) === 2 ? $regionCode : null; + $state = $regionCode && strlen($regionCode) === 2 ? $regionCode : null; $this->consignment ->setCity($address->getCity()) @@ -218,6 +218,7 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options) ->setDropOffPoint($dropOffPoint) ->setOnlyRecipient($this->shipmentOptionsHelper->hasOnlyRecipient()) ->setSignature($this->shipmentOptionsHelper->hasSignature()) + ->setReceiptCode($this->shipmentOptionsHelper->hasReceiptCode()) ->setReturn($this->shipmentOptionsHelper->hasReturn()) ->setSameDayDelivery($this->shipmentOptionsHelper->hasSameDayDelivery()) ->setLargeFormat($this->shipmentOptionsHelper->hasLargeFormat()) @@ -249,7 +250,7 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options) try { $this->convertDataForCdCountry($magentoTrack) - ->calculateTotalWeight($magentoTrack, $totalWeight); + ->calculateTotalWeight($magentoTrack, $totalWeight); } catch (Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); return $this; @@ -261,9 +262,9 @@ public function convertDataFromMagentoToApi(Track $magentoTrack, array $options) /** * Create Magento Track from Magento shipment * - * @param \Magento\Sales\Model\Order\Shipment $shipment + * @param \Magento\Sales\Model\Order\Shipment $shipment * - * @return $this + * @return self */ public function createTrackTraceFromShipment(Shipment $shipment) { @@ -282,15 +283,15 @@ public function createTrackTraceFromShipment(Shipment $shipment) /** * Get country of origin from product settings or, if they are not found, from the MyParcel settings. * - * @param $product_id + * @param int $product_id * * @return string */ public function getCountryOfOrigin(int $product_id): string { - $product = - $this->objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface') - ->getById($product_id); + $product + = $this->objectManager->get('Magento\Catalog\Api\ProductRepositoryInterface') + ->getById($product_id); $productCountryOfManufacture = $product->getCountryOfManufacture(); if ($productCountryOfManufacture) { @@ -303,9 +304,9 @@ public function getCountryOfOrigin(int $product_id): string /** * Override to check if key isset * - * @param null|string $apiKey + * @param null|string $apiKey * - * @return $this + * @return self * @throws \Magento\Framework\Exception\LocalizedException */ public function validateApiKey(?string $apiKey): self @@ -322,12 +323,12 @@ public function validateApiKey(?string $apiKey): self } /** - * @param Order\Shipment\Track $magentoTrack - * @param int $totalWeight + * @param Order\Shipment\Track $magentoTrack + * @param int $totalWeight * - * @return TrackTraceHolder - * @throws LocalizedException - * @throws \Exception + * @return \MyParcelNL\Magento\Model\Sales\TrackTraceHolder + * @throws \Magento\Framework\Exception\LocalizedException + * @throws Exception */ private function calculateTotalWeight(Track $magentoTrack, int $totalWeight = 0): self { @@ -348,9 +349,9 @@ private function calculateTotalWeight(Track $magentoTrack, int $totalWeight = 0) return $this; } - $shipmentItems = - $magentoTrack->getShipment() - ->getItems(); + $shipmentItems + = $magentoTrack->getShipment() + ->getItems(); foreach ($shipmentItems as $shipmentItem) { $totalWeight += $shipmentItem['weight'] * $shipmentItem['qty']; @@ -363,8 +364,8 @@ private function calculateTotalWeight(Track $magentoTrack, int $totalWeight = 0) sprintf( 'Order %s can not be exported as digital stamp, no weights have been entered.', $magentoTrack->getShipment() - ->getOrder() - ->getIncrementId() + ->getOrder() + ->getIncrementId() ) ); } @@ -377,12 +378,12 @@ private function calculateTotalWeight(Track $magentoTrack, int $totalWeight = 0) } /** - * @param Order\Shipment\Track $magentoTrack + * @param Order\Shipment\Track $magentoTrack * - * @return $this - * @throws LocalizedException - * @throws MissingFieldException - * @throws \Exception + * @return self + * @throws \Magento\Framework\Exception\LocalizedException + * @throws \MyParcelNL\Sdk\src\Exception\MissingFieldException + * @throws Exception */ private function convertDataForCdCountry(Track $magentoTrack) { @@ -390,9 +391,9 @@ private function convertDataForCdCountry(Track $magentoTrack) return $this; } - if ($products = - $magentoTrack->getShipment() - ->getData('items')) { + if ($products + = $magentoTrack->getShipment() + ->getData('items')) { foreach ($products as $product) { $myParcelProduct = (new MyParcelCustomsItem()) ->setDescription($product->getName()) @@ -412,7 +413,7 @@ private function convertDataForCdCountry(Track $magentoTrack) } foreach ($magentoTrack->getShipment() - ->getItems() as $item) { + ->getItems() as $item) { $myParcelProduct = (new MyParcelCustomsItem()) ->setDescription($item->getName()) ->setAmount($item->getQty()) @@ -434,9 +435,9 @@ private function convertDataForCdCountry(Track $magentoTrack) } /** - * @param Order\Shipment\Track $magentoTrack - * @param object $address - * @param array $options + * @param \Magento\Sales\Model\Order\Shipment\Track $magentoTrack + * @param object $address + * @param array $options * * @return bool * @throws \Magento\Framework\Exception\LocalizedException @@ -455,9 +456,9 @@ private function getAgeCheck(Track $magentoTrack, $address, array $options = []) } /** - * @param string $tableName - * @param string $entityId - * @param string $column + * @param string $tableName + * @param string $entityId + * @param string $column * * @return string|null */ @@ -481,7 +482,7 @@ private function getAttributeValue(string $tableName, string $entityId, string $ } /** - * @param array $options + * @param array $options * * @return null|string */ @@ -490,19 +491,19 @@ private function getCarrierFromOptions(array $options): ?string $carrier = null; if (array_key_exists('carrier', $options) && $options['carrier']) { - $carrier = - DefaultOptions::DEFAULT_OPTION_VALUE === $options['carrier'] ? self::$defaultOptions->getCarrier() - : $options['carrier']; + $carrier + = DefaultOptions::DEFAULT_OPTION_VALUE === $options['carrier'] ? self::$defaultOptions->getCarrier() + : $options['carrier']; } return $carrier; } /** - * @param Order\Shipment\Track $magentoTrack - * @param object $address - * @param array $options - * @param array $deliveryOptions + * @param \Magento\Sales\Model\Order\Shipment\Track $magentoTrack + * @param object $address + * @param array $options + * @param array $deliveryOptions * * @return int * @throws \Magento\Framework\Exception\LocalizedException diff --git a/Model/Source/DefaultOptions.php b/Model/Source/DefaultOptions.php index 71349428..655ade58 100755 --- a/Model/Source/DefaultOptions.php +++ b/Model/Source/DefaultOptions.php @@ -13,7 +13,6 @@ namespace MyParcelNL\Magento\Model\Source; -use BadMethodCallException; use Exception; use Magento\Sales\Model\Order; use MyParcelNL\Magento\Helper\Checkout; @@ -29,29 +28,29 @@ class DefaultOptions { // Maximum characters length of company name. - private const COMPANY_NAME_MAX_LENGTH = 50; + private const COMPANY_NAME_MAX_LENGTH = 50; /** @deprecated */ - private const INSURANCE_BELGIUM = 'insurance_belgium_custom'; + private const INSURANCE_BELGIUM = 'insurance_belgium_custom'; /** @deprecated */ - private const INSURANCE_EU_AMOUNT_50 = 'insurance_eu_50'; + private const INSURANCE_EU_AMOUNT_50 = 'insurance_eu_50'; /** @deprecated */ - private const INSURANCE_EU_AMOUNT_500 = 'insurance_eu_500'; + private const INSURANCE_EU_AMOUNT_500 = 'insurance_eu_500'; /** @deprecated */ - private const INSURANCE_AMOUNT_100 = 'insurance_100'; + private const INSURANCE_AMOUNT_100 = 'insurance_100'; /** @deprecated */ - private const INSURANCE_AMOUNT_250 = 'insurance_250'; + private const INSURANCE_AMOUNT_250 = 'insurance_250'; /** @deprecated */ - private const INSURANCE_AMOUNT_500 = 'insurance_500'; + private const INSURANCE_AMOUNT_500 = 'insurance_500'; /** @deprecated */ - private const INSURANCE_AMOUNT_CUSTOM = 'insurance_custom'; + private const INSURANCE_AMOUNT_CUSTOM = 'insurance_custom'; - private const INSURANCE_FROM_PRICE = 'insurance_from_price'; - private const INSURANCE_LOCAL_AMOUNT = 'insurance_local_amount'; - private const INSURANCE_BELGIUM_AMOUNT = 'insurance_belgium_amount'; - private const INSURANCE_EU_AMOUNT = 'insurance_eu_amount'; - private const INSURANCE_ROW_AMOUNT = 'insurance_row_amount'; - private const INSURANCE_PERCENTAGE = 'insurance_percentage'; - public const DEFAULT_OPTION_VALUE = 'default'; + private const INSURANCE_FROM_PRICE = 'insurance_from_price'; + private const INSURANCE_LOCAL_AMOUNT = 'insurance_local_amount'; + private const INSURANCE_BELGIUM_AMOUNT = 'insurance_belgium_amount'; + private const INSURANCE_EU_AMOUNT = 'insurance_eu_amount'; + private const INSURANCE_ROW_AMOUNT = 'insurance_row_amount'; + private const INSURANCE_PERCENTAGE = 'insurance_percentage'; + public const DEFAULT_OPTION_VALUE = 'default'; /** * @var Data @@ -71,8 +70,8 @@ class DefaultOptions /** * Insurance constructor. * - * @param Order $order - * @param Data $helper + * @param \Magento\Sales\Model\Order $order + * @param \MyParcelNL\Magento\Helper\Data $helper */ public function __construct(Order $order, Data $helper) { @@ -90,8 +89,8 @@ public function __construct(Order $order, Data $helper) /** * Get default of the option * - * @param string $option 'only_recipient'|'signature'|'return'|'large_format' - * @param string $carrier + * @param string $option 'only_recipient'|'signature'|'receipt_code'|'return'|'large_format' + * @param string $carrier * * @return bool */ @@ -130,8 +129,8 @@ public function getMaxCompanyName(?string $company): ?string /** * Get default value of options without price check * - * @param string $carrier - * @param string $option + * @param string $carrier + * @param string $option * * @return bool */ @@ -144,7 +143,7 @@ public function hasDefaultLargeFormat(string $carrier, string $option): bool $activeKey = "{$option}_active"; if (isset($settings[$activeKey]) && - 'weight' === $settings[$activeKey] && + 'weight' === $settings[$activeKey] && $weight >= PackageRepository::DEFAULT_LARGE_FORMAT_WEIGHT ) { return true; @@ -161,8 +160,8 @@ public function hasDefaultLargeFormat(string $carrier, string $option): bool } /** - * @param string $carrier - * @param string $option + * @param string $carrier + * @param string $option * * @return bool */ @@ -179,7 +178,7 @@ public function hasDefaultOptionsWithoutPrice(string $carrier, string $option): * @param string $carrier * * @return int - * @throws \Exception + * @throws Exception */ public function getDefaultInsurance(string $carrier): int { @@ -206,8 +205,8 @@ public function getDefaultInsurance(string $carrier): int */ private function getInsurance(string $carrierName, string $priceKey, string $shippingCountry): int { - $total = self::$order->getGrandTotal(); - $settings = self::$helper->getStandardConfig($carrierName, 'default_options'); + $total = self::$order->getGrandTotal(); + $settings = self::$helper->getStandardConfig($carrierName, 'default_options'); $totalAfterPercentage = $total * (($settings[self::INSURANCE_PERCENTAGE] ?? 0) / 100); if (! isset($settings[$priceKey]) @@ -216,7 +215,7 @@ private function getInsurance(string $carrierName, string $priceKey, string $shi return 0; } - $carrier = ConsignmentFactory::createByCarrierName($carrierName); + $carrier = ConsignmentFactory::createByCarrierName($carrierName); $insuranceTiers = $carrier->getInsurancePossibilities($shippingCountry); sort($insuranceTiers); @@ -255,7 +254,7 @@ public function getPackageType(): int $keyIsPresent = array_key_exists('packageType', self::$chosenOptions); if ($keyIsPresent) { - $packageType = self::$chosenOptions['packageType']; + $packageType = self::$chosenOptions['packageType']; return AbstractConsignment::PACKAGE_TYPES_NAMES_IDS_MAP[$packageType]; } @@ -295,7 +294,7 @@ public function getPackageTypeName(): string * TODO: In the future, when multiple carriers will be available for Rest of World shipments, replace PostNL with a setting for default carrier * * @return \MyParcelNL\Sdk\src\Model\Carrier\AbstractCarrier - * @throws \Exception + * @throws Exception */ public static function getDefaultCarrier(): AbstractCarrier { diff --git a/Observer/NewShipment.php b/Observer/NewShipment.php index 351eb09e..7dd1adef 100755 --- a/Observer/NewShipment.php +++ b/Observer/NewShipment.php @@ -14,10 +14,16 @@ namespace MyParcelNL\Magento\Observer; +use Exception; +use Magento\Backend\Model\View\Result\RedirectFactory; use Magento\Framework\App\ObjectManager; +use Magento\Framework\App\RequestInterface; use Magento\Framework\Event\Observer; use Magento\Framework\Event\ObserverInterface; +use Magento\Framework\Message\Manager; use Magento\Sales\Model\Order\Shipment; +use Magento\Sales\Model\ResourceModel\Order\Collection; +use MyParcelNL\Magento\Helper\Data; use MyParcelNL\Magento\Model\Sales\MagentoOrderCollection; use MyParcelNL\Magento\Model\Sales\TrackTraceHolder; @@ -46,12 +52,7 @@ class NewShipment implements ObserverInterface private $request; /** - * @var \Magento\Sales\Model\Order\Shipment\Track - */ - private $modelTrack; - - /** - * @var MagentoOrderCollection + * @var \MyParcelNL\Magento\Model\Sales\MagentoOrderCollection */ private $orderCollection; @@ -68,21 +69,20 @@ class NewShipment implements ObserverInterface public function __construct(MagentoOrderCollection $orderCollection = null) { $this->objectManager = ObjectManager::getInstance(); - $this->request = $this->objectManager->get('Magento\Framework\App\RequestInterface'); - $this->redirectFactory = $this->objectManager->get('Magento\Framework\Controller\Result\RedirectFactory'); - $this->messageManager = $this->objectManager->get('Magento\Framework\Message\Manager'); + $this->request = $this->objectManager->get(RequestInterface::class); + $this->redirectFactory = $this->objectManager->get(RedirectFactory::class); + $this->messageManager = $this->objectManager->get(Manager::class); $this->orderCollection = $orderCollection ?? new MagentoOrderCollection($this->objectManager, $this->request); - $this->helper = $this->objectManager->get('MyParcelNL\Magento\Helper\Data'); - $this->modelTrack = $this->objectManager->create('Magento\Sales\Model\Order\Shipment\Track'); + $this->helper = $this->objectManager->get(Data::class); } /** * Create MyParcel concept * - * @param Observer $observer + * @param \Magento\Framework\Event\Observer $observer * * @return void - * @throws \Exception + * @throws Exception */ public function execute(Observer $observer) { @@ -92,7 +92,7 @@ public function execute(Observer $observer) try { $this->setMagentoAndMyParcelTrack($shipment); - } catch (\Exception $e) { + } catch (Exception $e) { $this->messageManager->addErrorMessage($e->getMessage()); } @@ -107,12 +107,12 @@ public function execute(Observer $observer) * * @param \Magento\Sales\Model\Order\Shipment $shipment * - * @throws \Exception + * @throws Exception */ private function setMagentoAndMyParcelTrack(Shipment $shipment): void { $options = $this->orderCollection->setOptionsFromParameters() - ->getOptions(); + ->getOptions(); if (isset($options['carrier']) && false === $options['carrier']) { unset($options['carrier']); @@ -120,7 +120,7 @@ private function setMagentoAndMyParcelTrack(Shipment $shipment): void $amount = $options['label_amount'] ?? self::DEFAULT_LABEL_AMOUNT; - /** @var \MyParcelNL\Magento\Model\Sales\TrackTraceHolder[] $trackTraceHolders */ + /** @var TrackTraceHolder[] $trackTraceHolders */ $trackTraceHolders = []; $i = 1; $useMultiCollo = false; @@ -177,14 +177,14 @@ private function setMagentoAndMyParcelTrack(Shipment $shipment): void * @param $shipment * * @return void - * @throws \Exception + * @throws Exception */ private function exportEntireOrder($shipment): void { $orderId = $shipment->getOrderId(); /** - * @var \Magento\Sales\Model\ResourceModel\Order\Collection $collection + * @var Collection $collection */ $collection = $this->objectManager->get(MagentoOrderCollection::PATH_MODEL_ORDER); $collection->addAttributeToFilter('entity_id', ['in' => $orderId]); @@ -199,7 +199,7 @@ private function exportEntireOrder($shipment): void * * @param \Magento\Sales\Model\Order\Shipment $shipment * - * @throws \Exception + * @throws Exception */ private function updateTrackGrid($shipment, $entireOrder): void { @@ -210,8 +210,8 @@ private function updateTrackGrid($shipment, $entireOrder): void } $shipment->getOrder() - ->setData('track_status', $aHtml['track_status']) - ->setData('track_number', $aHtml['track_number']) - ->save(); + ->setData('track_status', $aHtml['track_status']) + ->setData('track_number', $aHtml['track_number']) + ->save(); } } diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml index 433d09f4..4726743b 100755 --- a/etc/adminhtml/system.xml +++ b/etc/adminhtml/system.xml @@ -1,42 +1,54 @@ - + -
+
myparcelnl_magento MyParcelNL_Magento::myparcelnl_magento - + \MyParcelNL\Magento\Block\System\Config\Form\SupportTab
-
+
myparcelnl_magento MyParcelNL_Magento::myparcelnl_magento - + Go to the general settings in the back office of MyParcel to generate the API Key. - + The API Key - + - Clicking this button will fetch settings from the MyParcel Backoffice and overwrite the current settings. + Clicking this button will fetch settings from the MyParcel Backoffice and overwrite the + current settings. + MyParcelNL\Magento\Block\System\Config\Form\SettingsButton - + - + Show a delivery date in the checkout. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -44,20 +56,28 @@ MyParcelNL\Magento\Model\Source\NumberOfDays Amount of days in the future customers can choose from in the checkout. - + - This options allows you to set the number of days it takes you to pick, pack and hand in your parcels when ordered before the cutoff time. + This options allows you to set the number of days it takes you to pick, pack and hand in + your parcels when ordered before the cutoff time. + MyParcelNL\Magento\Model\Source\DropOffDelayDays - + - + - With 'Export entire order', MyParcel will export every order in its entirety to the back office for further processing. + With 'Export entire order', MyParcel will export every order in its entirety to the back + office for further processing. + MyParcelNL\Magento\Model\Source\ExportMode - + Select a standard orientation for printing labels. MyParcelNL\Magento\Model\Source\PaperType @@ -65,123 +85,164 @@ shipments - + - This description will appear on the shipment label. The following parts can be used: %order_nr%, %delivery_date%, %product_id%, %product_name%, %product_qty%. + This description will appear on the shipment label. The following parts can be used: + %order_nr%, %delivery_date%, %product_id%, %product_name%, %product_qty%. + - + - This country will appear on the international consignment labels. This is where your products are shipped from. You can use NL, BE, DE etc. This will be overridden by country of manufacture on product level. + This country will appear on the international consignment labels. This is where your + products are shipped from. You can use NL, BE, DE etc. This will be overridden by country of + manufacture on product level. + - + Enable create label concept, when invoice is printed. Magento\Config\Model\Config\Source\Yesno - + This is the type of weight that I use with my products. MyParcelNL\Magento\Model\Source\WeightType - - - - - + + + + + - + - + MyParcelNL\Magento\Model\Source\ShippingMethods The extra myparcel options are added to this shipping method 1 - + MyParcelNL\Magento\Model\Source\PickupLocationsView - When pickup locations are enabled, the user can choose between map or list view. This setting decides which option will be selected first, upon opening the pickup locations. + When pickup locations are enabled, the user can choose between map or list view. This + setting decides which option will be selected first, upon opening the pickup locations. + - - - MyParcelNL\Magento\Model\Source\PriceDeliveryOptionsView - This determines the way the price of delivery is shown to the customer through the delivery options. - The price can be shown as a total for each delivery option or as a surchage on top of the regular shipping price. - + + + MyParcelNL\Magento\Model\Source\PriceDeliveryOptionsView + This determines the way the price of delivery is shown to the customer through the delivery + options. + The price can be shown as a total for each delivery option or as a surchage on top of the + regular shipping price. + - + - + - + The times will be visible when nothing is filled in - + - The times will be visible when nothing is filled in - + + + + - + - The times will be visible when nothing is filled in - + The times will be visible when nothing is filled in - + The times will be visible when nothing is filled in - + - + - + - + - + - + - +
-
+
myparcelnl_magento MyParcelNL_Magento::myparcelnl_magento - + - + Magento\Config\Model\Config\Source\Yesno - + - Delivery on monday may require special conditions compared to other (week)days including but not limited to fee and cutoff time. + Delivery on monday may require special conditions compared to other (week)days including + but not limited to fee and cutoff time. + Magento\Config\Model\Config\Source\Yesno 1 - + This will be added to the regular shipping price @@ -189,14 +250,16 @@ 1 - + Magento\Config\Model\Config\Source\Yesno 1 - + This will be added to the regular shipping price @@ -204,14 +267,34 @@ 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 @@ -220,87 +303,104 @@ - + - Specify the days you hand in your parcels for this carrier. Specify the latest time a customer can order for you to deliver the package in time for shipment that day. - + Specify the days you hand in your parcels for this carrier. Specify the latest time a customer + can order for you to deliver the package in time for shipment that day. + + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -308,14 +408,20 @@ 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. - + 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 @@ -323,11 +429,27 @@ 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 @@ -335,11 +457,13 @@ 1 - + Magento\Config\Model\Config\Source\Yesno - + validate-number validate-zero-or-greater 'Return if no answer' operates above a certain order total amount @@ -347,11 +471,13 @@ 1 - + MyParcelNL\Magento\Model\Source\LargeFormatOptions - + validate-number validate-zero-or-greater 'Large format' operates above a certain order total amount @@ -359,95 +485,126 @@ price - + Magento\Config\Model\Config\Source\Yesno - The age check is intended for parcel shipments for which the recipient must show 18+ by means of a proof of identity. With this shipping option Signature on receipt and Home address only are included. The age 18+ is further excluded from the delivery options morning and evening delivery. + The age check is intended for parcel shipments for which the recipient must show 18+ by + means of a proof of identity. With this shipping option Signature on receipt and Home address + only are included. The age 18+ is further excluded from the delivery options morning and evening + delivery. + - + validate-number validate-zero-or-greater The minimum amount from when insurance is active. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\Postnl\Local This setting applies to domestic shipments only - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\Postnl\Belgium A custom be insurance price within a range of possibilities. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\Postnl\EU A custom eu insurance price within a range of possibilities. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\Postnl\ROW A custom row insurance price within a range of possibilities. - + 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. + Use percentage of total order amount for insurance. After the calculation, the next + available price scale is selected. + - + - + Select automatically digital stamp packages based on weight Magento\Config\Model\Config\Source\Yesno - + - Price depends on the weight. Are the weights correctly filled in for all products? Choose 'No standard weight' to let MyParcel calculate the weight itself. Select a standard weight here when the products do not contain correct weights. + Price depends on the weight. Are the weights correctly filled in for all products? Choose + 'No standard weight' to let MyParcel calculate the weight itself. Select a standard weight here + when the products do not contain correct weights. + MyParcelNL\Magento\Model\Source\DigitalStampWeightOptions 1 - + - Enter a basic price for a digital stamp. The regular price will not affect this price. + Enter a basic price for a digital stamp. The regular price will not affect this price. + 1 - + - + Select automatically mailbox packages based on weight or volume Magento\Config\Model\Config\Source\Yesno - + - 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. + 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. + 1 - + Enter a basic price for a mailbox. The regular price will not affect this price. 1 - + - Only available for certain contracts. If this is not in your contract, the setting has no effect. + Only available for certain contracts. If this is not in your contract, the setting has no + effect. + Magento\Config\Model\Config\Source\Yesno 1 - + Enter a basic price for a mailbox. The regular price will not affect this price. @@ -456,36 +613,48 @@ - - - - - Automatically select package type 'Small Package' for orders under 2000 grams. Package type will be 'Small Package' when a product has setting 'Fit in mailbox' set to 0 and the weight is under 2000 grams. - Magento\Config\Model\Config\Source\Yesno - - - - Shipments heavier than the weight specified here will not be of package type 'Small Package'. - - 1 - - - - - Enter a basic price for a mailbox. The regular price will not affect this price. - - 1 - - + + + + + Automatically select package type 'Small Package' for orders under 2000 grams. Package type + will be 'Small Package' when a product has setting 'Fit in mailbox' set to 0 and the weight is + under 2000 grams. + + Magento\Config\Model\Config\Source\Yesno + + + + Shipments heavier than the weight specified here will not be of package type 'Small + Package'. + + + 1 + + + + + Enter a basic price for a mailbox. The regular price will not affect this price. + + 1 + + - + - + MyParcelNL\Magento\Model\Source\AgeCheckNo If age check is active then the morning delivery is not possible - + This will be added to the regular shipping price @@ -493,14 +662,17 @@ - + - + MyParcelNL\Magento\Model\Source\AgeCheckNo If age check is active then the evening delivery is not possible - + This will be added to the regular shipping price @@ -508,46 +680,58 @@ - + - + Magento\Config\Model\Config\Source\Yesno - + - Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + Enter an amount that is either positive or negative. For example, do you want to give a + discount for using this function or do you want to charge extra for this delivery option. + 1 - + - + MyParcelNL\Magento\Block\System\Config\Form\DefaultDropOffPointPostNL
-
+
myparcelnl_magento MyParcelNL_Magento::myparcelnl_magento - + - + Magento\Config\Model\Config\Source\Yesno - + Magento\Config\Model\Config\Source\Yesno 1 - + This will be added to the regular shipping price @@ -555,14 +739,16 @@ 1 - + Magento\Config\Model\Config\Source\Yesno 1 - + This will be added to the regular shipping price @@ -571,87 +757,104 @@ - + - Specify the days you hand in your parcels for this carrier. Specify the latest time a customer can order for you to deliver the package in time for shipment that day. - + Specify the days you hand in your parcels for this carrier. Specify the latest time a customer + can order for you to deliver the package in time for shipment that day. + + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -659,14 +862,20 @@ 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. - + 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 @@ -674,11 +883,13 @@ 1 - + Magento\Config\Model\Config\Source\Yesno - + validate-number validate-zero-or-greater 'Home address only' operates above a certain order total amount @@ -686,52 +897,72 @@ 1 - + Magento\Config\Model\Config\Source\Yesno - The age check is intended for parcel shipments for which the recipient must show 18+ by means of a proof of identity. With this shipping option Signature on receipt and Home address only are included. The age 18+ is further excluded from the delivery options morning and evening delivery. + The age check is intended for parcel shipments for which the recipient must show 18+ by + means of a proof of identity. With this shipping option Signature on receipt and Home address + only are included. The age 18+ is further excluded from the delivery options morning and evening + delivery. + - + Magento\Config\Model\Config\Source\Yesno - Activating the 'hide sender' option will remove the name and address of the sender from the label + Activating the 'hide sender' option will remove the name and address of the sender from the + label + - + validate-number validate-zero-or-greater The minimum amount from when insurance is active. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\DHLForYou\Local This setting applies to domestic shipments only - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\DHLForYou\Belgium A custom be insurance price within a range of possibilities. - + 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. + Use percentage of total order amount for insurance. After the calculation, the next + available price scale is selected. + - + - + Select automatically mailbox packages based on weight or volume Magento\Config\Model\Config\Source\Yesno - + - 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. + 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. + 1 - + Enter a basic price for a mailbox. The regular price will not affect this price. @@ -739,113 +970,138 @@ - + - + Magento\Config\Model\Config\Source\Yesno - + - Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + Enter an amount that is either positive or negative. For example, do you want to give a + discount for using this function or do you want to charge extra for this delivery option. + 1
-
+
myparcelnl_magento MyParcelNL_Magento::myparcelnl_magento - + - + Magento\Config\Model\Config\Source\Yesno - + - Specify the days you hand in your parcels for this carrier. Specify the latest time a customer can order for you to deliver the package in time for shipment that day. - + Specify the days you hand in your parcels for this carrier. Specify the latest time a customer + can order for you to deliver the package in time for shipment that day. + + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -853,133 +1109,165 @@ 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. - + 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. + + validate-number validate-zero-or-greater The minimum amount from when insurance is active. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\DHLEuroPlus\Local This setting applies to domestic shipments only - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\DHLEuroPlus\Belgium A custom be insurance price within a range of possibilities. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\DHLEuroPlus\EU A custom eu insurance price within a range of possibilities. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\DHLEuroPlus\ROW A custom row insurance price within a range of possibilities. - + 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. + Use percentage of total order amount for insurance. After the calculation, the next + available price scale is selected. +
-
+
myparcelnl_magento MyParcelNL_Magento::myparcelnl_magento - + - + Magento\Config\Model\Config\Source\Yesno - + - Specify the days you hand in your parcels for this carrier. Specify the latest time a customer can order for you to deliver the package in time for shipment that day. - + Specify the days you hand in your parcels for this carrier. Specify the latest time a customer + can order for you to deliver the package in time for shipment that day. + + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -987,137 +1275,172 @@ 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. - + 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. + + validate-number validate-zero-or-greater The minimum amount from when insurance is active. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\DHLParcelConnect\EU A custom eu insurance price within a range of possibilities. - + MyParcelNL\Magento\Model\Source\CarrierInsurancePossibilities\DHLParcelConnect\ROW A custom row insurance price within a range of possibilities. - + 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. + Use percentage of total order amount for insurance. After the calculation, the next + available price scale is selected. + - + - + Magento\Config\Model\Config\Source\Yesno - + - Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. + Enter an amount that is either positive or negative. For example, do you want to give a + discount for using this function or do you want to charge extra for this delivery option. + 1
-
- - myparcelnl_magento - MyParcelNL_Magento::myparcelnl_magento - - - - - Magento\Config\Model\Config\Source\Yesno - - - +
+ + myparcelnl_magento + MyParcelNL_Magento::myparcelnl_magento + + + + + Magento\Config\Model\Config\Source\Yesno + + + - Specify the days you hand in your parcels for this carrier. Specify the latest time a customer can order for you to deliver the package in time for shipment that day. - + Specify the days you hand in your parcels for this carrier. Specify the latest time a customer + can order for you to deliver the package in time for shipment that day. + + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -1125,20 +1448,25 @@ For orders before this time, the drop-off is considered done on this day. - - - - - Magento\Config\Model\Config\Source\Yesno - - - - Enter an amount that is either positive or negative. For example, do you want to give a discount for using this function or do you want to charge extra for this delivery option. - - 1 - - - + + + + + Magento\Config\Model\Config\Source\Yesno + + + + Enter an amount that is either positive or negative. For example, do you want to give a + discount for using this function or do you want to charge extra for this delivery option. + + + 1 + + + @@ -1168,98 +1496,118 @@
-
+
myparcelnl_magento MyParcelNL_Magento::myparcelnl_magento - + - + Magento\Config\Model\Config\Source\Yesno - + - Specify the days you hand in your parcels for this carrier. Specify the latest time a customer can order for you to deliver the package in time for shipment that day. - + Specify the days you hand in your parcels for this carrier. Specify the latest time a customer + can order for you to deliver the package in time for shipment that day. + + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 For orders before this time, the drop-off is considered done on this day. - + Whether you drop off packages on this day. Magento\Config\Model\Config\Source\Yesno - + 1 @@ -1269,23 +1617,28 @@
- + Enable this option to add the MyParcel barcode in the email. - + Magento\Config\Model\Config\Source\Yesno - + Magento\Config\Model\Config\Source\Email\Identity - + Use Shipment email template when "Default" option is selected. Magento\Config\Model\Config\Source\Email\Template - + Use Shipment email template when "Default" option is selected. Magento\Config\Model\Config\Source\Email\Template diff --git a/i18n/en_US.csv b/i18n/en_US.csv index 08ddd101..cece314f 100755 --- a/i18n/en_US.csv +++ b/i18n/en_US.csv @@ -74,6 +74,7 @@ mailbox_title, Mailbox digital_stamp_title, Digital Stamp packet_title, Packet signature_title, Signature +receipt_code_title, Receiving code only_recipient_title, Only Recipient saturday_delivery, Saturday Delivery diff --git a/i18n/fr_FR.csv b/i18n/fr_FR.csv index 88a64165..93284b04 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 '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' "Insurance € 500' operates above a certain order total amount.","L''Assurance jusqu'à € 500' est activée lorsque le montant total dépasse le montant ci-dessus." @@ -85,6 +86,8 @@ Track action,Action de suivi MyParcel options,Options MyParcel Package,Colis Signature on receipt,Signature pour réception +Receipt code,Code de réception +Receipt code fee,Frais de code de réception Home address only,Livraison à domicile uniquement Hide sender title,Titre de masquer l'expéditeur Insured up to:,Assuré jusqu'à : @@ -221,5 +224,6 @@ mailbox_title, Colis boîte aux lettres digital_stamp_title, Timbre digital packet_title, Colis signature_title, Signature à réception +receipt_code_title, Code de réception only_recipient_title, Adresse de résidence uniquement saturday_delivery, Livraison le samedi diff --git a/i18n/nl_NL.csv b/i18n/nl_NL.csv index 220368ce..81f85927 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 'Receipt code',Automatiseer 'Ontvangstcode' Automate 'Home address only',Automatiseer 'Alleen huisadres' Automate 'Return if no answer',Automatiseer 'Retour bij geen gehoor' Automate 'Large format',Automatiseer 'Groter dan 100 x 70 x 58 cm of zwaarder dan 23 kg' @@ -125,6 +126,8 @@ Monday delivery,Maandag levering "Delivery on monday may require special conditions compared to other (week)days including but not limited to fee and cutoff time.","Levering op maandag kan speciale voorwaarden vereisen in vergelijking met andere (week)dagen, waaronder maar niet beperkt tot kosten en laatste bestelmoment." Number of days,Aantal dagen Delivery enabled,Bezorging ingeschakeld +Receipt code,Ontvangstcode +Receipt code fee,Ontvangstcode kosten Home address only,Alleen huisadres Home address only fee,Alleen huisadres kosten Digital stamp settings,Digitalepostzegel instellingen @@ -314,4 +317,5 @@ digital_stamp_title, Digitale postzegel packet_title, Pakket signature_title, Handtekening voor ontvangst only_recipient_title, Alleen huisadres +receipt_code_title, Ontvangstcode saturday_delivery, Zaterdag levering diff --git a/view/adminhtml/templates/new_shipment.phtml b/view/adminhtml/templates/new_shipment.phtml index 9698d673..cc57d83f 100755 --- a/view/adminhtml/templates/new_shipment.phtml +++ b/view/adminhtml/templates/new_shipment.phtml @@ -1,19 +1,18 @@ - +
+ id="mypa_create_from_observer" + class="admin__control-checkbox" + name="mypa_create_from_observer" + value="1" + type="checkbox" + checked="checked"/> @@ -31,11 +30,11 @@ foreach ($form->getCarrierSpecificAbstractConsignments() as $abstractConsignment
+ type="radio" + class="admin__control-radio" + id="mypa_carrier_" + name="mypa_carrier" + value=""> @@ -43,9 +42,9 @@ foreach ($form->getCarrierSpecificAbstractConsignments() as $abstractConsignment
+ class="field field-mypa_package_type js--mypa-options" + data-for_mypa_carrier="" + style="margin: 10px 0 0 30px;">
getCountry(); @@ -63,14 +62,14 @@ foreach ($form->getCarrierSpecificAbstractConsignments() as $abstractConsignment ?>
+ type="radio" + class="admin__control-radio" + id="mypa_package_type-_" + name="mypa_package_type" + value=""> getCarrierSpecificAbstractConsignments() as $abstractConsignment $weight = $block->getDigitalStampWeight(); ?> + name="mypa_label_amount" + id="mypa_label_amount__" + class="required product-custom-option admin__control-select" + title=""> ', __($label_amount), ''; @@ -142,34 +141,41 @@ foreach ($form->getCarrierSpecificAbstractConsignments() as $abstractConsignment setPackageType($packageTypeId); - } catch (\Exception $e) { + } catch (Exception $e) { continue; } foreach ($abstractConsignment->getAllowedShipmentOptions() as $shipmentOption) { if (AbstractConsignment::SHIPMENT_OPTION_INSURANCE === $shipmentOption || ! $block->consignmentHasShipmentOption($abstractConsignment, $shipmentOption) + || ($shipmentOption === AbstractConsignment::SHIPMENT_OPTION_RECEIPT_CODE + && AbstractConsignment::DELIVERY_TYPE_STANDARD !== $block->getDeliveryType()) ) { continue; } ?>
+ class="field choice admin__field admin__field-option field-mypa_signature mypa_package-toggle mypa-option-toggle" + data-for_mypa_package_type="" + style="padding-left:30px;"> hasDefaultOption($shipmentOption, $carrierName) ? 'checked="checked"' : '' ?> />
@@ -180,18 +186,19 @@ foreach ($form->getCarrierSpecificAbstractConsignments() as $abstractConsignment if ($abstractConsignment->canHaveShipmentOption(AbstractConsignment::SHIPMENT_OPTION_INSURANCE)) { ?>
+ class="field choice admin__field admin__field-option field-mypa_insurance mypa_package-toggle mypa-option-toggle" + data-for_mypa_package_type="" + style="padding-left:30px;"> - getDefaultInsurance($carrierName); ?> + getDefaultInsurance($carrierName); ?>